示例#1
0
        /// /////////////////////////////////////////////////////////
        /// Awake ops
        /// /////////////////////////////////////////////////////////

        // Init mesh root. Copy Rigid component for children with mesh
        bool SetRootMesh()
        {
            if (objectType == ObjectType.MeshRoot)
            {
                // Stop if already initiated
                if (limitations.demolished == true || physics.exclude == true)
                {
                    return(true);
                }

                // Get children
                List <Transform> children = new List <Transform>();
                for (int i = 0; i < transform.childCount; i++)
                {
                    children.Add(transform.GetChild(i));
                }

                // Add Rigid to child with mesh
                fragments = new List <RayfireRigid>();
                for (int i = 0; i < children.Count; i++)
                {
                    if (children[i].GetComponent <MeshFilter>() != null)
                    {
                        // Get rigid  // TODO check if fragment already has Rigid, Reinit in this case.
                        RayfireRigid childRigid = children[i].gameObject.GetComponent <RayfireRigid>();
                        if (childRigid == null)
                        {
                            childRigid = children[i].gameObject.AddComponent <RayfireRigid>();
                        }
                        fragments.Add(childRigid);

                        // Copy parent properties
                        CopyPropertiesTo(childRigid);

                        // Init
                        childRigid.Initialize();
                    }
                }

                // Copy initialized particles
                RFParticles.CopyRootMeshParticles(this, fragments);

                // TODO Setup as clusters root children with transform only

                // Check for Unyielding component
                RayfireUnyielding[] unyArray = transform.GetComponents <RayfireUnyielding>();
                for (int i = 0; i < unyArray.Length; i++)
                {
                    unyArray[i].SetUnyByOverlap(this);
                }

                // Turn off demolition and physics
                demolitionType  = DemolitionType.None;
                physics.exclude = true;
                return(true);
            }

            return(false);
        }