Пример #1
0
 public void checkConnections()
 {
     if (!stickyFrag && !this.fragged && !this.connected && (fragControl.stickyTop > 0 || fragControl.stickyBottom > 0))
     {
         //			Debug.Log("checkConnections");
         int        counter = 0;
         Collider[] colls   = null;
         colls = Physics.OverlapSphere(transform.position, fragControl.connectOverlapSphere * fragControl.transform.localScale.x, fragControl.stickyMask);
         for (int i = 0; i <= colls.Length - 1; i++)
         {
             FraggedChild frag = colls[i].transform.GetComponent <FraggedChild>();
             if (frag != null && !frag.fragged && transform.parent == frag.transform.parent)
             {
                 if (frag.stickyFrag || frag.connected)
                 {
                     counter++;
                 }
             }
         }
         if (counter >= fragControl.connectedFragments)
         {
             connected = true;
         }
     }
 }
Пример #2
0
 public void checkConnections()
 {
     if (stickyTop > 0 || stickyBottom > 0)
     {
         //set all connected to false
         FraggedChild frag = null;
         for (int i = stickyTop; i < meshFilters.Length; i++)
         {
             frag           = meshFilters[i].GetComponent <FraggedChild>();
             frag.connected = false;
         }
         //checks connections upwards
         for (int j = stickyTop; j < meshFilters.Length; j++)
         {
             frag.checkConnections();
             frag = meshFilters[j].GetComponent <FraggedChild>();
         }
         // checks connections down
         for (int u = meshFilters.Length - stickyBottom - 1; u >= stickyTop; u--)
         {
             frag = meshFilters[u].GetComponent <FraggedChild>();
             if (!frag.fragged)
             {
                 frag.checkConnections();
                 if (!frag.connected)
                 {
                     frag.fragMe(2.0f);
                 }
             }
         }
     }
 }
Пример #3
0
 public void FragAll()
 {
     for (int i = fragments.transform.childCount; i > 0; i--)
     {
         FraggedChild child = fragments.GetChild(i - 1).GetComponent <FraggedChild>();
         child.fragMe(200.0f);
     }
 }
Пример #4
0
 public void FixedUpdate()
 {
     if (limitFragmentSpeed > 0 && (combinedFrags == null) && !this.startMesh.GetComponent <Renderer>().enabled)
     {
         for (int i = fragments.childCount; i > 0; i--)
         {
             FraggedChild child = fragments.GetChild(i - 1).GetComponent <FraggedChild>();
             child.SpeedCheck();
         }
     }
 }
Пример #5
0
 // FIND STICKY FRAGMENTS
 public void FindSticky()
 {
     if (stickyTop > 0 || stickyBottom > 0)
     {
         //JS
         //meshFilters.Sort(meshFilters, function(g1, g2) Compare(g1.transform.position.y, g2.transform.position.y));
         //C# + ADD using System.Linq;
         meshFilters = meshFilters.OrderByDescending(x => x.transform.position.y).ToArray();
         for (int j = 0; j < stickyTop; j++)
         {
             FraggedChild g = meshFilters[j].GetComponent <FraggedChild>();
             g.stickyFrag = true;
         }
         for (int i = meshFilters.Length - stickyBottom; i < meshFilters.Length; i++)
         {
             FraggedChild k = meshFilters[i].GetComponent <FraggedChild>();
             k.stickyFrag = true;
         }
     }
 }
Пример #6
0
    //// COMBINE FRAGMENTS TO A SINGLE MESH
    public void CombineFrags()
    {
        if ((combinedFrags == null) && !this.startMesh.GetComponent <Renderer>().enabled)
        {
            combinedFrags      = new GameObject();
            combinedFrags.name = "Combined Fragments";
            combinedFrags.gameObject.AddComponent <MeshFilter>();
            combinedFrags.gameObject.AddComponent <MeshRenderer>();
            if (meshFilters.Length == 0)
            {
                meshFilters = new MeshFilter[fragments.transform.childCount];
                meshFilters = fragments.transform.GetComponentsInChildren <MeshFilter> (true);
            }
            ArrayList materials             = new ArrayList();
            ArrayList combineInstanceArrays = new ArrayList();
            for (int i = 0; i < meshFilters.Length; i++)
            {
                MeshFilter[] meshFilterss = meshFilters[i].GetComponentsInChildren <MeshFilter> ();
                foreach (MeshFilter meshFilter in meshFilterss)
                {
                    MeshRenderer meshRenderer = meshFilter.GetComponent <MeshRenderer>();
                    FraggedChild c            = meshFilter.transform.GetComponent <FraggedChild>();
                    if ((c != null) && c.fragged == false || (c != null) && combineFrags)               //&& c.fragged == false) {
                    {
                        c.fragged   = false;
                        c.hitPoints = 1.0f;

                        meshFilters[i].transform.gameObject.GetComponent <Renderer>().enabled = false;
                        meshFilters[i].GetComponent <Rigidbody>().isKinematic = true;
                        for (int o = 0; o < meshFilter.sharedMesh.subMeshCount; o++)
                        {
                            int materialArrayIndex = Contains(materials, meshRenderer.sharedMaterials[o].name);
                            if (materialArrayIndex == -1)
                            {
                                materials.Add(meshRenderer.sharedMaterials[o]);
                                materialArrayIndex = materials.Count - 1;
                            }
                            combineInstanceArrays.Add(new ArrayList());
                            CombineInstance combineInstance = new CombineInstance();
                            combineInstance.transform    = meshRenderer.transform.localToWorldMatrix;
                            combineInstance.subMeshIndex = o;
                            combineInstance.mesh         = meshFilter.sharedMesh;
                            (combineInstanceArrays[materialArrayIndex] as ArrayList).Add(combineInstance);
                        }
                    }
                }
            }
            Mesh[]            meshes           = new Mesh[materials.Count];
            CombineInstance[] combineInstances = new CombineInstance[materials.Count];
            for (int m = 0; m < materials.Count; m++)
            {
                CombineInstance[] combineInstanceArray = (combineInstanceArrays[m] as ArrayList).ToArray(typeof(CombineInstance)) as CombineInstance[];
                meshes[m] = new Mesh();
                meshes[m].CombineMeshes(combineInstanceArray, true, true);
                combineInstances[m]              = new CombineInstance();
                combineInstances[m].mesh         = meshes[m];
                combineInstances[m].subMeshIndex = 0;
            }
            combinedFrags.GetComponent <MeshFilter>().sharedMesh = new Mesh();
            combinedFrags.GetComponent <MeshFilter>().sharedMesh.CombineMeshes(combineInstances, false, false);
            foreach (Mesh mesh in meshes)
            {
                mesh.Clear();
                DestroyImmediate(mesh);
            }
            MeshRenderer meshRendererCombine = combinedFrags.GetComponent <MeshFilter>().GetComponent <MeshRenderer>();
            if (meshRendererCombine == null)
            {
                meshRendererCombine = gameObject.AddComponent <MeshRenderer>();
            }
            Material[] materialsArray = materials.ToArray(typeof(Material)) as Material[];
            meshRendererCombine.materials = materialsArray;
            if (Application.isEditor && !Application.isPlaying && combinedFrags.transform.parent != transform)
            {
                combinedFrags.transform.parent = transform;
            }
        }
    }