Exemplo n.º 1
0
        static public void CombineMeshesMaterials(MaterialList ml, GameObject parent, Vector3 add)
        {
            CombineInstance[] combine = new CombineInstance[ml.gameObjects.Count];
            int i = 0;

            foreach (GameObject go in ml.gameObjects)
            {
                combine[i].mesh      = go.GetComponent <MeshFilter>().sharedMesh;
                combine[i].transform = go.transform.localToWorldMatrix;
                i++;
                //					go.SetActive(false);
            }

            GameObject main = new GameObject(parent.name + "_" + ml.mat);

            main.AddComponent <MeshFilter>();
            main.AddComponent <MeshRenderer>();
            main.GetComponent <MeshFilter>().mesh = new Mesh();
            Mesh mesh = main.GetComponent <MeshFilter>().sharedMesh;

            mesh.CombineMeshes(combine);
            mesh.RecalculateNormals();
            ;

            main.GetComponent <Renderer>().material = (Material)Resources.Load(ml.mat);
            main.transform.position += add;

            main.transform.parent = parent.transform;
        }
Exemplo n.º 2
0
        static void InsertGameObject(GameObject go, List <MaterialList> list)
        {
            foreach (MaterialList ml in list)
            {
                if (ml.mat == trimMaterial(go.GetComponent <Renderer>().sharedMaterial.name))
                {
                    ml.gameObjects.Add(go);
                    return;
                }
            }

            MaterialList mli = new MaterialList();

            mli.mat = trimMaterial(go.GetComponent <Renderer>().sharedMaterial.name);
            mli.gameObjects.Add(go);
            list.Add(mli);
        }