예제 #1
0
 // Activation of kinematik/inactive
 static void ActivationCheck(RayfireRigid scrRigid)
 {
     if (scrRigid.simulationType == SimType.Inactive || scrRigid.simulationType == SimType.Kinematic)
     {
         if (scrRigid.activation.byImpact == true)
         {
             scrRigid.Activate();
         }
     }
 }
예제 #2
0
        /// /////////////////////////////////////////////////////////
        /// Coroutines
        /// /////////////////////////////////////////////////////////

        // Check velocity for activation
        public IEnumerator ActivationVelocityCor(RayfireRigid scr)
        {
            while (scr.activation.activated == false && scr.activation.byVelocity > 0)
            {
                if (scr.physics.rigidBody.velocity.magnitude > byVelocity)
                {
                    scr.Activate();
                }
                yield return(null);
            }
        }
예제 #3
0
 // Check offset for activation
 public IEnumerator ActivationOffsetCor(RayfireRigid scr)
 {
     while (scr.activation.activated == false && scr.activation.byOffset > 0)
     {
         if (Vector3.Distance(scr.transForm.position, scr.physics.initPosition) > scr.activation.byOffset)
         {
             scr.Activate();
         }
         yield return(null);
     }
 }
예제 #4
0
        // Exclude from simulation and keep object in scene
        IEnumerator DelayedActivationCor(RayfireRigid rigid)
        {
            // Wait life time
            yield return(new WaitForSeconds(delay));

            // Activate
            if (rigid != null)
            {
                rigid.Activate();
            }
        }
예제 #5
0
        // Apply damage
        public static bool ApplyDamage(RayfireRigid scr, float damageValue, Vector3 damagePoint, float damageRadius = 0f)
        {
            // Initialize if not
            if (scr.initialized == false)
            {
                scr.Initialize();
            }

            // Already demolished or should be
            if (scr.limitations.demolished == true || scr.limitations.demolitionShould == true)
            {
                return(false);
            }

            // Apply damage and get demolition state
            bool demolitionState = Apply(scr, damageValue);

            // TODO demolish first to activate only demolished fragments AND activate if object can't be demolished

            // Set demolition info
            if (demolitionState == true)
            {
                // Demolition available check
                if (scr.DemolitionState() == false)
                {
                    return(false);
                }

                // Set damage position
                scr.limitations.contactVector3     = damagePoint;
                scr.clusterDemolition.damageRadius = damageRadius;

                // Demolish object
                scr.limitations.demolitionShould = true;

                // Demolish
                scr.Demolish();

                // Was demolished
                if (scr.limitations.demolished == true)
                {
                    return(true);
                }
            }

            // Check for activation
            if (scr.activation.byDamage > 0 && scr.damage.currentDamage > scr.activation.byDamage)
            {
                scr.Activate();
            }

            return(false);
        }
예제 #6
0
        /// /////////////////////////////////////////////////////////
        /// Activation
        /// /////////////////////////////////////////////////////////

        // Check for RayFire Rigid component activation
        void ActivationCheck(Collider coll)
        {
            // Get rigid from collider or rigid body
            RayfireRigid rigid = coll.attachedRigidbody == null
                ? coll.GetComponent <RayfireRigid>()
                : coll.attachedRigidbody.GetComponent <RayfireRigid>();

            // Has no rigid
            if (rigid == null)
            {
                return;
            }

            // Activation
            if (rigid.activation.byActivator == true)
            {
                if (rigid.simulationType == SimType.Inactive || rigid.simulationType == SimType.Kinematic)
                {
                    if (delay <= 0)
                    {
                        rigid.Activate();
                    }
                    else
                    {
                        StartCoroutine(DelayedActivationCor(rigid));
                    }
                }
            }

            // Connected cluster one fragment detach
            if (rigid.objectType == ObjectType.ConnectedCluster)
            {
                if (demolishCluster == true)
                {
                    if (delay <= 0)
                    {
                        RFDemolitionCluster.DemolishConnectedCluster(rigid, new[] { coll });
                    }
                    else
                    {
                        StartCoroutine(DelayedClusterCor(rigid, coll));
                    }
                }
            }
        }
예제 #7
0
        /// /////////////////////////////////////////////////////////
        /// Activation
        /// /////////////////////////////////////////////////////////

        // Check for RayFire Rigid component activation
        void ActivationCheck(Collider coll)
        {
            RayfireRigid scrRigid = coll.gameObject.GetComponent <RayfireRigid>();

            if (scrRigid != null && scrRigid.activation.byActivator == true)
            {
                if (scrRigid.simulationType == SimType.Inactive || scrRigid.simulationType == SimType.Kinematic)
                {
                    if (delay <= 0)
                    {
                        scrRigid.Activate();
                    }
                    else
                    {
                        StartCoroutine(DelayedActivationCor(scrRigid));
                    }
                }
            }
        }
예제 #8
0
        /// /////////////////////////////////////////////////////////
        /// Coroutines
        /// /////////////////////////////////////////////////////////

        // Exclude from simulation, move under ground, destroy
        static IEnumerator FadeMoveDown(RayfireRigid scr)
        {
            // Activate inactive
            if (scr.simulationType == SimType.Inactive)
            {
                scr.Activate();
            }

            // Wale up if sleeping
            scr.physics.rigidBody.WakeUp();

            // Turn off collider // TODO CHECK CLUSTER COLLIDERS
            scr.physics.meshCollider.enabled = false;

            // Wait to fall down
            yield return(new WaitForSeconds(scr.fading.fadeTime));

            // Check if fragment is the last child in root and delete root as well
            RayfireMan.DestroyFragment(scr, scr.rootParent);
        }
예제 #9
0
        /// /////////////////////////////////////////////////////////
        /// Coroutines
        /// /////////////////////////////////////////////////////////

        // Exclude from simulation, move under ground, destroy
        static IEnumerator FadeMoveDown(RayfireRigid scr)
        {
            // Activate inactive
            if (scr.simulationType == SimType.Inactive)
            {
                scr.Activate();
            }

            // Wale up if sleeping
            scr.physics.rigidBody.WakeUp();

            // Turn off collider
            if (scr.objectType == ObjectType.Mesh)
            {
                if (scr.physics.meshCollider != null)
                {
                    scr.physics.meshCollider.enabled = false;
                }
            }
            else if (scr.objectType == ObjectType.ConnectedCluster || scr.objectType == ObjectType.NestedCluster)
            {
                if (scr.physics.clusterColliders != null)
                {
                    for (int i = 0; i < scr.physics.clusterColliders.Count; i++)
                    {
                        scr.physics.clusterColliders[i].enabled = false;
                    }
                }
            }

            // Wait to fall down
            yield return(new WaitForSeconds(scr.fading.fadeTime));

            // Check if fragment is the last child in root and delete root as well
            RayfireMan.DestroyFragment(scr, scr.rootParent);
        }
예제 #10
0
        // Impact hit to rigid bodies. Activated inactive, detach clusters
        void ImpactHit(RayfireRigid rigid, RaycastHit hit, Vector3 impactPoint, Vector3 shootVector)
        {
            // Prepare impact list
            List <Rigidbody> impactRbList = new List <Rigidbody>();

            // Hit object Impact activation and detach before impact force
            if (radius == 0)
            {
                // Inactive Activation
                if (rigid.objectType == ObjectType.Mesh)
                {
                    if (rigid.simulationType == SimType.Inactive || rigid.simulationType == SimType.Kinematic)
                    {
                        if (rigid.activation.byImpact == true)
                        {
                            rigid.Activate();
                        }
                    }
                }

                // Connected cluster one fragment detach
                if (rigid.objectType == ObjectType.ConnectedCluster)
                {
                    if (demolishCluster == true)
                    {
                        RFDemolitionCluster.DemolishConnectedCluster(rigid, new[] { hit.collider });
                    }
                }

                // Collect for impact
                impactRbList.Add(hit.collider.attachedRigidbody);
            }

            // Group by radius Impact activation and detach before impact force
            if (radius > 0)
            {
                // Get all colliders
                impactColliders = null;
                impactColliders = Physics.OverlapSphere(impactPoint, radius, mask);

                // TODO tag filter
                if (tagFilter != untagged)
                {
                    //  && colliders[i].CompareTag (tagFilter) == false)
                }

                // No colliders. Stop
                if (impactColliders == null)
                {
                    return;
                }

                // Connected cluster group detach first, check for rigids in range next
                if (rigid.objectType == ObjectType.ConnectedCluster)
                {
                    if (demolishCluster == true)
                    {
                        RFDemolitionCluster.DemolishConnectedCluster(rigid, impactColliders);
                    }
                }

                // Collect all rigid bodies in range
                RayfireRigid        scr;
                List <RayfireRigid> impactRigidList = new List <RayfireRigid>();
                for (int i = 0; i < impactColliders.Length; i++)
                {
                    // Get rigid from collider or rigid body
                    scr = impactColliders[i].attachedRigidbody == null
                        ? impactColliders[i].GetComponent <RayfireRigid>()
                        : impactColliders[i].attachedRigidbody.transform.GetComponent <RayfireRigid>();

                    // Collect uniq rigids in radius
                    if (scr != null)
                    {
                        if (impactRigidList.Contains(scr) == false)
                        {
                            impactRigidList.Add(scr);
                        }
                    }
                    // Collect RigidBodies without rigid script
                    else
                    {
                        if (affectRigidBodies == true)
                        {
                            if (impactColliders[i].attachedRigidbody == null)
                            {
                                if (impactRbList.Contains(impactColliders[i].attachedRigidbody) == false)
                                {
                                    impactRbList.Add(impactColliders[i].attachedRigidbody);
                                }
                            }
                        }
                    }
                }

                // Group Activation first
                for (int i = 0; i < impactRigidList.Count; i++)
                {
                    if (impactRigidList[i].activation.byImpact == true)
                    {
                        if (impactRigidList[i].simulationType == SimType.Inactive || impactRigidList[i].simulationType == SimType.Kinematic)
                        {
                            impactRigidList[i].Activate();
                        }
                    }
                }

                // Collect rigid body from rigid components
                if (strength > 0)
                {
                    for (int i = 0; i < impactRigidList.Count; i++)
                    {
                        // Skip inactive objects
                        if (impactRigidList[i].simulationType == SimType.Inactive && affectInactive == false)
                        {
                            continue;
                        }

                        // Collect
                        impactRbList.Add(impactRigidList[i].physics.rigidBody);
                    }
                }
            }

            // NO Strength
            if (strength == 0)
            {
                return;
            }

            // No rigid bodies
            if (impactRbList.Count == 0)
            {
                return;
            }

            // Apply force
            for (int i = 0; i < impactRbList.Count; i++)
            {
                // Skip static and kinematik objects
                if (impactRbList[i] == null || impactRbList[i].isKinematic == true)
                {
                    continue;
                }

                // Add force
                impactRbList[i].AddForceAtPosition(shootVector * strength, impactPoint, ForceMode.VelocityChange);
            }
        }