Example #1
0
        private void ApplyExplosion2D(
            ExploderTransform meshTransform,
            Vector3 centroid,
            float force,
            GameObject original)
        {
            Rigidbody2D rigid2D   = this.rigid2D;
            Vector2     vector2_1 = Vector2.get_zero();
            float       num1      = 0.0f;
            float       num2      = this.settings.FragmentOptions.Mass;

            if (this.settings.FragmentOptions.InheritParentPhysicsProperty && Object.op_Implicit((Object)original) && Object.op_Implicit((Object)original.GetComponent <Rigidbody2D>()))
            {
                Rigidbody2D component = (Rigidbody2D)original.GetComponent <Rigidbody2D>();
                vector2_1 = component.get_velocity();
                num1      = component.get_angularVelocity();
                num2      = component.get_mass() / (float)this.settings.TargetFragments;
            }
            Vector3 vector3   = Vector3.op_Subtraction(meshTransform.TransformPoint(centroid), this.settings.Position);
            Vector2 vector2_2 = Vector2.op_Implicit(((Vector3) ref vector3).get_normalized());
            float   num3      = this.settings.FragmentOptions.AngularVelocity * (!this.settings.FragmentOptions.RandomAngularVelocityVector ? (float)this.settings.FragmentOptions.AngularVelocityVector.y : (float)Random.get_insideUnitCircle().x);

            if (this.settings.UseForceVector)
            {
                vector2_2 = Vector2.op_Implicit(this.settings.ForceVector);
            }
            rigid2D.set_velocity(Vector2.op_Addition(Vector2.op_Multiply(vector2_2, force), vector2_1));
            rigid2D.set_angularVelocity(num3 + num1);
            rigid2D.set_mass(num2);
        }
Example #2
0
        /// <summary>
        /// apply physical explosion to fragment piece (2D case)
        /// </summary>
        void ApplyExplosion2D(ExploderTransform meshTransform, Vector3 centroid, float force, GameObject original)
        {
            var rigid = rigid2D;

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

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

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

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

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

            rigid.velocity        = forceVector * force + parentVelocity;
            rigid.angularVelocity = angularVelocity + parentAngularVelocity;
            rigid.mass            = mass;
        }
Example #3
0
        /// <summary>
        /// apply physical explosion to fragment piece
        /// </summary>
        public void ApplyExplosion(ExploderTransform 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;
        }
Example #4
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;
        }
Example #5
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);
     }
 }
Example #6
0
        /// <summary>
        /// apply physical explosion to fragment piece (2D case)
        /// </summary>
        void ApplyExplosion2D(ExploderTransform 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;
        }