private void DeprocessDestroyable(List <DestroyableGameObject> destroyable, List <DestroyableGameObject> processing, bool isMisc) { for (int i = processing.Count - 1; i >= 0; --i) { DestroyableGameObject toProcess = processing[i]; if (toProcess.fragmenterStat != null && toProcess.fragmenterStat.isDone) { if (toProcess.state == DestroyableGameObject.StateType.fragmenting) { Fragmenter.Stats fs = new Fragmenter.Stats(); toProcess.gameObject = toProcess.fragmenterStat.fragmentedGameObject; toProcess.fragmenterStat = fs; toProcess.state = DestroyableGameObject.StateType.exploding; Debug.Log($"Exploding {toProcess.gameObject.name}"); StartCoroutine(Fragmenter.Explode( CalculateExplosionPoint(toProcess.gameObject, true), isMisc ? Constants.MiscExplosionRadius : Constants.BuildExplosionRadius, isMisc ? Constants.MiscExplosionForce : Constants.BuildExplosionForce, fs, isMisc) ); } else if (toProcess.state == DestroyableGameObject.StateType.exploding) { processing.RemoveAt(i); if (toProcess.fragmenterStat.destroyedAll) { toProcess.state = DestroyableGameObject.StateType.destroyed; } else { toProcess.state = DestroyableGameObject.StateType.fragmented; destroyable.Add(toProcess); } } } } }
private void ProcessDestroyable(List <DestroyableGameObject> destroyable, List <DestroyableGameObject> processing, bool isMisc) { if (Random.Range(0.0f, 1.0f) < 0.25f && destroyable.Count > 0) { int index = Random.Range(0, destroyable.Count - 1); DestroyableGameObject toDestroy = destroyable[index]; if (toDestroy.state == DestroyableGameObject.StateType.decaying) { Debug.Log($"Fragmenting {toDestroy.gameObject.name}"); Fragmenter.Stats fs = new Fragmenter.Stats(); toDestroy.fragmenterStat = fs; toDestroy.state = DestroyableGameObject.StateType.fragmenting; destroyable.RemoveAt(index); processing.Add(toDestroy); StartCoroutine(Fragmenter.Fragment(toDestroy.gameObject, fs, isMisc)); } else if (toDestroy.state == DestroyableGameObject.StateType.fragmented) { Debug.Log($"Exploding {toDestroy.gameObject.name}"); Fragmenter.Stats fs = new Fragmenter.Stats(); toDestroy.fragmenterStat = fs; toDestroy.state = DestroyableGameObject.StateType.exploding; destroyable.RemoveAt(index); processing.Add(toDestroy); StartCoroutine(Fragmenter.Explode( CalculateExplosionPoint(toDestroy.gameObject), isMisc ? Constants.MiscExplosionRadius : Constants.BuildExplosionRadius, isMisc ? Constants.MiscExplosionForce : Constants.BuildExplosionForce, fs) ); } else { Debug.Log("Oops"); } } }