void OnGUI()
    {
        if (material == null)
        {
            return;
        }

        // if this was an undo, repaint it
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                Repaint();
                return;
            }
        }

        Undo.RecordObject(material, "Modified Terrain Material");

        if (Ferr.EditorTools.ResetHandles())
        {
            GUI.changed = true;
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical(GUILayout.Width(width));

        Ferr.EditorTools.Box(5, () => {
            if (currDir != Ferr2DT_TerrainDirection.None)
            {
                Ferr2DT_TerrainMaterialUtility.ShowSample(material, currDir, width - 10);
            }
            Ferr.EditorTools.Box(2, () => {
                if (GUILayout.Button("Top"))
                {
                    currDir = Ferr2DT_TerrainDirection.Top;
                }
                if (currDir == Ferr2DT_TerrainDirection.Top)
                {
                    if (prevDir != currDir)
                    {
                        simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir));
                    }

                    bool showTop = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Top), "Use Top");
                    material.Set(Ferr2DT_TerrainDirection.Top, showTop);
                    if (showTop)
                    {
                        ShowDirection(material, currDir);
                    }
                }
            }, width - 10, 0);
            Ferr.EditorTools.Box(2, () => {
                if (GUILayout.Button("Left"))
                {
                    currDir = Ferr2DT_TerrainDirection.Left;
                }
                if (currDir == Ferr2DT_TerrainDirection.Left)
                {
                    if (prevDir != currDir)
                    {
                        simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir));
                    }

                    bool showLeft = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Left), "Use Left");
                    material.Set(Ferr2DT_TerrainDirection.Left, showLeft);
                    if (showLeft)
                    {
                        ShowDirection(material, currDir);
                    }
                }
            }, width - 10, 0);
            Ferr.EditorTools.Box(2, () => {
                if (GUILayout.Button("Right"))
                {
                    currDir = Ferr2DT_TerrainDirection.Right;
                }
                if (currDir == Ferr2DT_TerrainDirection.Right)
                {
                    if (prevDir != currDir)
                    {
                        simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir));
                    }

                    bool showRight = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Right), "Use Right");
                    material.Set(Ferr2DT_TerrainDirection.Right, showRight);
                    if (showRight)
                    {
                        ShowDirection(material, currDir);
                    }
                }
            }, width - 10, 0);
            Ferr.EditorTools.Box(2, () => {
                if (GUILayout.Button("Bottom"))
                {
                    currDir = Ferr2DT_TerrainDirection.Bottom;
                }
                if (currDir == Ferr2DT_TerrainDirection.Bottom)
                {
                    if (prevDir != currDir)
                    {
                        simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir));
                    }

                    bool showBottom = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Bottom), "Use Bottom");
                    material.Set(Ferr2DT_TerrainDirection.Bottom, showBottom);
                    if (showBottom)
                    {
                        ShowDirection(material, currDir);
                    }
                }
            }, width - 10, 0);
        }, 0, (int)this.position.height);

        EditorGUILayout.EndVertical();
        EditorGUILayout.BeginVertical();
        scroll = EditorGUILayout.BeginScrollView(scroll);
        if (currDir != Ferr2DT_TerrainDirection.None)
        {
            Ferr2DT_TerrainMaterialUtility.ShowPreview(material, currDir, simpleUVs, true, width);
        }
        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();

        if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDrag)
        {
            Repaint();
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(material);

            Ferr2DT_PathTerrain[] terrain = GameObject.FindObjectsOfType(typeof(Ferr2DT_PathTerrain)) as Ferr2DT_PathTerrain[];
            for (int i = 0; i < terrain.Length; i++)
            {
                if (terrain[i].TerrainMaterial == material)
                {
                    terrain[i].Build(true);
                }
            }
        }

        prevDir = currDir;
    }
Beispiel #2
0
    void OnGUI()
    {
        if (material == null)
        {
            return;
        }

        // if this was an undo, repaint it
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                Repaint();
                return;
            }
        }

                #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
        Undo.RecordObject(material, "Modified Terrain Material");
                #else
        Undo.SetSnapshotTarget(material, "Modified Terrain Material");
        if (!Ferr_EditorTools.HandlesMoving())
        {
            Undo.CreateSnapshot();
        }
                #endif
        if (Ferr_EditorTools.ResetHandles())
        {
            GUI.changed = true;
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical(GUILayout.Width(width));

        if (EditorGUILayout.Foldout(currDir == Ferr2DT_TerrainDirection.Top, "Top", foldoutStyle))
        {
            if (currDir != Ferr2DT_TerrainDirection.Top)
            {
                simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.descriptors[(int)Ferr2DT_TerrainDirection.Top]);
            }
            currDir = Ferr2DT_TerrainDirection.Top;
            bool showTop = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Top), "Use Top");
            material.Set(Ferr2DT_TerrainDirection.Top, showTop);
            if (showTop)
            {
                ShowDirection(material, currDir);
            }
        }
        if (EditorGUILayout.Foldout(currDir == Ferr2DT_TerrainDirection.Left, "Left", foldoutStyle))
        {
            if (currDir != Ferr2DT_TerrainDirection.Left)
            {
                simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.descriptors[(int)Ferr2DT_TerrainDirection.Left]);
            }
            currDir = Ferr2DT_TerrainDirection.Left;
            bool showLeft = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Left), "Use Left");
            material.Set(Ferr2DT_TerrainDirection.Left, showLeft);
            if (showLeft)
            {
                ShowDirection(material, currDir);
            }
        }
        if (EditorGUILayout.Foldout(currDir == Ferr2DT_TerrainDirection.Right, "Right", foldoutStyle))
        {
            if (currDir != Ferr2DT_TerrainDirection.Right)
            {
                simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.descriptors[(int)Ferr2DT_TerrainDirection.Right]);
            }
            currDir = Ferr2DT_TerrainDirection.Right;
            bool showRight = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Right), "Use Right");
            material.Set(Ferr2DT_TerrainDirection.Right, showRight);
            if (showRight)
            {
                ShowDirection(material, currDir);
            }
        }
        if (EditorGUILayout.Foldout(currDir == Ferr2DT_TerrainDirection.Bottom, "Bottom", foldoutStyle))
        {
            if (currDir != Ferr2DT_TerrainDirection.Bottom)
            {
                simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.descriptors[(int)Ferr2DT_TerrainDirection.Bottom]);
            }
            currDir = Ferr2DT_TerrainDirection.Bottom;
            bool showBottom = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Bottom), "Use Bottom");
            material.Set(Ferr2DT_TerrainDirection.Bottom, showBottom);
            if (showBottom)
            {
                ShowDirection(material, currDir);
            }
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.BeginVertical();
        if (currDir != Ferr2DT_TerrainDirection.None)
        {
            Ferr2DT_TerrainMaterialUtility.ShowPreview(material, currDir, simpleUVs, true, width);
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();

        if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDrag)
        {
            Repaint();
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(material);
                        #if (UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
            Undo.RegisterSnapshot();
                        #endif

            Ferr2DT_PathTerrain[] terrain = GameObject.FindObjectsOfType(typeof(Ferr2DT_PathTerrain)) as Ferr2DT_PathTerrain[];
            for (int i = 0; i < terrain.Length; i++)
            {
                if (terrain[i].TerrainMaterial == material)
                {
                    terrain[i].RecreatePath();
                }
            }
        }
                #if (UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
        Undo.ClearSnapshotTarget();
                #endif
    }