bool Postprocess(long timeOffset) { var postTimer = new Stopwatch(); postTimer.Start(); var count = postList.Count; #if DBG postProcessingFrames++; #endif while (poolIdx < count) { var fragment = pool[poolIdx]; var mesh = postList[poolIdx]; poolIdx++; if (!mesh.original) { continue; } if (crack) { Exploder2DUtils.SetActiveRecursively(fragment.gameObject, false); } fragment.CreateSprite(mesh.spriteMesh, mesh.sprite, mesh.original.transform, mesh.sortingLayer, mesh.orderInLayer, mesh.color); var oldParent = fragment.transform.parent; fragment.transform.parent = mesh.parent; fragment.transform.position = new Vector3(mesh.position.x, mesh.position.y, mesh.original.transform.position.z); fragment.transform.rotation = mesh.rotation; fragment.transform.localScale = mesh.localScale; fragment.transform.parent = null; fragment.transform.parent = oldParent; if (!crack) { if (mesh.original != gameObject) { Exploder2DUtils.SetActiveRecursively(mesh.original, false); } else { Exploder2DUtils.EnableCollider(mesh.original, false); Exploder2DUtils.SetVisible(mesh.original, false); } } if (!FragmentOptions.DisableColliders) { Core.MeshUtils.GeneratePolygonCollider(fragment.polygonCollider2D, mesh.spriteMesh); } if (mesh.option) { mesh.option.DuplicateSettings(fragment.options); } if (!crack) { fragment.Explode(); } var force = Force; if (mesh.option && mesh.option.UseLocalForce) { force = mesh.option.Force; } // apply force to rigid body fragment.ApplyExplosion2D(mesh.transform, mesh.centroidLocal, mainCentroid, FragmentOptions, UseForceVector, ForceVector, force, mesh.original, TargetFragments); #if SHOW_DEBUG_LINES UnityEngine.Debug.DrawLine(mainCentroid, forceVector * Force, Color.yellow, 3); #endif if (postTimer.ElapsedMilliseconds + timeOffset > FrameBudget) { return(false); } } #if DBG var watch = new Stopwatch(); watch.Start(); #endif if (!crack) { if (DestroyOriginalObject) { foreach (var mesh in postList) { if (mesh.original && !mesh.original.GetComponent <Fragment2D>()) { Object.Destroy(mesh.original); } } } if (ExplodeSelf) { if (!DestroyOriginalObject) { Exploder2DUtils.SetActiveRecursively(gameObject, false); } } if (HideSelf) { Exploder2DUtils.SetActiveRecursively(gameObject, false); } #if DBG Exploder2DUtils.Log("Explosion finished! " + postList.Count + postList[0].original.transform.gameObject.name); #endif OnExplosionFinished(true); } else { cracked = true; if (CrackedCallback != null) { CrackedCallback(); } } #if DBG postProcessingTimeEnd = watch.ElapsedMilliseconds; #endif return(true); }
void PostCrackExplode(OnExplosion callback) { if (callback != null) { callback(0.0f, ExplosionState.ExplosionStarted); } var count = postList.Count; poolIdx = 0; while (poolIdx < count) { var fragment = pool[poolIdx]; var mesh = postList[poolIdx]; poolIdx++; if (mesh.original != gameObject) { Exploder2DUtils.SetActiveRecursively(mesh.original, false); } else { Exploder2DUtils.EnableCollider(mesh.original, false); Exploder2DUtils.SetVisible(mesh.original, false); } fragment.Explode(); } if (DestroyOriginalObject) { foreach (var mesh in postList) { if (mesh.original && !mesh.original.GetComponent <Fragment2D>()) { Object.Destroy(mesh.original); } } } if (ExplodeSelf) { if (!DestroyOriginalObject) { Exploder2DUtils.SetActiveRecursively(gameObject, false); } } if (HideSelf) { Exploder2DUtils.SetActiveRecursively(gameObject, false); } #if DBG Exploder2DUtils.Log("Crack finished! " + postList.Count + postList[0].original.transform.gameObject.name); #endif ExplosionCallback = callback; OnExplosionFinished(true); }