Пример #1
0
        // Exclude from simulation and keep object in scene
        static void FadeExclude(RayfireRigid scr)
        {
            // Set faded
            scr.fading.state = 2;

            // Not going to be reused
            if (scr.reset.action == RFReset.PostDemolitionType.DestroyWithDelay)
            {
                scr.DestroyRb(scr.physics.rigidBody);
                scr.DestroyCollider(scr.physics.meshCollider);
                scr.DestroyRigid(scr);
            }

            // Going to be reused
            else if (scr.reset.action == RFReset.PostDemolitionType.DeactivateToReset)
            {
                scr.physics.rigidBody.isKinematic = true;
                scr.physics.meshCollider.enabled  = false; // TODO CHECK CLUSTER COLLIDERS
                scr.StopAllCoroutines();
            }
        }
Пример #2
0
        // Demolish connected cluster
        static void DemolishClusterConnected(RayfireRigid scr)
        {
            // TODO If demolition.chunkRadius == 100. Detach all.
            // TODO Infinite demolition to detached frags.

            // Get detach radius distance
            float detachRadius = scr.limitations.bboxSize / 100f * scr.clusterDemolition.contactRadius;

            // Damage radius. TODO reset it.
            if (scr.clusterDemolition.damageRadius > 0)
            {
                detachRadius = scr.clusterDemolition.damageRadius;
            }

            // Detached solo fragments
            List <RFShard> detachShards = new List <RFShard>();

            // Get all colliders TODO input mask by gameobject
            List <Collider> detachColliders = Physics.OverlapSphere(scr.limitations.contactPoint, detachRadius).ToList();

            // No colliders to detach
            if (detachColliders.Count == 0)
            {
                return;
            }

            // Detach contacted fragments to solo. IMPROVE force spread by shards connection info. Connectivity check
            for (int i = scr.physics.clusterColliders.Count - 1; i >= 0; i--)
            {
                if (detachColliders.Contains(scr.physics.clusterColliders[i]))
                {
                    // Detach shard ans im them solo
                    detachShards.Add(scr.clusterDemolition.cluster.shards[i]);
                    scr.clusterDemolition.cluster.shards.RemoveAt(i);

                    // Destroy colliders to keep original cluster in scene
                    scr.DestroyCollider(scr.physics.clusterColliders[i]);
                    scr.physics.clusterColliders.RemoveAt(i);
                }
            }

            // No detach shards
            if (detachShards.Count == 0)
            {
                return;
            }

            // Prepare
            scr.fragments = new List <RayfireRigid>();

            // Create parent for all fragments.
            GameObject root = new GameObject(scr.gameObject.name + "_root");

            root.transform.parent  = RayfireMan.inst.transForm;
            scr.rootChild          = root.transform;
            scr.rootChild.position = scr.transForm.position;
            scr.rootChild.rotation = scr.transForm.rotation;

            // Get tm list for detached shards
            List <Transform> detachChildren = detachShards.Select(t => t.tm).ToList();

            // Add rigid component to detached children
            AddRigidComponent(scr, detachChildren);

            // Parent to main root
            for (int i = 0; i < detachChildren.Count; i++)
            {
                detachChildren[i].parent = root.transform;
            }

            // All shards were detached. Set demolished state
            if (scr.clusterDemolition.cluster.shards.Count == 0)
            {
                scr.limitations.demolished = true;
                return;
            }

            // Check cluster for connectivity and return list of not connected clusters
            scr.clusterDemolition.cluster.childClusters = RFCluster.ConnectivityCheck(scr.clusterDemolition.cluster.shards);

            // CLuster is demolished
            scr.limitations.demolished = true;

            // Main cluster connected. Create new cluster based on left shards. IMPORTANT. attempt to use old cluster with old RB cause sim instability
            if (scr.clusterDemolition.cluster.childClusters.Count == 0)
            {
                CreateClusterRuntime(scr, scr.clusterDemolition.cluster);
            }

            // Main cluster not connected. Create connected cluster for every cluster in list
            else
            {
                foreach (RFCluster cls in scr.clusterDemolition.cluster.childClusters)
                {
                    CreateClusterRuntime(scr, cls);
                }
            }

            // Turn off demolition for solo fragments
            if (scr.clusterDemolition.meshDemolition == false)
            {
                foreach (var frag in scr.fragments)
                {
                    if (frag.objectType == ObjectType.Mesh)
                    {
                        frag.demolitionType = DemolitionType.None;
                    }
                }
            }
        }