Beispiel #1
0
        private static void MakeBatch(List <MeshSubsetCombineUtility.MeshInstance> meshes, List <MeshSubsetCombineUtility.SubMeshInstance> subsets, List <GameObject> subsetGOs, Transform staticBatchRootTransform, int batchIndex)
        {
            if (meshes.Count < 2)
            {
                return;
            }
            MeshSubsetCombineUtility.MeshInstance[]    meshes2 = meshes.ToArray();
            MeshSubsetCombineUtility.SubMeshInstance[] array   = subsets.ToArray();
            string text = "Combined Mesh";

            text = text + " (root: " + ((!(staticBatchRootTransform != null)) ? "scene" : staticBatchRootTransform.name) + ")";
            if (batchIndex > 0)
            {
                text = text + " " + (batchIndex + 1);
            }
            Mesh mesh = StaticBatchingUtility.InternalCombineVertices(meshes2, text);

            StaticBatchingUtility.InternalCombineIndices(array, mesh);
            int num = 0;

            for (int i = 0; i < array.Length; i++)
            {
                MeshSubsetCombineUtility.SubMeshInstance subMeshInstance = array[i];
                GameObject gameObject = subsetGOs[i];
                Mesh       sharedMesh = mesh;
                MeshFilter meshFilter = (MeshFilter)gameObject.GetComponent(typeof(MeshFilter));
                meshFilter.sharedMesh = sharedMesh;
                Renderer component = gameObject.GetComponent <Renderer>();
                component.SetSubsetIndex(subMeshInstance.subMeshIndex, num);
                component.staticBatchRootTransform = staticBatchRootTransform;
                component.enabled = false;
                component.enabled = true;
                MeshRenderer meshRenderer = component as MeshRenderer;
                if (meshRenderer != null)
                {
                    meshRenderer.additionalVertexStreams = null;
                }
                num++;
            }
        }
Beispiel #2
0
        private static void MakeBatch(List <MeshSubsetCombineUtility.MeshInstance> meshes, List <MeshSubsetCombineUtility.SubMeshInstance> subsets, List <GameObject> subsetGOs, Transform staticBatchRootTransform, int batchIndex)
        {
            if (meshes.Count < 2)
            {
                return;
            }
            MeshSubsetCombineUtility.MeshInstance[]    array1 = meshes.ToArray();
            MeshSubsetCombineUtility.SubMeshInstance[] array2 = subsets.ToArray();
            string meshName = "Combined Mesh" + " (root: " + (!((Object)staticBatchRootTransform != (Object)null) ? "scene" : staticBatchRootTransform.name) + ")";

            if (batchIndex > 0)
            {
                meshName = meshName + " " + (object)(batchIndex + 1);
            }
            Mesh combinedMesh = StaticBatchingUtility.InternalCombineVertices(array1, meshName);

            StaticBatchingUtility.InternalCombineIndices(array2, combinedMesh);
            int subSetIndexForMaterial = 0;

            for (int index = 0; index < array2.Length; ++index)
            {
                MeshSubsetCombineUtility.SubMeshInstance subMeshInstance = array2[index];
                GameObject subsetGo = subsetGOs[index];
                Mesh       mesh     = combinedMesh;
                ((MeshFilter)subsetGo.GetComponent(typeof(MeshFilter))).sharedMesh = mesh;
                Renderer component = subsetGo.GetComponent <Renderer>();
                component.SetSubsetIndex(subMeshInstance.subMeshIndex, subSetIndexForMaterial);
                component.staticBatchRootTransform = staticBatchRootTransform;
                component.enabled = false;
                component.enabled = true;
                MeshRenderer meshRenderer = component as MeshRenderer;
                if ((Object)meshRenderer != (Object)null)
                {
                    meshRenderer.additionalVertexStreams = (Mesh)null;
                }
                ++subSetIndexForMaterial;
            }
        }