Exemplo n.º 1
0
 private static void checkBatchable(List <GameObject> list, MeshFilter mesh, MeshRenderer renderer)
 {
     if (mesh != null && mesh.sharedMesh != null && renderer != null && renderer.sharedMaterials != null && renderer.sharedMaterials.Length == 1)
     {
         Texture2D texture2D = (Texture2D)renderer.sharedMaterial.mainTexture;
         HighlighterShaderGroup highlighterShaderGroup = null;
         if (texture2D != null && texture2D.wrapMode == 1 && texture2D.width <= 128 && texture2D.height <= 128)
         {
             if (renderer.sharedMaterial.shader.name == "Standard")
             {
                 if (renderer.sharedMaterial.GetFloat("_Mode") == 0f && texture2D.filterMode == null)
                 {
                     highlighterShaderGroup = HighlighterTool.batchableOpaque;
                 }
             }
             else if (renderer.sharedMaterial.shader.name == "Custom/Card")
             {
                 highlighterShaderGroup = HighlighterTool.batchableCard;
             }
             else if (renderer.sharedMaterial.shader.name == "Custom/Foliage" && texture2D.filterMode == 2)
             {
                 highlighterShaderGroup = HighlighterTool.batchableFoliage;
             }
         }
         if (highlighterShaderGroup != null)
         {
             HighlighterBatch highlighterBatch = null;
             if (!highlighterShaderGroup.batchableTextures.TryGetValue(texture2D, out highlighterBatch))
             {
                 highlighterBatch         = HighlighterTool.getBatchable();
                 highlighterBatch.texture = texture2D;
                 highlighterShaderGroup.batchableTextures.Add(texture2D, highlighterBatch);
             }
             if (highlighterBatch != null)
             {
                 List <MeshFilter> list2;
                 if (!highlighterBatch.meshes.TryGetValue(mesh.sharedMesh, out list2))
                 {
                     list2 = new List <MeshFilter>();
                     highlighterBatch.meshes.Add(mesh.sharedMesh, list2);
                 }
                 list2.Add(mesh);
                 highlighterBatch.renderers.Add(renderer);
                 list.Add(mesh.gameObject);
             }
         }
         else
         {
             List <GameObject> list3 = null;
             if (!HighlighterTool.batchableMaterials.TryGetValue(renderer.sharedMaterial, out list3))
             {
                 list3 = new List <GameObject>();
                 HighlighterTool.batchableMaterials.Add(renderer.sharedMaterial, list3);
             }
             list3.Add(mesh.gameObject);
         }
     }
 }
Exemplo n.º 2
0
        private static void batch(HighlighterShaderGroup group)
        {
            Material materialTemplate = group.materialTemplate;
            Dictionary <Texture2D, HighlighterBatch> batchableTextures = group.batchableTextures;

            if (batchableTextures.Count > 0)
            {
                Texture2D texture2D = new Texture2D(16, 16);
                texture2D.name       = "Atlas";
                texture2D.wrapMode   = 1;
                texture2D.filterMode = group.filterMode;
                HighlighterBatch[] array = new HighlighterBatch[batchableTextures.Count];
                batchableTextures.Values.CopyTo(array, 0);
                Texture2D[] array2 = new Texture2D[array.Length];
                for (int i = 0; i < array.Length; i++)
                {
                    HighlighterBatch highlighterBatch = array[i];
                    Texture2D        texture          = highlighterBatch.texture;
                    RenderTexture    temporary        = RenderTexture.GetTemporary(texture.width, texture.height, 0, 0, 0);
                    Graphics.Blit(texture, temporary);
                    RenderTexture active = RenderTexture.active;
                    RenderTexture.active = temporary;
                    Texture2D texture2D2 = new Texture2D(texture.width, texture.height, 5, false, true);
                    texture2D2.name = "Copy";
                    texture2D2.ReadPixels(new Rect(0f, 0f, (float)texture.width, (float)texture.height), 0, 0);
                    texture2D2.Apply();
                    array2[i]            = texture2D2;
                    RenderTexture.active = active;
                    RenderTexture.ReleaseTemporary(temporary);
                }
                Rect[] array3 = texture2D.PackTextures(array2, 0, 1024, true);
                if (array3 != null)
                {
                    Material material = Object.Instantiate <Material>(materialTemplate);
                    material.name        = "Material";
                    material.mainTexture = texture2D;
                    for (int j = 0; j < array.Length; j++)
                    {
                        HighlighterBatch    highlighterBatch2 = array[j];
                        List <MeshFilter>[] array4            = new List <MeshFilter> [highlighterBatch2.meshes.Count];
                        highlighterBatch2.meshes.Values.CopyTo(array4, 0);
                        for (int k = 0; k < array4.Length; k++)
                        {
                            Mesh      mesh = array4[k][0].mesh;
                            Vector2[] uv   = mesh.uv;
                            for (int l = 0; l < uv.Length; l++)
                            {
                                uv[l].x = array3[j].x + uv[l].x * array3[j].width;
                                uv[l].y = array3[j].y + uv[l].y * array3[j].height;
                            }
                            mesh.uv = uv;
                            if (array4[k].Count > 1)
                            {
                                for (int m = 1; m < array4[k].Count; m++)
                                {
                                    array4[k][m].sharedMesh = mesh;
                                }
                            }
                        }
                        for (int n = 0; n < highlighterBatch2.renderers.Count; n++)
                        {
                            highlighterBatch2.renderers[n].sharedMaterial = material;
                        }
                    }
                }
                else
                {
                    Object.DestroyImmediate(texture2D);
                }
                for (int num = 0; num < array2.Length; num++)
                {
                    Object.DestroyImmediate(array2[num]);
                }
            }
        }