Example #1
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;
     DeactivateOptions           = exploder.DeactivateOptions;
     DeactivateTimeout           = exploder.DeactivateTimeout;
     MeshColliders               = exploder.MeshColliders;
     ExplodeSelf                 = exploder.ExplodeSelf;
     HideSelf                    = exploder.HideSelf;
     ThreadOptions               = exploder.ThreadOption;
     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;
     DisableRadiusScan           = exploder.DisableRadiusScan;
     UniformFragmentDistribution = exploder.UniformFragmentDistribution;
     DisableTriangulation        = exploder.DisableTriangulation;
     ExploderGameObject          = exploder.gameObject;
 }
 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;
 }
Example #3
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);
                }
            }
        }
Example #4
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;
        }
Example #5
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 PHYSICS_2D
            if (rigid2D)
            {
                ApplyExplosion2D(meshTransform, centroid, mainCentroid, fragmentOption, useForceVector, ForceVector, force, original, targetFragments);
                return;
            }
#endif

            var rigid = rigidBody;

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

            // 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;
                }
            }

            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;
        }