Esempio n. 1
0
        public void OnExplosionFinished(int id, long ellapsedMS)
        {
            ExploderParams exploderParams = this.queue.Dequeue();

            if (exploderParams.Callback != null)
            {
                exploderParams.Callback((float)ellapsedMS, !exploderParams.Crack ? ExploderObject.ExplosionState.ExplosionFinished : ExploderObject.ExplosionState.ObjectCracked);
            }
            this.ProcessQueue();
        }
Esempio n. 2
0
        public long Explode()
        {
            var count   = pool.Count;
            var poolIdx = 0;

            if (count == 0)
            {
                return(0);
            }

            watch.Start();

            if (parameters.Callback != null)
            {
                parameters.Callback(0, ExploderObject.ExplosionState.ExplosionStarted);
            }

            var diffPos = Vector3.zero;
            var diffRot = Quaternion.identity;

            if (originalObject)
            {
                diffPos = originalObject.transform.position - initPos;
                diffRot = originalObject.transform.rotation * Quaternion.Inverse(initRot);
            }

            while (poolIdx < count)
            {
                var fragment = pool[poolIdx];

                poolIdx++;

                if (originalObject != parameters.ExploderGameObject)
                {
                    ExploderUtils.SetActiveRecursively(originalObject, false);
                }
                else
                {
                    ExploderUtils.EnableCollider(originalObject, false);
                    ExploderUtils.SetVisible(originalObject, false);
                }

                fragment.transform.position += diffPos;
                fragment.transform.rotation *= diffRot;

                fragment.Explode();
            }

            if (parameters.DestroyOriginalObject)
            {
                if (originalObject && !originalObject.GetComponent <Fragment>())
                {
                    GameObject.Destroy(originalObject);
                }
            }

            if (parameters.ExplodeSelf)
            {
                if (!parameters.DestroyOriginalObject)
                {
                    ExploderUtils.SetActiveRecursively(parameters.ExploderGameObject, false);
                }
            }

            if (parameters.HideSelf)
            {
                ExploderUtils.SetActiveRecursively(parameters.ExploderGameObject, false);
            }

            watch.Stop();
            return(watch.ElapsedMilliseconds);
        }