Ejemplo n.º 1
0
        public void StartExplosionFromQueue(ExploderParams p)
        {
            ExploderUtils.Assert(currTaskType == TaskType.None, "Wrong task: " + currTaskType);
            this.parameters  = p;
            processingFrames = 1;
            explosionWatch.Reset();
            explosionWatch.Start();

            //
            // do preprocess right away
            //
            currTaskType = TaskType.Preprocess;
            InitTask(currTaskType);
            RunTask(currTaskType);

            if (parameters.ThreadOptions != ExploderObject.ThreadOptions.Disabled)
            {
                currTaskType = NextTask(currTaskType);

                if (currTaskType != TaskType.None)
                {
                    InitTask(currTaskType);
                    RunTask(currTaskType, parameters.FrameBudget);
                }
                else
                {
                    explosionWatch.Stop();
                    queue.OnExplosionFinished(parameters.id, explosionWatch.ElapsedMilliseconds);
                }
            }
        }
Ejemplo n.º 2
0
        public CrackedObject Create(GameObject originalObject, ExploderParams parameters)
        {
            CrackedObject crackedObject = new CrackedObject(originalObject, parameters);

            this.crackedObjects[originalObject] = crackedObject;
            return(crackedObject);
        }
Ejemplo n.º 3
0
        public void StartExplosionFromQueue(ExploderParams p)
        {
            this.parameters       = p;
            this.processingFrames = 1;
            this.explosionWatch.Reset();
            this.explosionWatch.Start();
            AudioSource component = (AudioSource)p.ExploderGameObject.GetComponent <AudioSource>();

            if (Object.op_Implicit((Object)component))
            {
                ExploderUtils.CopyAudioSource(component, this.audioSource);
            }
            this.currTaskType = TaskType.Preprocess;
            this.InitTask(this.currTaskType);
            this.RunTask(this.currTaskType, 0.0f);
            if (this.parameters.ThreadOptions == ExploderObject.ThreadOptions.Disabled)
            {
                return;
            }
            this.currTaskType = this.NextTask(this.currTaskType);
            if (this.currTaskType != TaskType.None)
            {
                this.InitTask(this.currTaskType);
                this.RunTask(this.currTaskType, this.parameters.FrameBudget);
            }
            else
            {
                this.explosionWatch.Stop();
                this.queue.OnExplosionFinished(this.parameters.id, this.explosionWatch.ElapsedMilliseconds);
            }
        }
Ejemplo n.º 4
0
 public void Reset(ExploderParams parameters)
 {
     Allocate(parameters.FragmentPoolSize, parameters.FragmentOptions.MeshColliders, parameters.Use2DCollision);
     SetExplodableFragments(parameters.FragmentOptions.ExplodeFragments, parameters.DontUseTag);
     SetFragmentPhysicsOptions(parameters.FragmentOptions, parameters.Use2DCollision);
     SetSFXOptions(parameters.FragmentSFX);
 }
Ejemplo n.º 5
0
 public CrackedObject(GameObject originalObject, ExploderParams parameters)
 {
     this.originalObject = originalObject;
     this.parameters     = parameters;
     this.fractureGrid   = new FractureGrid(this);
     this.initPos        = originalObject.get_transform().get_position();
     this.initRot        = originalObject.get_transform().get_rotation();
     this.watch          = new Stopwatch();
 }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
        public CrackedObject Create(GameObject originalObject, ExploderParams parameters)
        {
//            Debug.Assert(!crackedObjects.ContainsKey(originalObject), "GameObject already cracked!");

            var crackedObject = new CrackedObject(originalObject, parameters);

            crackedObjects[originalObject] = crackedObject;

            return(crackedObject);
        }
Ejemplo n.º 8
0
        public CrackedObject(GameObject originalObject, ExploderParams parameters)
        {
            this.originalObject = originalObject;
            this.parameters     = parameters;

            this.initPos = originalObject.transform.position;
            this.initRot = originalObject.transform.rotation;

            watch = new Stopwatch();
        }
Ejemplo n.º 9
0
        public void Initialize(ExploderObject exploder)
        {
            if (initialized)
            {
                return;
            }

            initialized = true;
            parameters  = new ExploderParams(exploder);

            // init pool
            FragmentPool.Instance.Reset(parameters);
            frameWatch     = new Stopwatch();
            explosionWatch = new Stopwatch();

            crackManager = new CrackManager(this);

            bakeSkinManager = new BakeSkinManager(this);

            //
            // init queue
            //
            queue = new ExploderQueue(this);

            //
            // init tasks
            //
            tasks = new ExploderTask[(int)TaskType.TaskMax];

            tasks[(int)TaskType.Preprocess] = new Preprocess(this);

#if DISABLE_MULTITHREADING
            tasks[(int)TaskType.ProcessCutter] = new CutterST(this);
#else
            if (parameters.ThreadOptions == ExploderObject.ThreadOptions.Disabled)
            {
                tasks[(int)TaskType.ProcessCutter] = new CutterST(this);
            }
            else
            {
                tasks[(int)TaskType.ProcessCutter] = new CutterMT(this);
            }
#endif

            tasks[(int)TaskType.IsolateMeshIslands] = new IsolateMeshIslands(this);
            tasks[(int)TaskType.PostprocessExplode] = new PostprocessExplode(this);
            tasks[(int)TaskType.PostprocessCrack]   = new PostprocessCrack(this);

            PreAllocateBuffers();

            audioSource = gameObject.AddComponent <AudioSource>();
        }
Ejemplo n.º 10
0
        public void Enqueue(ExploderObject exploderObject, ExploderObject.OnExplosion callback, bool crack, params GameObject[] target)
        {
            var settings = new ExploderParams(exploderObject)
            {
                Callback   = callback,
                Targets    = target,
                Crack      = crack,
                processing = false
            };

            queue.Enqueue(settings);
            ProcessQueue();
        }
Ejemplo n.º 11
0
        private void ProcessQueue()
        {
            if (this.queue.Count <= 0)
            {
                return;
            }
            ExploderParams p = this.queue.Peek();

            if (p.processing)
            {
                return;
            }
            p.id         = Random.Range(int.MinValue, int.MaxValue);
            p.processing = true;
            this.core.StartExplosionFromQueue(p);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// apply physical explosion to fragment piece
        /// </summary>
        public void ApplyExplosion(ExploderTransform meshTransform, Vector3 centroid, float force, GameObject original, ExploderParams set)
        {
            this.settings = set;

            if (rigid2D)
            {
                ApplyExplosion2D(meshTransform, centroid, force, original);
                return;
            }

            var rigid = rigidBody;

            // apply fragment mass and velocity properties
            var parentVelocity        = Vector3.zero;
            var parentAngularVelocity = Vector3.zero;
            var mass       = settings.FragmentOptions.Mass;
            var useGravity = settings.FragmentOptions.UseGravity;

            rigid.maxAngularVelocity = settings.FragmentOptions.MaxAngularVelocity;

            // inherit velocity and mass from original object
            if (settings.FragmentOptions.InheritParentPhysicsProperty)
            {
                if (original && original.GetComponent <Rigidbody>())
                {
                    var parentRigid = original.GetComponent <Rigidbody>();

                    parentVelocity        = parentRigid.velocity;
                    parentAngularVelocity = parentRigid.angularVelocity;
                    mass       = parentRigid.mass / settings.TargetFragments;
                    useGravity = parentRigid.useGravity;
                }
            }

            var forceVector     = (meshTransform.TransformPoint(centroid) - settings.Position).normalized;
            var angularVelocity = settings.FragmentOptions.AngularVelocity * (settings.FragmentOptions.RandomAngularVelocityVector ? Random.onUnitSphere : settings.FragmentOptions.AngularVelocityVector);

            if (settings.UseForceVector)
            {
                forceVector = settings.ForceVector;
            }

            rigid.velocity        = forceVector * force + parentVelocity;
            rigid.angularVelocity = angularVelocity + parentAngularVelocity;
            rigid.mass            = mass;
            rigid.useGravity      = useGravity;
        }
Ejemplo n.º 13
0
        public void EnqueuePartialExplosion(ExploderObject exploderObject, ExploderObject.OnExplosion callback,
                                            GameObject target, Vector3 shotDir, Vector3 hitPosition, float bulletSize)
        {
            var settings = new ExploderParams(exploderObject)
            {
                Callback         = callback,
                Target           = target,
                HitPosition      = hitPosition,
                BulletSize       = bulletSize,
                PartialExplosion = true,
                ShotDir          = shotDir,
                processing       = false,
            };

            queue.Enqueue(settings);
            ProcessQueue();
        }
Ejemplo n.º 14
0
 public void Explode(ExploderParams parameters)
 {
     this.settings = parameters;
     this.IsActive = true;
     ExploderUtils.SetActiveRecursively(((Component)this).get_gameObject(), true);
     this.visibilityCheckTimer = 0.1f;
     this.Visible         = true;
     this.Cracked         = false;
     this.collided        = false;
     this.deactivateTimer = this.settings.FragmentDeactivation.DeactivateTimeout;
     this.originalScale   = ((Component)this).get_transform().get_localScale();
     if (this.settings.FragmentOptions.ExplodeFragments)
     {
         ((Component)this).set_tag(ExploderObject.Tag);
     }
     this.Emit(true);
 }
Ejemplo n.º 15
0
        /// <summary>
        /// this is called from exploder class to start the explosion
        /// </summary>
        public void Explode(ExploderParams parameters)
        {
            this.settings = parameters;

            IsActive = true;
            ExploderUtils.SetActiveRecursively(gameObject, true);
            visibilityCheckTimer = 0.1f;
            Visible         = true;
            Cracked         = false;
            collided        = false;
            deactivateTimer = settings.FragmentDeactivation.DeactivateTimeout;
            originalScale   = transform.localScale;

            if (settings.FragmentOptions.ExplodeFragments)
            {
                tag = ExploderObject.Tag;
            }

            Emit(true);
        }
Ejemplo n.º 16
0
 public void ApplyExplosion(
     ExploderTransform meshTransform,
     Vector3 centroid,
     float force,
     GameObject original,
     ExploderParams set)
 {
     this.settings = set;
     if (Object.op_Implicit((Object)this.rigid2D))
     {
         this.ApplyExplosion2D(meshTransform, centroid, force, original);
     }
     else
     {
         Rigidbody rigidBody  = this.rigidBody;
         Vector3   vector3_1  = Vector3.get_zero();
         Vector3   vector3_2  = Vector3.get_zero();
         float     num        = this.settings.FragmentOptions.Mass;
         bool      useGravity = this.settings.FragmentOptions.UseGravity;
         rigidBody.set_maxAngularVelocity(this.settings.FragmentOptions.MaxAngularVelocity);
         if (this.settings.FragmentOptions.InheritParentPhysicsProperty && Object.op_Implicit((Object)original) && Object.op_Implicit((Object)original.GetComponent <Rigidbody>()))
         {
             Rigidbody component = (Rigidbody)original.GetComponent <Rigidbody>();
             vector3_1  = component.get_velocity();
             vector3_2  = component.get_angularVelocity();
             num        = component.get_mass() / (float)this.settings.TargetFragments;
             useGravity = component.get_useGravity();
         }
         Vector3 vector3_3 = Vector3.op_Subtraction(meshTransform.TransformPoint(centroid), this.settings.Position);
         Vector3 vector3_4 = ((Vector3) ref vector3_3).get_normalized();
         Vector3 vector3_5 = Vector3.op_Multiply(this.settings.FragmentOptions.AngularVelocity, !this.settings.FragmentOptions.RandomAngularVelocityVector ? this.settings.FragmentOptions.AngularVelocityVector : Random.get_onUnitSphere());
         if (this.settings.UseForceVector)
         {
             vector3_4 = this.settings.ForceVector;
         }
         rigidBody.set_velocity(Vector3.op_Addition(Vector3.op_Multiply(vector3_4, force), vector3_1));
         rigidBody.set_angularVelocity(Vector3.op_Addition(vector3_5, vector3_2));
         rigidBody.set_mass(num);
         rigidBody.set_useGravity(useGravity);
     }
 }
Ejemplo n.º 17
0
 public void Initialize(ExploderObject exploder)
 {
     if (this.initialized)
     {
         return;
     }
     this.initialized = true;
     this.parameters  = new ExploderParams(exploder);
     FragmentPool.Instance.Reset(this.parameters);
     this.frameWatch      = new Stopwatch();
     this.explosionWatch  = new Stopwatch();
     this.crackManager    = new CrackManager(this);
     this.bakeSkinManager = new BakeSkinManager(this);
     this.queue           = new ExploderQueue(this);
     this.tasks           = new ExploderTask[6];
     this.tasks[1]        = (ExploderTask) new Preprocess(this);
     this.tasks[2]        = this.parameters.ThreadOptions != ExploderObject.ThreadOptions.Disabled ? (ExploderTask) new CutterMT(this) : (ExploderTask) new CutterST(this);
     this.tasks[3]        = (ExploderTask) new IsolateMeshIslands(this);
     this.tasks[4]        = (ExploderTask) new PostprocessExplode(this);
     this.tasks[5]        = (ExploderTask) new PostprocessCrack(this);
     this.PreAllocateBuffers();
     this.audioSource = (AudioSource)((Component)this).get_gameObject().AddComponent <AudioSource>();
 }
Ejemplo n.º 18
0
        public void Initialize(ExploderObject exploder)
        {
            if (initialized)
            {
                return;
            }

            initialized = true;
            parameters  = new ExploderParams(exploder);

            // init pool
            FragmentPool.Instance.Allocate(parameters.FragmentPoolSize, parameters.MeshColliders, parameters.Use2DCollision, parameters.FragmentPrefab);
            FragmentPool.Instance.SetDeactivateOptions(parameters.DeactivateOptions, parameters.FadeoutOptions, parameters.DeactivateTimeout);
            FragmentPool.Instance.SetExplodableFragments(parameters.ExplodeFragments, parameters.DontUseTag);
            FragmentPool.Instance.SetFragmentPhysicsOptions(parameters.FragmentOptions, parameters.Use2DCollision);
            FragmentPool.Instance.SetSFXOptions(parameters.SFXOptions);
            frameWatch     = new Stopwatch();
            explosionWatch = new Stopwatch();

            crackManager = new CrackManager();

            //
            // init queue
            //
            queue = new ExploderQueue(this);

            //
            // init tasks
            //
            tasks = new ExploderTask[(int)TaskType.TaskMax];

            tasks[(int)TaskType.Preprocess] = new Preprocess(this);

#if DISABLE_MULTITHREADING
            tasks[(int)TaskType.ProcessCutter] = new CutterST(this);
#else
            if (parameters.ThreadOptions == ExploderObject.ThreadOptions.Disabled)
            {
                tasks[(int)TaskType.ProcessCutter] = new CutterST(this);
            }
            else
            {
                tasks[(int)TaskType.ProcessCutter] = new CutterMT(this);
            }
#endif

            tasks[(int)TaskType.IsolateMeshIslands] = new IsolateMeshIslands(this);
            tasks[(int)TaskType.PostprocessExplode] = new PostprocessExplode(this);
            tasks[(int)TaskType.PostprocessCrack]   = new PostprocessCrack(this);
            tasks[(int)TaskType.PartialSeparator]   = new PartialSeparator(this);

            PreAllocateBuffers();

            if (parameters.SFXOptions.ExplosionSoundClip)
            {
                audioSource = gameObject.GetComponent <AudioSource>();

                if (!audioSource)
                {
                    audioSource = gameObject.AddComponent <AudioSource>();
                }
            }
        }