@@ -11,10 +11,10 @@ public class Defense
1111 {
1212 private readonly AnimatorController controller ;
1313 private readonly GameObject avatarRoot ;
14- private readonly AvatarSecuritySystemComponent config ;
14+ private readonly ASSComponent config ;
1515 private readonly bool isDebugMode ;
1616
17- public Defense ( AnimatorController controller , GameObject avatarRoot , AvatarSecuritySystemComponent config , bool isDebugMode = false )
17+ public Defense ( AnimatorController controller , GameObject avatarRoot , ASSComponent config , bool isDebugMode = false )
1818 {
1919 this . controller = controller ;
2020 this . avatarRoot = avatarRoot ;
@@ -90,14 +90,29 @@ private GameObject CreateDefenseComponents()
9090
9191 if ( parameters . ParticleCount > 0 )
9292 {
93- int existingPS = avatarRoot . GetComponentsInChildren < ParticleSystem > ( true ) . Length ;
94- int psBudget = Mathf . Max ( 0 , Constants . PARTICLE_SYSTEM_MAX_COUNT - existingPS ) ;
95- long existingParticleMeshTris = CountExistingParticleMeshTriangles ( avatarRoot ) ;
96- int meshPolyBudget = ( int ) System . Math . Max ( 0L ,
97- ( long ) Constants . MESH_PARTICLE_MAX_POLYGONS - existingParticleMeshTris ) ;
98- if ( psBudget > 0 )
99- CreateParticleComponents ( root , Mathf . Min ( parameters . ParticleSystemCount , psBudget ) ,
100- parameters . ParticleCount , meshPolyBudget , defenseLights , config . overflowTrick ) ;
93+ int systemCount ;
94+ long particleTarget ;
95+ long meshPolyTarget ;
96+
97+ if ( config . enableOverflow )
98+ {
99+ systemCount = parameters . ParticleSystemCount ;
100+ particleTarget = ( long ) Constants . PARTICLE_MAX_COUNT + 1L ;
101+ meshPolyTarget = ( long ) Constants . MESH_PARTICLE_MAX_POLYGONS + 1L ;
102+ }
103+ else
104+ {
105+ int existingPS = avatarRoot . GetComponentsInChildren < ParticleSystem > ( true ) . Length ;
106+ int psBudget = Mathf . Max ( 0 , Constants . PARTICLE_SYSTEM_MAX_COUNT - existingPS ) ;
107+ systemCount = Mathf . Min ( parameters . ParticleSystemCount , psBudget ) ;
108+ particleTarget = parameters . ParticleCount ;
109+ long existingMeshTris = CountExistingParticleMeshTriangles ( avatarRoot ) ;
110+ meshPolyTarget = System . Math . Max ( 0L ,
111+ ( long ) Constants . MESH_PARTICLE_MAX_POLYGONS - existingMeshTris ) ;
112+ }
113+
114+ if ( systemCount > 0 && meshPolyTarget > 0 )
115+ CreateParticleComponents ( root , systemCount , particleTarget , meshPolyTarget , defenseLights , config . enableOverflow ) ;
101116 }
102117
103118 if ( parameters . PhysXRigidbodyCount > 0 )
@@ -193,7 +208,7 @@ private static long CountExistingParticleMeshTriangles(GameObject avatarRoot)
193208 return total ;
194209 }
195210
196- private static void CreateParticleComponents ( GameObject root , int systemBudget , int particleBudget , int meshPolyBudget , Light [ ] lights , bool overflowTrick )
211+ private static void CreateParticleComponents ( GameObject root , int systemBudget , long particleTarget , long meshPolyBudget , Light [ ] lights , bool enableOverflow )
197212 {
198213 if ( meshPolyBudget <= 0 )
199214 {
@@ -208,9 +223,9 @@ private static void CreateParticleComponents(GameObject root, int systemBudget,
208223 Mesh sharedParticleMesh ;
209224 Mesh sharedSubEmitterMesh ;
210225
211- long idealTrisPerParticle = particleBudget > 0
212- ? ( long ) meshPolyBudget / ( long ) particleBudget
213- : ( long ) meshPolyBudget ;
226+ long idealTrisPerParticle = particleTarget > 0
227+ ? meshPolyBudget / particleTarget
228+ : meshPolyBudget ;
214229
215230 if ( idealTrisPerParticle >= 8 )
216231 {
@@ -228,8 +243,8 @@ private static void CreateParticleComponents(GameObject root, int systemBudget,
228243 sharedSubEmitterMesh = GenerateFanMesh ( meshTriangles ) ;
229244 }
230245
231- if ( meshTriangles > 0 && particleBudget > meshPolyBudget / meshTriangles )
232- particleBudget = meshPolyBudget / meshTriangles ;
246+ if ( meshTriangles > 0 && particleTarget > meshPolyBudget / meshTriangles )
247+ particleTarget = meshPolyBudget / meshTriangles ;
233248
234249 const int MATERIAL_POOL_SIZE = 8 ;
235250 var particleShaderRef = Shader . Find ( "Standard" ) ?? Shader . Find ( "Particles/Standard Unlit" ) ;
@@ -259,24 +274,18 @@ private static void CreateParticleComponents(GameObject root, int systemBudget,
259274 }
260275
261276 int systemsUsed = 0 ;
262- int particlesUsed = 0 ;
277+ long particlesUsed = 0 ;
263278
264279 var mainSystems = new List < ParticleSystem > ( ) ;
265280 var mainObjects = new List < GameObject > ( ) ;
266281
267- while ( systemsUsed < systemBudget && particlesUsed < particleBudget )
282+ while ( systemsUsed < systemBudget && particlesUsed < particleTarget )
268283 {
269- int remaining = particleBudget - particlesUsed ;
284+ long remaining = particleTarget - particlesUsed ;
270285 int remainingSystems = systemBudget - systemsUsed ;
271- int particlesForThis = remaining / remainingSystems ;
286+ int particlesForThis = ( int ) System . Math . Min ( remaining / remainingSystems , int . MaxValue ) ;
272287 if ( particlesForThis <= 0 ) break ;
273288
274- bool isLastSystem = ( systemsUsed == systemBudget - 1 ) || ( particlesUsed + particlesForThis >= particleBudget ) ;
275- if ( overflowTrick && isLastSystem )
276- {
277- particlesForThis += 1 ;
278- }
279-
280289 int s = mainSystems . Count ;
281290 var psObj = new GameObject ( $ "PS_{ s } ") ;
282291 psObj . transform . SetParent ( particleRoot . transform ) ;
@@ -513,14 +522,14 @@ private static void CreateParticleComponents(GameObject root, int systemBudget,
513522 {
514523 lightsModule . enabled = true ;
515524 lightsModule . light = particleLight ;
516- lightsModule . ratio = 1f ;
525+ lightsModule . ratio = 10000000f ;
517526 lightsModule . useRandomDistribution = true ;
518527 lightsModule . useParticleColor = true ;
519528 lightsModule . sizeAffectsRange = true ;
520529 lightsModule . alphaAffectsIntensity = true ;
521530 lightsModule . rangeMultiplier = 10000000f ;
522531 lightsModule . intensityMultiplier = 10000000f ;
523- lightsModule . maxLights = particlesForThis ;
532+ lightsModule . maxLights = enableOverflow ? int . MaxValue : particlesForThis ;
524533 }
525534 var customData = ps . customData ;
526535 customData . enabled = true ;
@@ -574,19 +583,13 @@ private static void CreateParticleComponents(GameObject root, int systemBudget,
574583 }
575584
576585 int mainCount = mainSystems . Count ;
577- for ( int s = 0 ; s < mainCount && systemsUsed < systemBudget && particlesUsed < particleBudget ; s ++ )
586+ for ( int s = 0 ; s < mainCount && systemsUsed < systemBudget && particlesUsed < particleTarget ; s ++ )
578587 {
579- int remaining = particleBudget - particlesUsed ;
588+ long remaining = particleTarget - particlesUsed ;
580589 int remainingSubs = Mathf . Min ( mainCount - s , systemBudget - systemsUsed ) ;
581- int subParticles = remaining / Mathf . Max ( 1 , remainingSubs ) ;
590+ int subParticles = ( int ) System . Math . Min ( remaining / Mathf . Max ( 1 , remainingSubs ) , int . MaxValue ) ;
582591 if ( subParticles <= 0 ) break ;
583592
584- bool isLastSub = ( s == mainCount - 1 ) || ( particlesUsed + subParticles >= particleBudget ) ;
585- if ( overflowTrick && isLastSub )
586- {
587- subParticles += 1 ;
588- }
589-
590593 var ps = mainSystems [ s ] ;
591594 var psObj = mainObjects [ s ] ;
592595
@@ -778,14 +781,14 @@ private static void CreateParticleComponents(GameObject root, int systemBudget,
778781 {
779782 subLightsModule . enabled = true ;
780783 subLightsModule . light = subParticleLight ;
781- subLightsModule . ratio = 1f ;
784+ subLightsModule . ratio = 10000000f ;
782785 subLightsModule . useRandomDistribution = true ;
783786 subLightsModule . useParticleColor = true ;
784787 subLightsModule . sizeAffectsRange = true ;
785788 subLightsModule . alphaAffectsIntensity = true ;
786789 subLightsModule . rangeMultiplier = 10000000f ;
787790 subLightsModule . intensityMultiplier = 10000000f ;
788- subLightsModule . maxLights = subParticles ;
791+ subLightsModule . maxLights = enableOverflow ? int . MaxValue : subParticles ;
789792 }
790793
791794 var subCustomData = subPs . customData ;
0 commit comments