public ExploderSettings(ExploderObject exploder)
 {
     Position = ExploderUtils.GetCentroid(exploder.gameObject);
     DontUseTag = exploder.DontUseTag;
     Radius = exploder.Radius;
     UseCubeRadius = exploder.UseCubeRadius;
     CubeRadius = exploder.CubeRadius;
     ForceVector = exploder.ForceVector;
     UseForceVector = exploder.UseForceVector;
     Force = exploder.Force;
     FrameBudget = exploder.FrameBudget;
     TargetFragments = exploder.TargetFragments;
     DeactivateOptions = exploder.DeactivateOptions;
     DeactivateTimeout = exploder.DeactivateTimeout;
     MeshColliders = exploder.MeshColliders;
     ExplodeSelf = exploder.ExplodeSelf;
     HideSelf = exploder.HideSelf;
     DestroyOriginalObject = exploder.DestroyOriginalObject;
     ExplodeFragments = exploder.ExplodeFragments;
     SplitMeshIslands = exploder.SplitMeshIslands;
     FragmentOptions = exploder.FragmentOptions.Clone();
     SfxOptions = exploder.SFXOptions.Clone();
     Use2DCollision = exploder.Use2DCollision;
     FragmentPoolSize = exploder.FragmentPoolSize;
     FragmentPrefab = exploder.FragmentPrefab;
     FadeoutOptions = exploder.FadeoutOptions;
     SFXOptions = exploder.SFXOptions;
     DisableRadiusScan = exploder.DisableRadiusScan;
     UniformFragmentDistribution = exploder.UniformFragmentDistribution;
     AllowOpenMeshCutting = exploder.AllowOpenMeshCutting;
 }
Пример #2
0
 void OnExplosion(float timeMS, ExploderObject.ExplosionState state)
 {
     if (state == ExploderObject.ExplosionState.ExplosionFinished)
     {
         Finish();
     }
 }
Пример #3
0
 public ExploderParams(ExploderObject exploder)
 {
     Position                    = ExploderUtils.GetCentroid(exploder.gameObject);
     DontUseTag                  = exploder.DontUseTag;
     Radius                      = exploder.Radius;
     UseCubeRadius               = exploder.UseCubeRadius;
     CubeRadius                  = exploder.CubeRadius;
     ForceVector                 = exploder.ForceVector;
     UseForceVector              = exploder.UseForceVector;
     Force                       = exploder.Force;
     FrameBudget                 = exploder.FrameBudget;
     TargetFragments             = exploder.TargetFragments;
     ExplodeSelf                 = exploder.ExplodeSelf;
     HideSelf                    = exploder.HideSelf;
     ThreadOptions               = exploder.ThreadOption;
     DestroyOriginalObject       = exploder.DestroyOriginalObject;
     SplitMeshIslands            = exploder.SplitMeshIslands;
     FragmentOptions             = exploder.FragmentOptions.Clone();
     FragmentDeactivation        = exploder.FragmentDeactivation.Clone();
     FragmentSFX                 = exploder.FragmentSFX.Clone();
     Use2DCollision              = exploder.Use2DCollision;
     FragmentPoolSize            = exploder.FragmentPoolSize;
     DisableRadiusScan           = exploder.DisableRadiusScan;
     UniformFragmentDistribution = exploder.UniformFragmentDistribution;
     DisableTriangulation        = exploder.DisableTriangulation;
     ExploderGameObject          = exploder.gameObject;
     CuttingStyle                = exploder.CuttingStyle;
 }
Пример #4
0
 public ExploderParams(ExploderObject exploder)
 {
     this.Position                    = ExploderUtils.GetCentroid(((Component)exploder).get_gameObject());
     this.DontUseTag                  = exploder.DontUseTag;
     this.Radius                      = exploder.Radius;
     this.UseCubeRadius               = exploder.UseCubeRadius;
     this.CubeRadius                  = exploder.CubeRadius;
     this.ForceVector                 = exploder.ForceVector;
     this.UseForceVector              = exploder.UseForceVector;
     this.Force                       = exploder.Force;
     this.FrameBudget                 = exploder.FrameBudget;
     this.TargetFragments             = exploder.TargetFragments;
     this.ExplodeSelf                 = exploder.ExplodeSelf;
     this.HideSelf                    = exploder.HideSelf;
     this.ThreadOptions               = exploder.ThreadOption;
     this.DestroyOriginalObject       = exploder.DestroyOriginalObject;
     this.SplitMeshIslands            = exploder.SplitMeshIslands;
     this.FragmentOptions             = exploder.FragmentOptions.Clone();
     this.FragmentDeactivation        = exploder.FragmentDeactivation.Clone();
     this.FragmentSFX                 = exploder.FragmentSFX.Clone();
     this.Use2DCollision              = exploder.Use2DCollision;
     this.FragmentPoolSize            = exploder.FragmentPoolSize;
     this.DisableRadiusScan           = exploder.DisableRadiusScan;
     this.UniformFragmentDistribution = exploder.UniformFragmentDistribution;
     this.DisableTriangulation        = exploder.DisableTriangulation;
     this.ExploderGameObject          = ((Component)exploder).get_gameObject();
     this.CuttingStyle                = exploder.CuttingStyle;
 }
Пример #5
0
 public ExploderSettings(ExploderObject exploder)
 {
     Position                    = ExploderUtils.GetCentroid(exploder.gameObject);
     DontUseTag                  = exploder.DontUseTag;
     Radius                      = exploder.Radius;
     UseCubeRadius               = exploder.UseCubeRadius;
     CubeRadius                  = exploder.CubeRadius;
     ForceVector                 = exploder.ForceVector;
     UseForceVector              = exploder.UseForceVector;
     Force                       = exploder.Force;
     FrameBudget                 = exploder.FrameBudget;
     TargetFragments             = exploder.TargetFragments;
     DeactivateOptions           = exploder.DeactivateOptions;
     DeactivateTimeout           = exploder.DeactivateTimeout;
     MeshColliders               = exploder.MeshColliders;
     ExplodeSelf                 = exploder.ExplodeSelf;
     HideSelf                    = exploder.HideSelf;
     DestroyOriginalObject       = exploder.DestroyOriginalObject;
     ExplodeFragments            = exploder.ExplodeFragments;
     SplitMeshIslands            = exploder.SplitMeshIslands;
     FragmentOptions             = exploder.FragmentOptions.Clone();
     SfxOptions                  = exploder.SFXOptions.Clone();
     Use2DCollision              = exploder.Use2DCollision;
     FragmentPoolSize            = exploder.FragmentPoolSize;
     FragmentPrefab              = exploder.FragmentPrefab;
     FadeoutOptions              = exploder.FadeoutOptions;
     SFXOptions                  = exploder.SFXOptions;
     DisableRadiusScan           = exploder.DisableRadiusScan;
     UniformFragmentDistribution = exploder.UniformFragmentDistribution;
     AllowOpenMeshCutting        = exploder.AllowOpenMeshCutting;
 }
Пример #6
0
        public void Explode(ExploderObject.OnExplosion callback)
        {
            var settings = new ExploderSettings
            {
                Position = ExploderUtils.GetCentroid(exploder.gameObject),
                DontUseTag = exploder.DontUseTag,
                Radius = exploder.Radius,
                UseCubeRadius = exploder.UseCubeRadius,
                CubeRadius = exploder.CubeRadius,
                ForceVector = exploder.ForceVector,
                UseForceVector = exploder.UseForceVector,
                Force = exploder.Force,
                FrameBudget = exploder.FrameBudget,
                TargetFragments = exploder.TargetFragments,
                DeactivateOptions = exploder.DeactivateOptions,
                DeactivateTimeout = exploder.DeactivateTimeout,
                MeshColliders = exploder.MeshColliders,
                ExplodeSelf = exploder.ExplodeSelf,
                HideSelf = exploder.HideSelf,
                DestroyOriginalObject = exploder.DestroyOriginalObject,
                ExplodeFragments = exploder.ExplodeFragments,
                SplitMeshIslands = exploder.SplitMeshIslands,
                FragmentOptions = exploder.FragmentOptions.Clone(),
                SfxOptions = exploder.SFXOptions.Clone(),
                Callback = callback,
                processing = false,
            };

            queue.Enqueue(settings);
            ProcessQueue();
        }
Пример #7
0
 public void Enqueue(
     ExploderObject exploderObject,
     ExploderObject.OnExplosion callback,
     bool crack,
     params GameObject[] obj)
 {
     this.queue.Enqueue(exploderObject, callback, crack, obj);
 }
Пример #8
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>();
        }
Пример #9
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();
        }
Пример #10
0
 public void Enqueue(
     ExploderObject exploderObject,
     ExploderObject.OnExplosion callback,
     bool crack,
     params GameObject[] target)
 {
     this.queue.Enqueue(new ExploderParams(exploderObject)
     {
         Callback   = callback,
         Targets    = target,
         Crack      = crack,
         processing = false
     });
     this.ProcessQueue();
 }
Пример #11
0
    // Use this for initialization
    void Awake()
    {
        notePostion = false;
        isExploded  = false;
        revertEvent = false;
        framePos    = new Vector3[5];

        originPos      = this.transform.position;
        originRotation = this.transform.rotation;

        mRigidbody  = this.GetComponent <Rigidbody>();
        exploderObj = GameObject.FindObjectOfType <Exploder.ExploderObject>() as Exploder.ExploderObject;

        revertHandType = Fingo.HandType.Invalid;
        canRevertClips = false;
        revertTime     = 0.0f;
    }
Пример #12
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();
        }
Пример #13
0
        /// <summary>
        /// exploder callback
        /// </summary>
        private void OnExplosion(float time, ExploderObject.ExplosionState state)
        {
            // explosion is finished
            if (state == ExploderObject.ExplosionState.ExplosionFinished)
            {
                //!
                //! HERE IS THE LIST OF ACTIVE FRAGMENTS
                //!

                //            var list = FragmentPool.Instance.GetActiveFragments();

                // NOTE:
                // if you run another explosion afterwards and you dont clear or deactivate fragmets in fragment pool
                // you might get some of the fragments from old explosion as well
                // to deactivate fragments you can call FragmentPool.Instance.DeactivateFragments()
            }
        }
Пример #14
0
    public override void BeginState(IAiProcess currentState)
    {
        m_ownerUnit.m_ai.m_dead = true;
        m_ownerUnit.Die();
        m_ownerUnit.m_unitGagebar.gameObject.SetActive(false);
        m_time = 0;

        Exploder.ExploderObject l_ExploderObject = m_ownerUnit.GetComponent <Exploder.ExploderObject> ();
        if (l_ExploderObject != null)
        {
            l_ExploderObject.Explode();
        }
        if (m_UnityActionDeadStart != null &&
            m_UnityActionDeadStart.Target != null)
        {
            m_UnityActionDeadStart.Invoke();
        }
    }
Пример #15
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>();
 }
Пример #16
0
 public ExploderQueue(ExploderObject exploder)
 {
     this.exploder = exploder;
     queue         = new Queue <ExploderSettings>();
 }
Пример #17
0
 private void Start()
 {
     this.Exploder = ExploderSingleton.Instance;
 }
Пример #18
0
        /// <summary>
        /// set options for fragment rigid bodies and layer
        /// </summary>
        public void SetFragmentPhysicsOptions(ExploderObject.FragmentOption options, bool physics2d)
        {
            if (pool != null)
            {
                var constrains = RigidbodyConstraints.None;

                if (options.FreezePositionX)
                    constrains |= RigidbodyConstraints.FreezePositionX;
                if (options.FreezePositionY)
                    constrains |= RigidbodyConstraints.FreezePositionY;
                if (options.FreezePositionZ)
                    constrains |= RigidbodyConstraints.FreezePositionZ;
                if (options.FreezeRotationX)
                    constrains |= RigidbodyConstraints.FreezeRotationX;
                if (options.FreezeRotationY)
                    constrains |= RigidbodyConstraints.FreezeRotationY;
                if (options.FreezeRotationZ)
                    constrains |= RigidbodyConstraints.FreezeRotationZ;

                foreach (var fragment in pool)
                {
                    if (fragment.gameObject)
                    {
                        fragment.gameObject.layer = LayerMask.NameToLayer(options.Layer);
                    }

                    fragment.SetConstraints(constrains);
                    fragment.DisableColliders(options.DisableColliders, meshColliders, physics2d);
                }
            }
        }
Пример #19
0
        /// <summary>
        /// set options for fragment sound and particle effects
        /// </summary>
        /// <param name="sfx"></param>
        public void SetSFXOptions(ExploderObject.SFXOption sfx)
        {
            if (pool != null)
            {
                HitSoundTimeout = sfx.HitSoundTimeout;
                MaxEmitters = sfx.EmitersMax;

                for (int i = 0; i < pool.Length; i++)
                {
                    pool[i].SetSFX(sfx, i < MaxEmitters);
                }
            }
        }
Пример #20
0
 void Start()
 {
     Exploder = Utils.ExploderSingleton.Instance;
 }
Пример #21
0
 void Start()
 {
     exploder    = GameObject.FindGameObjectWithTag("TheExploder").GetComponent <ExploderObject>();
     ForceVector = -Camera.main.transform.up.normalized;
 }
Пример #22
0
        /// <summary>
        /// apply physical explosion to fragment piece (2D case)
        /// </summary>
        void ApplyExplosion2D(Transform meshTransform, Vector3 centroid, Vector3 mainCentroid,
                              ExploderObject.FragmentOption fragmentOption,
                              bool useForceVector, Vector2 ForceVector, float force, GameObject original,
                              int targetFragments)
        {
            var rigid = rigid2D;

            // apply fragment mass and velocity properties
            var parentVelocity = Vector2.zero;
            var parentAngularVelocity = 0.0f;
            var mass = fragmentOption.Mass;

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

                    parentVelocity = parentRigid.velocity;
                    parentAngularVelocity = parentRigid.angularVelocity;
                    mass = parentRigid.mass / targetFragments;
                }
            }

            Vector2 forceVector = (meshTransform.TransformPoint(centroid) - mainCentroid).normalized;
            float angularVelocity = fragmentOption.AngularVelocity * (fragmentOption.RandomAngularVelocityVector ? Random.insideUnitCircle.x : fragmentOption.AngularVelocityVector.y);

            if (useForceVector)
            {
                forceVector = ForceVector;
            }

            rigid.velocity = forceVector * force + parentVelocity;
            rigid.angularVelocity = angularVelocity + parentAngularVelocity;
            rigid.mass = mass;
            maxVelocity = fragmentOption.MaxVelocity;
        }
Пример #23
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>();
                }
            }
        }
Пример #24
0
        /// <summary>
        /// apply physical explosion to fragment piece
        /// </summary>
        public void ApplyExplosion(Transform meshTransform, Vector3 centroid, Vector3 mainCentroid, ExploderObject.FragmentOption fragmentOption, 
                                    bool useForceVector, Vector3 ForceVector, float force, GameObject original, int targetFragments)
        {
            if (rigid2D)
            {
                ApplyExplosion2D(meshTransform, centroid, mainCentroid, fragmentOption, useForceVector, ForceVector, force, original, targetFragments);
                return;
            }

            var rigid = rigidBody;

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

            rigid.maxAngularVelocity = fragmentOption.MaxAngularVelocity;

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

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

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

            if (useForceVector)
            {
                forceVector = ForceVector;
            }

            rigid.velocity = forceVector * force + parentVelocity;
            rigid.angularVelocity = angularVelocity + parentAngularVelocity;
            rigid.mass = mass;
            maxVelocity = fragmentOption.MaxVelocity;
            rigid.useGravity = useGravity;
        }
Пример #25
0
        public void SetSFX(ExploderObject.SFXOption sfx, bool allowParticle)
        {
            audioClip = sfx.FragmentSoundClip;

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

            if (sfx.FragmentEmitter && allowParticle)
            {
                if (!particleChild)
                {
                    var dup = Instantiate(sfx.FragmentEmitter) as GameObject;

                    if (dup)
                    {
                        particleChild = new GameObject("Particles");
                        particleChild.transform.parent = gameObject.transform;

                        dup.transform.parent = particleChild.transform;
                    }
                }

                if (particleChild)
                {
                    emmiters = particleChild.GetComponentsInChildren<ParticleEmitter>();
                }

                emmitersTimeout = sfx.ParticleTimeout;
                stopEmitOnTimeout = emmitersTimeout > 0.0f;
            }
            else
            {
                if (particleChild)
                {
                    Destroy(particleChild);
                    emmitersTimeout = -1.0f;
                    stopEmitOnTimeout = false;
                }
            }
        }
        public void Enqueue(ExploderObject.OnExplosion callback, GameObject obj)
        {
            var settings = new ExploderSettings(exploder)
            {
                Callback = callback,
                Target = obj,
                processing = false
            };

            queue.Enqueue(settings);
            ProcessQueue();
        }
 public ExploderQueue(ExploderObject exploder)
 {
     this.exploder = exploder;
     queue = new Queue<ExploderSettings>();
 }
Пример #28
0
 public void Enqueue(ExploderObject exploderObject, ExploderObject.OnExplosion callback, GameObject obj, bool crack)
 {
     queue.Enqueue(exploderObject, callback, obj, crack);
 }
 void Start()
 {
     Exploder = Utils.ExploderSingleton.ExploderInstance;
 }
Пример #30
0
 public void Enqueue(ExploderObject exploderObject, ExploderObject.OnExplosion callback, GameObject obj, Vector3 shotDir, Vector3 hitPosition, float bulletSize)
 {
 }