Beispiel #1
0
        internal override bool HasExternalChanges()
        {
            string text;

            if (this.geometryMode == 4)
            {
                text = InternalEditorUtility.CalculateHashForObjectsAndDependencies(new UnityEngine.Object[]
                {
                    this.instanceMesh
                });
            }
            else
            {
                text = InternalEditorUtility.CalculateHashForObjectsAndDependencies(new UnityEngine.Object[]
                {
                    this.materialLeaf
                });
            }
            if (text != this.m_Hash)
            {
                this.m_Hash = text;
                return(true);
            }
            return(false);
        }
        internal override bool HasExternalChanges()
        {
            List <UnityEngine.Object> list = new List <UnityEngine.Object>();

            if (this.geometryMode == GeometryMode.Branch)
            {
                list.Add(this.materialBranch);
                if (this.breakingChance > 0f)
                {
                    list.Add(this.materialBreak);
                }
            }
            else if (this.geometryMode == GeometryMode.BranchFrond)
            {
                list.Add(this.materialBranch);
                list.Add(this.materialFrond);
                if (this.breakingChance > 0f)
                {
                    list.Add(this.materialBreak);
                }
            }
            else if (this.geometryMode == GeometryMode.Frond)
            {
                list.Add(this.materialFrond);
            }
            string str = InternalEditorUtility.CalculateHashForObjectsAndDependencies(list.ToArray());

            if (str != base.m_Hash)
            {
                base.m_Hash = str;
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        internal override bool HasExternalChanges()
        {
            string str;

            if (this.geometryMode == 4)
            {
                UnityEngine.Object[] objects = new UnityEngine.Object[] { this.instanceMesh };
                str = InternalEditorUtility.CalculateHashForObjectsAndDependencies(objects);
            }
            else
            {
                UnityEngine.Object[] objArray2 = new UnityEngine.Object[] { this.materialLeaf };
                str = InternalEditorUtility.CalculateHashForObjectsAndDependencies(objArray2);
            }
            if (str != base.m_Hash)
            {
                base.m_Hash = str;
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        private bool UpdateTextures(TextureAtlas atlas, List <TreeMaterial> materials)
        {
            if (!this.root.enableMaterialOptimize)
            {
                return(false);
            }
            bool flag = this.optimizedSolidMaterial.GetTexture("_MainTex") != null && this.optimizedSolidMaterial.GetTexture("_BumpSpecMap") != null && this.optimizedSolidMaterial.GetTexture("_TranslucencyMap") != null && this.optimizedCutoutMaterial.GetTexture("_MainTex") != null && this.optimizedCutoutMaterial.GetTexture("_ShadowTex") != null && this.optimizedCutoutMaterial.GetTexture("_BumpSpecMap") != null && this.optimizedCutoutMaterial.GetTexture("_TranslucencyMap");

            UnityEngine.Object[] array = new UnityEngine.Object[materials.Count];
            for (int i = 0; i < materials.Count; i++)
            {
                array[i] = materials[i].material;
            }
            string text = InternalEditorUtility.CalculateHashForObjectsAndDependencies(array);

            text += atlas.GetHashCode();
            if (this.materialHash == text && flag)
            {
                this.UpdateShadowTexture(this.optimizedCutoutMaterial.GetTexture("_ShadowTex") as Texture2D, atlas.atlasWidth, atlas.atlasHeight);
                return(false);
            }
            this.materialHash = text;
            int       atlasWidth   = atlas.atlasWidth;
            int       atlasHeight  = atlas.atlasHeight;
            int       atlasPadding = atlas.atlasPadding;
            Texture2D texture2D    = new Texture2D(atlasWidth, atlasHeight, TextureFormat.ARGB32, true);
            Texture2D texture2D2   = new Texture2D(atlasWidth, atlasHeight, TextureFormat.RGB24, true);
            Texture2D texture2D3   = new Texture2D(atlasWidth, atlasHeight, TextureFormat.ARGB32, true);
            Texture2D texture2D4   = new Texture2D(atlasWidth, atlasHeight, TextureFormat.ARGB32, true);

            texture2D.name  = "diffuse";
            texture2D2.name = "shadow";
            texture2D3.name = "normal_specular";
            texture2D4.name = "translucency_gloss";
            SavedRenderTargetState savedRenderTargetState = new SavedRenderTargetState();

            EditorUtility.SetTemporarilyAllowIndieRenderTexture(true);
            RenderTexture temporary  = RenderTexture.GetTemporary(atlasWidth, atlasHeight, 0, RenderTextureFormat.ARGB32);
            Color         white      = Color.white;
            Color         color      = new Color(0.03f, 0.5f, 0f, 0.5f);
            Color         color2     = new Color(0f, 0f, 0f, 0f);
            Texture2D     texture2D5 = new Texture2D(1, 1);

            texture2D5.SetPixel(0, 0, white);
            texture2D5.Apply();
            Texture2D texture2D6 = new Texture2D(1, 1);

            texture2D6.SetPixel(0, 0, white);
            texture2D6.Apply();
            Texture2D texture2D7 = new Texture2D(1, 1);

            texture2D7.SetPixel(0, 0, color);
            texture2D7.Apply();
            Texture2D texture2D8 = new Texture2D(1, 1);

            texture2D8.SetPixel(0, 0, color2);
            texture2D8.Apply();
            Texture2D texture2D9  = texture2D8;
            Texture2D texture2D10 = new Texture2D(1, 1);

            texture2D10.SetPixel(0, 0, Color.white);
            texture2D10.Apply();
            Material material = EditorGUIUtility.LoadRequired("Inspectors/TreeCreator/TreeTextureCombinerMaterial.mat") as Material;

            for (int j = 0; j < 4; j++)
            {
                RenderTexture.active = temporary;
                GL.LoadPixelMatrix(0f, (float)atlasWidth, 0f, (float)atlasHeight);
                material.SetVector("_TexSize", new Vector4((float)atlasWidth, (float)atlasHeight, 0f, 0f));
                switch (j)
                {
                case 0:
                    GL.Clear(false, true, color);
                    break;

                case 1:
                    GL.Clear(false, true, color2);
                    break;

                case 2:
                    GL.Clear(false, true, color2);
                    break;

                case 3:
                    GL.Clear(false, true, color2);
                    break;
                }
                for (int k = 0; k < atlas.nodes.Count; k++)
                {
                    TextureAtlas.TextureNode textureNode = atlas.nodes[k];
                    Rect    packedRect = textureNode.packedRect;
                    Texture texture    = null;
                    Texture texture2   = null;
                    Color   color3     = default(Color);
                    switch (j)
                    {
                    case 0:
                        texture  = textureNode.normalTexture;
                        texture2 = textureNode.shadowOffsetTexture;
                        color3   = new Color(textureNode.shininess, 0f, 0f, 0f);
                        if (texture == null)
                        {
                            texture = texture2D7;
                        }
                        if (texture2 == null)
                        {
                            texture2 = texture2D9;
                        }
                        break;

                    case 1:
                        texture = textureNode.diffuseTexture;
                        color3  = textureNode.diffuseColor;
                        if (texture == null)
                        {
                            texture = texture2D5;
                        }
                        break;

                    case 2:
                        texture  = textureNode.translucencyTexture;
                        texture2 = textureNode.glossTexture;
                        if (texture == null)
                        {
                            texture = texture2D10;
                        }
                        if (texture2 == null)
                        {
                            texture2 = texture2D8;
                        }
                        break;

                    case 3:
                        texture2 = textureNode.diffuseTexture;
                        if (texture2 == null)
                        {
                            texture2 = texture2D5;
                        }
                        break;
                    }
                    if (textureNode.tileV)
                    {
                        float x   = packedRect.x;
                        float num = (float)atlasPadding / 2f;
                        for (float num2 = num; num2 > 0f; num2 -= 1f)
                        {
                            Rect rect  = new Rect(packedRect);
                            Rect rect2 = new Rect(packedRect);
                            rect.x  = x - num2;
                            rect2.x = x + num2;
                            this.DrawTexture(rect, texture, texture2, material, color3, j);
                            this.DrawTexture(rect2, texture, texture2, material, color3, j);
                        }
                    }
                    this.DrawTexture(packedRect, texture, texture2, material, color3, j);
                }
                switch (j)
                {
                case 0:
                    texture2D3.ReadPixels(new Rect(0f, 0f, (float)atlasWidth, (float)atlasHeight), 0, 0);
                    texture2D3.Apply(true);
                    break;

                case 1:
                    texture2D.ReadPixels(new Rect(0f, 0f, (float)atlasWidth, (float)atlasHeight), 0, 0);
                    texture2D.Apply(true);
                    break;

                case 2:
                    texture2D4.ReadPixels(new Rect(0f, 0f, (float)atlasWidth, (float)atlasHeight), 0, 0);
                    texture2D4.Apply(true);
                    break;

                case 3:
                    texture2D2.ReadPixels(new Rect(0f, 0f, (float)atlasWidth, (float)atlasHeight), 0, 0);
                    texture2D2.Apply(true);
                    break;
                }
            }
            savedRenderTargetState.Restore();
            this.optimizedSolidMaterial.SetPass(0);
            RenderTexture.ReleaseTemporary(temporary);
            UnityEngine.Object.DestroyImmediate(texture2D5);
            UnityEngine.Object.DestroyImmediate(texture2D6);
            UnityEngine.Object.DestroyImmediate(texture2D10);
            UnityEngine.Object.DestroyImmediate(texture2D8);
            UnityEngine.Object.DestroyImmediate(texture2D7);
            EditorUtility.SetTemporarilyAllowIndieRenderTexture(false);
            Texture2D[] array2 = new Texture2D[]
            {
                texture2D,
                texture2D3,
                texture2D4,
                texture2D2
            };
            array2 = TreeData.WriteOptimizedTextures(AssetDatabase.GetAssetPath(this), array2);
            UnityEngine.Object.DestroyImmediate(texture2D);
            UnityEngine.Object.DestroyImmediate(texture2D3);
            UnityEngine.Object.DestroyImmediate(texture2D4);
            UnityEngine.Object.DestroyImmediate(texture2D2);
            this.optimizedSolidMaterial.SetTexture("_MainTex", array2[0]);
            this.optimizedSolidMaterial.SetTexture("_BumpSpecMap", array2[1]);
            this.optimizedSolidMaterial.SetTexture("_TranslucencyMap", array2[2]);
            this.optimizedCutoutMaterial.SetTexture("_MainTex", array2[0]);
            this.optimizedCutoutMaterial.SetTexture("_BumpSpecMap", array2[1]);
            this.optimizedCutoutMaterial.SetTexture("_TranslucencyMap", array2[2]);
            this.optimizedCutoutMaterial.SetTexture("_ShadowTex", array2[3]);
            this.UpdateShadowTexture(array2[3], atlas.atlasWidth, atlas.atlasHeight);
            return(true);
        }