예제 #1
0
        public static void Combine(GameObject staticBatchRoot, bool combineOnlyStatic, bool isEditorPostprocessScene)
        {
            GameObject[]      objectsOfType  = (GameObject[])Object.FindObjectsOfType(typeof(GameObject));
            List <GameObject> gameObjectList = new List <GameObject>();

            foreach (GameObject gameObject in objectsOfType)
            {
                if ((!((Object)staticBatchRoot != (Object)null) || gameObject.transform.IsChildOf(staticBatchRoot.transform)) && (!combineOnlyStatic || gameObject.isStaticBatchable))
                {
                    gameObjectList.Add(gameObject);
                }
            }
            InternalStaticBatchingUtility.CombineGameObjects(gameObjectList.ToArray(), staticBatchRoot, isEditorPostprocessScene);
        }
예제 #2
0
        public static void Combine(GameObject staticBatchRoot, bool combineOnlyStatic, bool isEditorPostprocessScene)
        {
            GameObject[]      array = (GameObject[])Object.FindObjectsOfType(typeof(GameObject));
            List <GameObject> list  = new List <GameObject>();

            foreach (GameObject gameObject in array)
            {
                if (!(staticBatchRoot != null) || gameObject.transform.IsChildOf(staticBatchRoot.transform))
                {
                    if (!combineOnlyStatic || gameObject.isStaticBatchable)
                    {
                        list.Add(gameObject);
                    }
                }
            }
            array = list.ToArray();
            InternalStaticBatchingUtility.CombineGameObjects(array, staticBatchRoot, isEditorPostprocessScene);
        }
        public static void Combine(GameObject staticBatchRoot, bool combineOnlyStatic)
        {
            GameObject[]      array = (GameObject[])Object.FindObjectsOfType(typeof(GameObject));
            List <GameObject> list  = new List <GameObject>();

            GameObject[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                GameObject gameObject = array2[i];
                if (!(staticBatchRoot != null) || gameObject.transform.IsChildOf(staticBatchRoot.transform))
                {
                    if (!combineOnlyStatic || gameObject.isStaticBatchable)
                    {
                        list.Add(gameObject);
                    }
                }
            }
            array = list.ToArray();
            if (!Application.HasProLicense() && !Application.HasAdvancedLicense() && staticBatchRoot != null && array.Length > 0)
            {
                Debug.LogError("Your Unity license is not sufficient for Static Batching.");
            }
            InternalStaticBatchingUtility.Combine(array, staticBatchRoot);
        }
예제 #4
0
        public static void CombineGameObjects(GameObject[] gos, GameObject staticBatchRoot, bool isEditorPostprocessScene)
        {
            Matrix4x4 lhs = Matrix4x4.identity;
            Transform staticBatchRootTransform = null;

            if (staticBatchRoot)
            {
                lhs = staticBatchRoot.transform.worldToLocalMatrix;
                staticBatchRootTransform = staticBatchRoot.transform;
            }
            int batchIndex = 0;
            int num        = 0;
            List <MeshSubsetCombineUtility.MeshContainer> list = new List <MeshSubsetCombineUtility.MeshContainer>();

            Array.Sort(gos, new InternalStaticBatchingUtility.SortGO());
            foreach (GameObject gameObject in gos)
            {
                MeshFilter meshFilter = gameObject.GetComponent(typeof(MeshFilter)) as MeshFilter;
                if (!(meshFilter == null))
                {
                    Mesh sharedMesh = meshFilter.sharedMesh;
                    if (!(sharedMesh == null) && (isEditorPostprocessScene || sharedMesh.canAccess))
                    {
                        Renderer component = meshFilter.GetComponent <Renderer>();
                        if (!(component == null) && component.enabled)
                        {
                            if (component.staticBatchIndex == 0)
                            {
                                Material[] array = component.sharedMaterials;
                                if (!array.Any((Material m) => m != null && m.shader != null && m.shader.disableBatching != DisableBatchingType.False))
                                {
                                    int vertexCount = sharedMesh.vertexCount;
                                    if (vertexCount != 0)
                                    {
                                        MeshRenderer meshRenderer = component as MeshRenderer;
                                        if (meshRenderer != null && meshRenderer.additionalVertexStreams != null)
                                        {
                                            if (vertexCount != meshRenderer.additionalVertexStreams.vertexCount)
                                            {
                                                goto IL_387;
                                            }
                                        }
                                        if (num + vertexCount > 64000)
                                        {
                                            InternalStaticBatchingUtility.MakeBatch(list, staticBatchRootTransform, batchIndex++);
                                            list.Clear();
                                            num = 0;
                                        }
                                        MeshSubsetCombineUtility.MeshInstance instance = default(MeshSubsetCombineUtility.MeshInstance);
                                        instance.meshInstanceID     = sharedMesh.GetInstanceID();
                                        instance.rendererInstanceID = component.GetInstanceID();
                                        if (meshRenderer != null && meshRenderer.additionalVertexStreams != null)
                                        {
                                            instance.additionalVertexStreamsMeshInstanceID = meshRenderer.additionalVertexStreams.GetInstanceID();
                                        }
                                        instance.transform                   = lhs * meshFilter.transform.localToWorldMatrix;
                                        instance.lightmapScaleOffset         = component.lightmapScaleOffset;
                                        instance.realtimeLightmapScaleOffset = component.realtimeLightmapScaleOffset;
                                        MeshSubsetCombineUtility.MeshContainer item = new MeshSubsetCombineUtility.MeshContainer
                                        {
                                            gameObject       = gameObject,
                                            instance         = instance,
                                            subMeshInstances = new List <MeshSubsetCombineUtility.SubMeshInstance>()
                                        };
                                        list.Add(item);
                                        if (array.Length > sharedMesh.subMeshCount)
                                        {
                                            Debug.LogWarning(string.Concat(new object[]
                                            {
                                                "Mesh '",
                                                sharedMesh.name,
                                                "' has more materials (",
                                                array.Length,
                                                ") than subsets (",
                                                sharedMesh.subMeshCount,
                                                ")"
                                            }), component);
                                            Material[] array2 = new Material[sharedMesh.subMeshCount];
                                            for (int j = 0; j < sharedMesh.subMeshCount; j++)
                                            {
                                                array2[j] = component.sharedMaterials[j];
                                            }
                                            component.sharedMaterials = array2;
                                            array = array2;
                                        }
                                        for (int k = 0; k < Math.Min(array.Length, sharedMesh.subMeshCount); k++)
                                        {
                                            MeshSubsetCombineUtility.SubMeshInstance item2 = default(MeshSubsetCombineUtility.SubMeshInstance);
                                            item2.meshInstanceID       = meshFilter.sharedMesh.GetInstanceID();
                                            item2.vertexOffset         = num;
                                            item2.subMeshIndex         = k;
                                            item2.gameObjectInstanceID = gameObject.GetInstanceID();
                                            item2.transform            = instance.transform;
                                            item.subMeshInstances.Add(item2);
                                        }
                                        num += sharedMesh.vertexCount;
                                    }
                                }
                            }
                        }
                    }
                }
                IL_387 :;
            }
            InternalStaticBatchingUtility.MakeBatch(list, staticBatchRootTransform, batchIndex);
        }
예제 #5
0
 public static void CombineRoot(GameObject staticBatchRoot)
 {
     InternalStaticBatchingUtility.Combine(staticBatchRoot, false, false);
 }
예제 #6
0
 public static void Combine(GameObject[] gos, GameObject staticBatchRoot)
 {
     InternalStaticBatchingUtility.CombineGameObjects(gos, staticBatchRoot, isEditorPostprocessScene: false);
 }
 /// <summary>
 ///   <para>Combine will prepare all gos for the static batching. staticBatchRoot will be treated as their parent.</para>
 /// </summary>
 /// <param name="gos"></param>
 /// <param name="staticBatchRoot"></param>
 public static void Combine(GameObject[] gos, GameObject staticBatchRoot)
 {
     InternalStaticBatchingUtility.CombineGameObjects(gos, staticBatchRoot, false);
 }
예제 #8
0
 static public void Combine(GameObject staticBatchRoot)
 {
     InternalStaticBatchingUtility.CombineRoot(staticBatchRoot);
 }
        public static void Combine(GameObject[] gos, GameObject staticBatchRoot)
        {
            Matrix4x4 lhs = Matrix4x4.identity;
            Transform staticBatchRootTransform = null;

            if (staticBatchRoot)
            {
                lhs = staticBatchRoot.transform.worldToLocalMatrix;
                staticBatchRootTransform = staticBatchRoot.transform;
            }
            int batchIndex = 0;
            int num        = 0;
            List <MeshSubsetCombineUtility.MeshInstance>    list  = new List <MeshSubsetCombineUtility.MeshInstance>();
            List <MeshSubsetCombineUtility.SubMeshInstance> list2 = new List <MeshSubsetCombineUtility.SubMeshInstance>();
            List <GameObject> list3 = new List <GameObject>();

            Array.Sort(gos, new InternalStaticBatchingUtility.SortGO());
            for (int i = 0; i < gos.Length; i++)
            {
                GameObject gameObject = gos[i];
                MeshFilter meshFilter = gameObject.GetComponent(typeof(MeshFilter)) as MeshFilter;
                if (!(meshFilter == null))
                {
                    Mesh sharedMesh = meshFilter.sharedMesh;
                    if (!(sharedMesh == null) && sharedMesh.canAccess)
                    {
                        Renderer component = meshFilter.GetComponent <Renderer>();
                        if (!(component == null) && component.enabled)
                        {
                            if (component.staticBatchIndex == 0)
                            {
                                Material[] array = meshFilter.GetComponent <Renderer>().sharedMaterials;
                                if (!array.Any((Material m) => m != null && m.shader != null && m.shader.disableBatching != DisableBatchingType.False))
                                {
                                    if (num + meshFilter.sharedMesh.vertexCount > 64000)
                                    {
                                        InternalStaticBatchingUtility.MakeBatch(list, list2, list3, staticBatchRootTransform, batchIndex++);
                                        list.Clear();
                                        list2.Clear();
                                        list3.Clear();
                                        num = 0;
                                    }
                                    MeshSubsetCombineUtility.MeshInstance item = default(MeshSubsetCombineUtility.MeshInstance);
                                    item.meshInstanceID     = sharedMesh.GetInstanceID();
                                    item.rendererInstanceID = component.GetInstanceID();
                                    MeshRenderer meshRenderer = component as MeshRenderer;
                                    if (meshRenderer != null && meshRenderer.additionalVertexStreams != null)
                                    {
                                        item.additionalVertexStreamsMeshInstanceID = meshRenderer.additionalVertexStreams.GetInstanceID();
                                    }
                                    item.transform                   = lhs * meshFilter.transform.localToWorldMatrix;
                                    item.lightmapScaleOffset         = component.lightmapScaleOffset;
                                    item.realtimeLightmapScaleOffset = component.realtimeLightmapScaleOffset;
                                    list.Add(item);
                                    if (array.Length > sharedMesh.subMeshCount)
                                    {
                                        Debug.LogWarning(string.Concat(new object[]
                                        {
                                            "Mesh has more materials (",
                                            array.Length,
                                            ") than subsets (",
                                            sharedMesh.subMeshCount,
                                            ")"
                                        }), meshFilter.GetComponent <Renderer>());
                                        Material[] array2 = new Material[sharedMesh.subMeshCount];
                                        for (int j = 0; j < sharedMesh.subMeshCount; j++)
                                        {
                                            array2[j] = meshFilter.GetComponent <Renderer>().sharedMaterials[j];
                                        }
                                        meshFilter.GetComponent <Renderer>().sharedMaterials = array2;
                                        array = array2;
                                    }
                                    for (int k = 0; k < Math.Min(array.Length, sharedMesh.subMeshCount); k++)
                                    {
                                        list2.Add(new MeshSubsetCombineUtility.SubMeshInstance
                                        {
                                            meshInstanceID       = meshFilter.sharedMesh.GetInstanceID(),
                                            vertexOffset         = num,
                                            subMeshIndex         = k,
                                            gameObjectInstanceID = gameObject.GetInstanceID(),
                                            transform            = item.transform
                                        });
                                        list3.Add(gameObject);
                                    }
                                    num += sharedMesh.vertexCount;
                                }
                            }
                        }
                    }
                }
            }
            InternalStaticBatchingUtility.MakeBatch(list, list2, list3, staticBatchRootTransform, batchIndex);
        }
예제 #10
0
        public static void CombineGameObjects(GameObject[] gos, GameObject staticBatchRoot, bool isEditorPostprocessScene)
        {
            Matrix4x4 matrix4x4 = Matrix4x4.identity;
            Transform staticBatchRootTransform = (Transform)null;

            if ((bool)((Object)staticBatchRoot))
            {
                matrix4x4 = staticBatchRoot.transform.worldToLocalMatrix;
                staticBatchRootTransform = staticBatchRoot.transform;
            }
            int batchIndex = 0;
            int num        = 0;
            List <MeshSubsetCombineUtility.MeshInstance>    meshes  = new List <MeshSubsetCombineUtility.MeshInstance>();
            List <MeshSubsetCombineUtility.SubMeshInstance> subsets = new List <MeshSubsetCombineUtility.SubMeshInstance>();
            List <GameObject> subsetGOs = new List <GameObject>();

            Array.Sort((Array)gos, (IComparer) new InternalStaticBatchingUtility.SortGO());
            foreach (GameObject go in gos)
            {
                MeshFilter component1 = go.GetComponent(typeof(MeshFilter)) as MeshFilter;
                if (!((Object)component1 == (Object)null))
                {
                    Mesh sharedMesh = component1.sharedMesh;
                    if (!((Object)sharedMesh == (Object)null) && (isEditorPostprocessScene || sharedMesh.canAccess))
                    {
                        Renderer component2 = component1.GetComponent <Renderer>();
                        if (!((Object)component2 == (Object)null) && component2.enabled && component2.staticBatchIndex == 0)
                        {
                            Material[] materialArray1 = component1.GetComponent <Renderer>().sharedMaterials;
                            if (!((IEnumerable <Material>)materialArray1).Any <Material>((Func <Material, bool>)(m =>
                            {
                                if ((Object)m != (Object)null && (Object)m.shader != (Object)null)
                                {
                                    return(m.shader.disableBatching != DisableBatchingType.False);
                                }
                                return(false);
                            })))
                            {
                                int vertexCount = sharedMesh.vertexCount;
                                if (vertexCount != 0)
                                {
                                    MeshRenderer meshRenderer = component2 as MeshRenderer;
                                    if (!((Object)meshRenderer != (Object)null) || !((Object)meshRenderer.additionalVertexStreams != (Object)null) || vertexCount == meshRenderer.additionalVertexStreams.vertexCount)
                                    {
                                        if (num + vertexCount > 64000)
                                        {
                                            InternalStaticBatchingUtility.MakeBatch(meshes, subsets, subsetGOs, staticBatchRootTransform, batchIndex++);
                                            meshes.Clear();
                                            subsets.Clear();
                                            subsetGOs.Clear();
                                            num = 0;
                                        }
                                        MeshSubsetCombineUtility.MeshInstance meshInstance = new MeshSubsetCombineUtility.MeshInstance();
                                        meshInstance.meshInstanceID     = sharedMesh.GetInstanceID();
                                        meshInstance.rendererInstanceID = component2.GetInstanceID();
                                        if ((Object)meshRenderer != (Object)null && (Object)meshRenderer.additionalVertexStreams != (Object)null)
                                        {
                                            meshInstance.additionalVertexStreamsMeshInstanceID = meshRenderer.additionalVertexStreams.GetInstanceID();
                                        }
                                        meshInstance.transform                   = matrix4x4 * component1.transform.localToWorldMatrix;
                                        meshInstance.lightmapScaleOffset         = component2.lightmapScaleOffset;
                                        meshInstance.realtimeLightmapScaleOffset = component2.realtimeLightmapScaleOffset;
                                        meshes.Add(meshInstance);
                                        if (materialArray1.Length > sharedMesh.subMeshCount)
                                        {
                                            Debug.LogWarning((object)("Mesh has more materials (" + (object)materialArray1.Length + ") than subsets (" + (object)sharedMesh.subMeshCount + ")"), (Object)component1.GetComponent <Renderer>());
                                            Material[] materialArray2 = new Material[sharedMesh.subMeshCount];
                                            for (int index = 0; index < sharedMesh.subMeshCount; ++index)
                                            {
                                                materialArray2[index] = component1.GetComponent <Renderer>().sharedMaterials[index];
                                            }
                                            component1.GetComponent <Renderer>().sharedMaterials = materialArray2;
                                            materialArray1 = materialArray2;
                                        }
                                        for (int index = 0; index < Math.Min(materialArray1.Length, sharedMesh.subMeshCount); ++index)
                                        {
                                            subsets.Add(new MeshSubsetCombineUtility.SubMeshInstance()
                                            {
                                                meshInstanceID       = component1.sharedMesh.GetInstanceID(),
                                                vertexOffset         = num,
                                                subMeshIndex         = index,
                                                gameObjectInstanceID = go.GetInstanceID(),
                                                transform            = meshInstance.transform
                                            });
                                            subsetGOs.Add(go);
                                        }
                                        num += sharedMesh.vertexCount;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            InternalStaticBatchingUtility.MakeBatch(meshes, subsets, subsetGOs, staticBatchRootTransform, batchIndex);
        }