public static Rect AtlasField(Ferr2DT_TerrainMaterial aMat, Rect aRect, Texture aTexture)
    {
        EditorGUILayout.BeginHorizontal(GUILayout.Height(64));
        GUILayout.Space(5);
        GUILayout.Space(64);

        Rect  r   = GUILayoutUtility.GetLastRect();
        float max = Mathf.Max(1, Mathf.Max(aRect.width, aRect.height));

        r.width  = Mathf.Max(1, (aRect.width / max) * 64);
        r.height = Mathf.Max(1, (aRect.height / max) * 64);

        GUI.DrawTexture(new Rect(r.x - 1, r.y - 1, r.width + 2, 1), EditorGUIUtility.whiteTexture);
        GUI.DrawTexture(new Rect(r.x - 1, r.yMax + 1, r.width + 2, 1), EditorGUIUtility.whiteTexture);
        GUI.DrawTexture(new Rect(r.x - 1, r.y - 1, 1, r.height + 2), EditorGUIUtility.whiteTexture);
        GUI.DrawTexture(new Rect(r.xMax, r.y - 1, 1, r.height + 2), EditorGUIUtility.whiteTexture);
        GUI.DrawTextureWithTexCoords(r, aTexture, aMat.ToUV(aRect));
        GUILayout.Space(10);

        Rect result = aMat.ToNative(EditorGUILayout.RectField(aMat.ToPixels(aRect)));

        EditorGUILayout.EndHorizontal();

        return(result);
    }
    void OnGUI()
    {
        if (materials.Count == 0)
        {
            GUILayout.Label("No recently used Terrain Material components found.\nTry drag & dropping one instead.");
        }
        else
        {
            GUILayout.Label("List of Terrain Materials in the project.");

            DrawDivider(Color.white, 2, 10);

            Ferr2DT_TerrainMaterial pick = null;

            scroll = GUILayout.BeginScrollView(scroll, false, true);
            foreach (Ferr2DT_TerrainMaterial o in materials)
            {
                if (DrawObject(o))
                {
                    pick = o;
                }
            }
            GUILayout.EndScrollView();

            if (pick != null)
            {
                if (onPickMaterial != null)
                {
                    onPickMaterial(pick);
                }
                Close();
            }
        }
    }
Beispiel #3
0
    static void AddDecoTerrain(Ferr2DT_TerrainMaterial aMaterial)
    {
        GameObject obj = CreateBaseTerrain(aMaterial, false);

        Selection.activeGameObject = obj;
        EditorGUIUtility.PingObject(obj);
    }
    public static void EditUVsComplex(Ferr2DT_TerrainMaterial    aMat, Ferr2DT_SegmentDescription desc, float aWidth, ref int aCurrBody)
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Body", GUILayout.Width(40f));

        int bodyID = Mathf.Clamp(aCurrBody, 0, desc.body.Length);
        if (GUILayout.Button("<", GUILayout.Width(20f))) aCurrBody = Mathf.Clamp(aCurrBody - 1, 0, desc.body.Length - 1);
        EditorGUILayout.LabelField("" + (bodyID + 1), GUILayout.Width(12f));
        if (GUILayout.Button(">", GUILayout.Width(20f))) aCurrBody = Mathf.Clamp(aCurrBody + 1, 0, desc.body.Length - 1);
        bodyID = Mathf.Clamp(aCurrBody, 0, desc.body.Length - 1);
        int length = Math.Max(1, EditorGUILayout.IntField(desc.body.Length, GUILayout.Width(32f)));
        EditorGUILayout.LabelField("Total", GUILayout.Width(40f));
        if (length != desc.body.Length) Array.Resize<Rect>(ref desc.body, length);

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();
        desc.body[bodyID] = AtlasField(aMat, desc.body[bodyID], aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
        if (desc.leftCap.width == 0 && desc.leftCap.height == 0)
        {
            if (EditorGUILayout.Toggle("Left Cap", false))
            {
                desc.leftCap = new Rect(0, 0, 30, 30);
            }
        }
        else
        {
            if (EditorGUILayout.Toggle("Left Cap", true))
            {
                desc.leftCap = AtlasField(aMat, desc.leftCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
            }
            else
            {
                desc.leftCap = new Rect(0, 0, 0, 0);
            }

        }
        if (desc.rightCap.width == 0 && desc.rightCap.height == 0)
        {
            if (EditorGUILayout.Toggle("Right Cap", false))
            {
                desc.rightCap = new Rect(0, 0, 30, 30);
            }
        }
        else
        {
            if (EditorGUILayout.Toggle("Right Cap", true))
            {
                desc.rightCap = AtlasField(aMat, desc.rightCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
            }
            else
            {
                desc.rightCap = new Rect(0, 0, 0, 0);
            }
        }
    }
 public void ShowPreviewDirection(Ferr2DT_TerrainMaterial aMat, Ferr2DT_TerrainDirection aDir, Rect aBounds)
 {
     Ferr2DT_SegmentDescription desc = aMat.descriptors[(int)aDir];
     for (int i = 0; i < desc.body.Length; i++)
     {
         DrawRect(aMat.ToScreen( desc.body[i]  ), aBounds);
     }
     DrawRect(aMat.ToScreen( desc.leftCap  ), aBounds);
     DrawRect(aMat.ToScreen( desc.rightCap ), aBounds);
 }
    public static void ShowPreview         (Ferr2DT_TerrainMaterial aMat, Ferr2DT_TerrainDirection aDir, bool aSimpleUVs, bool aEditable, float aWidth) {
		if (aMat.edgeMaterial == null || aMat.edgeMaterial.mainTexture == null) return;
		
		GUILayout.Label(aMat.edgeMaterial.mainTexture, GUILayout.Width(Screen.width-aWidth));
		
		Rect texRect   = GUILayoutUtility.GetLastRect();
        texRect.width  = Mathf.Min(Screen.width-aWidth, aMat.edgeMaterial.mainTexture.width);
        texRect.height = (texRect.width / aMat.edgeMaterial.mainTexture.width) * aMat.edgeMaterial.mainTexture.height;
		
		ShowPreviewDirection(aMat, aDir, texRect, aSimpleUVs, aEditable);
	}
Beispiel #7
0
    static GameObject CreateBaseTerrain(Ferr2DT_TerrainMaterial aMaterial, bool aCreateColliders)
    {
        GameObject          obj     = new GameObject("New Terrain");
        Ferr2D_Path         path    = obj.AddComponent <Ferr2D_Path>();
        Ferr2DT_PathTerrain terrain = obj.AddComponent <Ferr2DT_PathTerrain>();

        bool hasEdges = aMaterial.Has(Ferr2DT_TerrainDirection.Bottom) ||
                        aMaterial.Has(Ferr2DT_TerrainDirection.Left) ||
                        aMaterial.Has(Ferr2DT_TerrainDirection.Right);

        if (hasEdges)
        {
            path.Add(new Vector2(-6, 0));
            path.Add(new Vector2(-6, 6));
            path.Add(new Vector2(6, 6));
            path.Add(new Vector2(6, 0));
            path.closed = true;
        }
        else
        {
            path.Add(new Vector2(-6, 6));
            path.Add(new Vector2(6, 6));
            terrain.splitCorners = false;
            path.closed          = false;
        }

        if (aMaterial.fillMaterial != null)
        {
            if (hasEdges)
            {
                terrain.fill = Ferr2DT_FillMode.Closed;
            }
            else
            {
                terrain.fill         = Ferr2DT_FillMode.Skirt;
                terrain.splitCorners = true;
            }
        }
        else
        {
            terrain.fill = Ferr2DT_FillMode.None;
        }
        terrain.smoothPath     = Ferr_Menu.SmoothTerrain;
        terrain.pixelsPerUnit  = Ferr_Menu.PPU;
        terrain.createCollider = aCreateColliders;
        terrain.SetMaterial(aMaterial);
        terrain.RecreatePath(true);

        obj.isStatic           = true;
        obj.transform.position = GetSpawnPos();

        return(obj);
    }
    public static void EditUVsSimple(Ferr2DT_TerrainMaterial aMat, Ferr2DT_SegmentDescription desc)
    {
        Rect cap  = aMat.ToPixels(desc.leftCap);
        Rect body = aMat.ToPixels(desc.body[0]);

        float   height    = body.height;
        float   capWidth  = cap.width;
        float   bodyWidth = body.width;
        int     bodyCount = desc.body.Length;
        Vector2 pos       = new Vector2(cap.x, cap.y);

        if (cap.width == 0 && cap.height == 0)
        {
            pos = new Vector2(body.x, body.y);
        }

        pos       = EditorGUILayout.Vector2Field("Position", pos);
        height    = EditorGUILayout.FloatField("Height", height);
        capWidth  = EditorGUILayout.FloatField("Cap Width", capWidth);
        bodyWidth = EditorGUILayout.FloatField("Body Width", bodyWidth);
        bodyCount = Mathf.Max(1, EditorGUILayout.IntField("Body slices", bodyCount));

        if (bodyCount != desc.body.Length)
        {
            Array.Resize <Rect>(ref desc.body, bodyCount);
        }

        float currX = pos.x;

        desc.leftCap.x      = currX;
        desc.leftCap.y      = pos.y;
        desc.leftCap.width  = capWidth;
        desc.leftCap.height = capWidth == 0 ? 0 : height;
        desc.leftCap        = aMat.ToNative(desc.leftCap);
        currX += capWidth;

        for (int i = 0; i < desc.body.Length; i++)
        {
            desc.body[i].x      = currX;
            desc.body[i].y      = pos.y;
            desc.body[i].width  = bodyWidth;
            desc.body[i].height = height;
            desc.body[i]        = aMat.ToNative(desc.body[i]);
            currX += bodyWidth;
        }

        desc.rightCap.x      = currX;
        desc.rightCap.y      = pos.y;
        desc.rightCap.width  = capWidth;
        desc.rightCap.height = capWidth == 0 ? 0 : height;
        desc.rightCap        = aMat.ToNative(desc.rightCap);
    }
Beispiel #9
0
    public static void Show(Ferr2DT_TerrainMaterial aMaterial)
    {
        Ferr2DT_TerrainMaterialWindow window = EditorWindow.GetWindow <Ferr2DT_TerrainMaterialWindow>();

        window.material       = aMaterial;
        window.wantsMouseMove = true;
        window.title          = "Ferr2DT Editor";
        if (aMaterial != null && aMaterial.edgeMaterial != null)
        {
            window.minSize = new Vector2(width + aMaterial.edgeMaterial.mainTexture.width + 10, aMaterial.edgeMaterial.mainTexture.height + 10);
        }
        window.foldoutStyle           = EditorStyles.foldout;
        window.foldoutStyle.fontStyle = FontStyle.Bold;
        window.currDir = Ferr2DT_TerrainDirection.None;
    }
Beispiel #10
0
    public static void Show(Ferr2DT_TerrainMaterial aMaterial)
    {
        Ferr2DT_TerrainMaterialWindow window = EditorWindow.GetWindow <Ferr2DT_TerrainMaterialWindow>();

        window.material          = aMaterial;
        window.wantsMouseMove    = true;
        window.titleContent.text = "Ferr2DT Editor";
        if (aMaterial != null && aMaterial.edgeMaterial != null)
        {
            window.minSize = new Vector2(400, 400);
        }
        window.foldoutStyle           = EditorStyles.foldout;
        window.foldoutStyle.fontStyle = FontStyle.Bold;
        window.currDir = Ferr2DT_TerrainDirection.None;
        window.prevDir = Ferr2DT_TerrainDirection.None;
    }
    public static void ShowPreview(Ferr2DT_TerrainMaterial aMat, Ferr2DT_TerrainDirection aDir, bool aSimpleUVs, bool aEditable, float aWidth)
    {
        if (aMat.edgeMaterial == null || aMat.edgeMaterial.mainTexture == null)
        {
            return;
        }

        GUILayout.Label(aMat.edgeMaterial.mainTexture);

        Rect texRect = GUILayoutUtility.GetLastRect();

        texRect.width  = Mathf.Min(Screen.width - aWidth, aMat.edgeMaterial.mainTexture.width);
        texRect.height = (texRect.width / aMat.edgeMaterial.mainTexture.width) * aMat.edgeMaterial.mainTexture.height;

        ShowPreviewDirection(aMat, aDir, texRect, aSimpleUVs, aEditable);
    }
    public override void OnInspectorGUI()
    {
        Undo.RecordObject(target, "Modified Terrain Material");

        Ferr2DT_TerrainMaterial mat = target as Ferr2DT_TerrainMaterial;
        Material newMat;

        newMat = mat.edgeMaterial = (Material)EditorGUILayout.ObjectField("Edge Material", mat.edgeMaterial, typeof(Material), true);
        if (mat.edgeMaterial != newMat)
        {
            mat.edgeMaterial = newMat;
            Ferr2DT_TerrainMaterialUtility.CheckMaterialMode(mat.edgeMaterial, TextureWrapMode.Clamp);
        }

        newMat = (Material)EditorGUILayout.ObjectField("Fill Material", mat.fillMaterial, typeof(Material), true);
        if (mat.fillMaterial != newMat)
        {
            mat.fillMaterial = newMat;
            Ferr2DT_TerrainMaterialUtility.CheckMaterialMode(mat.fillMaterial, TextureWrapMode.Repeat);
        }

        if (mat.edgeMaterial == null)
        {
            EditorGUILayout.HelpBox("Please add an edge material to enable the material editor!", MessageType.Warning);
        }
        else
        {
            if (GUILayout.Button("Open Material Editor"))
            {
                Ferr2DT_TerrainMaterialWindow.Show(mat);
            }
        }
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);

            Ferr2DT_PathTerrain[] terrain = GameObject.FindObjectsOfType(typeof(Ferr2DT_PathTerrain)) as Ferr2DT_PathTerrain[];
            for (int i = 0; i < terrain.Length; i++)
            {
                if (terrain[i].TerrainMaterial == mat)
                {
                    terrain[i].Build(true);
                }
            }
        }
    }
    bool DrawObject(Ferr2DT_TerrainMaterial mb)
    {
        bool retVal = false;

        GUILayout.BeginHorizontal();
        {
            if (mb.edgeMaterial != null && mb.edgeMaterial.mainTexture != null) {
                retVal = GUILayout.Button(mb.edgeMaterial.mainTexture, GUILayout.Width(64f), GUILayout.Height(64f));
            } else {
                retVal = GUILayout.Button("Select",  GUILayout.Width(64f), GUILayout.Height(64f));
            }
            GUILayout.Label(mb.gameObject.name, GUILayout.Width(160f));

            GUI.color = Color.white;
        }
        GUILayout.EndHorizontal();
        return retVal;
    }
    void ShowDirection(Ferr2DT_TerrainMaterial aMat, Ferr2DT_TerrainDirection aDir)
    {
        Ferr2DT_SegmentDescription desc = aMat.GetDescriptor(aDir);

        desc.zOffset   = EditorGUILayout.FloatField("Z Offset", desc.zOffset);
        desc.yOffset   = EditorGUILayout.FloatField("Y Offset", desc.yOffset);
        desc.capOffset = EditorGUILayout.FloatField("Cap Offset", desc.capOffset);

        simpleUVs = EditorGUILayout.Toggle("Simple", simpleUVs);
        if (simpleUVs)
        {
            Ferr2DT_TerrainMaterialUtility.EditUVsSimple(aMat, desc);
        }
        else
        {
            Ferr2DT_TerrainMaterialUtility.EditUVsComplex(aMat, desc, width, ref currBody);
        }
    }
Beispiel #15
0
    static GameObject CreateBaseTerrain(Ferr2DT_TerrainMaterial aMaterial, bool aCreateColliders)
    {
        GameObject          obj     = new GameObject("New Terrain");
        Ferr2D_Path         path    = obj.AddComponent<Ferr2D_Path        >();
        Ferr2DT_PathTerrain terrain = obj.AddComponent<Ferr2DT_PathTerrain>();

        bool hasEdges = aMaterial.Has(Ferr2DT_TerrainDirection.Bottom) ||
                        aMaterial.Has(Ferr2DT_TerrainDirection.Left) ||
                        aMaterial.Has(Ferr2DT_TerrainDirection.Right);

        if (hasEdges) {
            path.Add(new Vector2(-6, 0));
            path.Add(new Vector2(-6, 6));
            path.Add(new Vector2( 6, 6));
            path.Add(new Vector2( 6, 0));
            path.closed = true;
        } else {
            path.Add(new Vector2(-6, 6));
            path.Add(new Vector2( 6, 6));
            terrain.splitCorners = false;
            path.closed = false;
        }

        if (aMaterial.fillMaterial != null) {
            if (hasEdges) {
                terrain.fill = Ferr2DT_FillMode.Closed;
            } else {
                terrain.fill = Ferr2DT_FillMode.Skirt;
                terrain.splitCorners = true;
            }
        } else {
            terrain.fill = Ferr2DT_FillMode.None;
        }
        terrain.smoothPath     = Ferr_Menu.SmoothTerrain;
        terrain.pixelsPerUnit  = Ferr_Menu.PPU;
        terrain.createCollider = aCreateColliders;
        terrain.SetMaterial (aMaterial);
        terrain.RecreatePath(true);

        obj.isStatic           = true;
        obj.transform.position = GetSpawnPos();

        return obj;
    }
Beispiel #16
0
    /// <summary>
    /// This will allow you to set the terrain material regardless of whether it's marked as the current material already or not. Also calls RecreatePath when finished.
    /// </summary>
    /// <param name="aMaterial">The terrain material! Usually from a terrain material prefab.</param>
    /// <param name="aForceUpdate">Force it to set the material, even if it's already the set material, or no?</param>
    /// <param name="aRecreate">Should we recreate the mesh? Usually, this is what you want (only happens if the material changes, or is forced to change)</param>
    public void                        ForceMaterial(Ferr2DT_TerrainMaterial aMaterial, bool aForceUpdate, bool aRecreate = true)
    {
        if (terrainMaterial != aMaterial || aForceUpdate)
        {
            terrainMaterial = aMaterial;

            // copy the materials into the renderer
            Material[] newMaterials = new Material[] {
                aMaterial.fillMaterial,
                aMaterial.edgeMaterial
            };
            renderer.sharedMaterials = newMaterials;

            if (aRecreate)
            {
                RecreatePath();
            }
        }
    }
Beispiel #17
0
    public override void OnInspectorGUI()
    {
                #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(target, "Modified Terrain Material");
                #else
        Undo.SetSnapshotTarget(target, "Modified Terrain Material");
                #endif

        Ferr2DT_TerrainMaterial mat = target as Ferr2DT_TerrainMaterial;

        mat.edgeMaterial = (Material)EditorGUILayout.ObjectField("Edge Material", mat.edgeMaterial, typeof(Material), true);
        Material newMat = (Material)EditorGUILayout.ObjectField("Fill Material", mat.fillMaterial, typeof(Material), true);
        if (mat.fillMaterial != newMat)
        {
            mat.fillMaterial = newMat;
            Ferr2DT_TerrainMaterialUtility.CheckMaterialRepeat(mat.fillMaterial);
        }
        if (mat.edgeMaterial == null)
        {
            EditorGUILayout.HelpBox("Please add an edge material to enable the material editor!", MessageType.Warning);
        }
        else
        {
            if (GUILayout.Button("Open Material Editor"))
            {
                Ferr2DT_TerrainMaterialWindow.Show(mat);
            }
        }
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);

            Ferr2DT_PathTerrain[] terrain = GameObject.FindObjectsOfType(typeof(Ferr2DT_PathTerrain)) as Ferr2DT_PathTerrain[];
            for (int i = 0; i < terrain.Length; i++)
            {
                if (terrain[i].TerrainMaterial == mat)
                {
                    terrain[i].RecreatePath(true);
                }
            }
        }
    }
Beispiel #18
0
    /// <summary>
    /// This will allow you to set the terrain material regardless of whether it's marked as the current material already or not. Also calls RecreatePath when finished.
    /// </summary>
    /// <param name="aMaterial">The terrain material! Usually from a terrain material prefab.</param>
    /// <param name="aForceUpdate">Force it to set the material, even if it's already the set material, or no?</param>
    /// <param name="aRecreate">Should we recreate the mesh? Usually, this is what you want (only happens if the material changes, or is forced to change)</param>
    public void                        ForceMaterial(Ferr2DT_TerrainMaterial aMaterial, bool aForceUpdate, bool aRecreate = true)
    {
        if (terrainMaterial != aMaterial || aForceUpdate)
        {
            terrainMaterial = aMaterial;

            // copy the materials into the renderer
            Material[] newMaterials = null;
            if (fill == Ferr2DT_FillMode.Closed || fill == Ferr2DT_FillMode.InvertedClosed || fill == Ferr2DT_FillMode.Skirt)
            {
                newMaterials = new Material[] {
                    aMaterial.fillMaterial,
                    aMaterial.edgeMaterial
                };
            }
            else if (fill == Ferr2DT_FillMode.None)
            {
                newMaterials = new Material[] {
                    aMaterial.edgeMaterial
                };
            }
            else if (fill == Ferr2DT_FillMode.FillOnlyClosed || fill == Ferr2DT_FillMode.FillOnlySkirt)
            {
                newMaterials = new Material[] {
                    aMaterial.fillMaterial
                };
            }
            GetComponent <Renderer>().sharedMaterials = newMaterials;

            // make sure we update the units per UV
            if (terrainMaterial.edgeMaterial != null && terrainMaterial.edgeMaterial.mainTexture != null)
            {
                unitsPerUV.x = terrainMaterial.edgeMaterial.mainTexture.width / pixelsPerUnit;
                unitsPerUV.y = terrainMaterial.edgeMaterial.mainTexture.height / pixelsPerUnit;
            }

            if (aRecreate)
            {
                Build(true);
            }
        }
    }
Beispiel #19
0
    static void AddDecoTerrain(Ferr2DT_TerrainMaterial aMaterial)
    {
        GameObject          obj     = new GameObject("New Terrain");
        Ferr2D_Path         path    = obj.AddComponent <Ferr2D_Path>();
        Ferr2DT_PathTerrain terrain = obj.AddComponent <Ferr2DT_PathTerrain>();

        path.Add(new Vector2(-6, 6));
        path.Add(new Vector2(6, 6));

        terrain.fill           = Ferr2DT_FillMode.Skirt;
        terrain.createCollider = false;
        terrain.SetMaterial(aMaterial);
        terrain.RecreatePath();

        obj.isStatic           = true;
        obj.transform.position = GetSpawnPos();

        Selection.activeGameObject = obj;
        EditorGUIUtility.PingObject(obj);
    }
Beispiel #20
0
    static void AddPhysicalTerrain(Ferr2DT_TerrainMaterial aMaterial)
    {
        GameObject           obj      = new GameObject("New Terrain");
        Ferr2D_Path         path     = obj.AddComponent<Ferr2D_Path>();
        Ferr2DT_PathTerrain  terrain  = obj.AddComponent<Ferr2DT_PathTerrain>();

        path.Add(new Vector2(-6, 6));
        path.Add(new Vector2( 6, 6));

        terrain.fill           = Ferr2DT_FillMode.Skirt;
        terrain.createCollider = true;
        terrain.SetMaterial (aMaterial);
        terrain.RecreatePath();

        obj.isStatic = true;
        obj.transform.position = GetSpawnPos();

        Selection.activeGameObject = obj;
        EditorGUIUtility.PingObject(obj);
    }
    bool DrawObject(Ferr2DT_TerrainMaterial mb)
    {
        bool retVal = false;

        GUILayout.BeginHorizontal();
        {
            if (mb.edgeMaterial != null && mb.edgeMaterial.mainTexture != null)
            {
                retVal = GUILayout.Button(mb.edgeMaterial.mainTexture, GUILayout.Width(64f), GUILayout.Height(64f));
            }
            else
            {
                retVal = GUILayout.Button("Select", GUILayout.Width(64f), GUILayout.Height(64f));
            }
            GUILayout.Label(mb.gameObject.name, GUILayout.Width(160f));

            GUI.color = Color.white;
        }
        GUILayout.EndHorizontal();
        return(retVal);
    }
    public static Rect AtlasField          (Ferr2DT_TerrainMaterial aMat, Rect aRect, Texture aTexture) {
		EditorGUILayout.BeginHorizontal(GUILayout.Height(64));
		GUILayout.Space(5);
		GUILayout.Space(64);
		
		Rect  r   = GUILayoutUtility.GetLastRect();
		float max = Mathf.Max (1, Mathf.Max ( aRect.width, aRect.height ));
		r.width   = Mathf.Max (1, (aRect.width  / max) * 64);
		r.height  = Mathf.Max (1, (aRect.height / max) * 64);
		
		GUI      .DrawTexture(new Rect(r.x-1,  r.y-1,    r.width+2, 1),          EditorGUIUtility.whiteTexture);
		GUI      .DrawTexture(new Rect(r.x-1,  r.yMax+1, r.width+2, 1),          EditorGUIUtility.whiteTexture);
		GUI      .DrawTexture(new Rect(r.x-1,  r.y-1,    1,         r.height+2), EditorGUIUtility.whiteTexture);
		GUI      .DrawTexture(new Rect(r.xMax, r.y-1,    1,         r.height+2), EditorGUIUtility.whiteTexture);
		GUI      .DrawTextureWithTexCoords(r, aTexture, aMat.ToUV(aRect));
		GUILayout.Space(10);

        Rect result = aMat.ToNative(EditorGUILayout.RectField(aMat.ToPixels(aRect)));
		EditorGUILayout.EndHorizontal();
		
		return result;
	}
Beispiel #23
0
    public static void Show(Action <Ferr2DT_TerrainMaterial> aOnPickMaterial)
    {
        Ferr2DT_MaterialSelector wiz = ScriptableWizard.DisplayWizard <Ferr2DT_MaterialSelector>("Select Terrain Material");

        wiz.materials      = new List <Ferr2DT_TerrainMaterial>();
        wiz.onPickMaterial = aOnPickMaterial;

        string[] fileNames  = System.IO.Directory.GetFiles(Application.dataPath, "*.prefab", System.IO.SearchOption.AllDirectories);
        int      pathLength = Application.dataPath.Length + 1;

        for (int i = fileNames.Length; i > 0; i--)
        {
            fileNames [i - 1] = "Assets\\" + fileNames[i - 1].Substring(pathLength);
            GameObject go = UnityEditor.AssetDatabase.LoadAssetAtPath(fileNames[i - 1], typeof(GameObject)) as GameObject;
            if (go != null)
            {
                Ferr2DT_TerrainMaterial source = go.GetComponent <Ferr2DT_TerrainMaterial>();
                if (source)
                {
                    wiz.materials.Add(source);
                }
            }
        }
    }
    public static void ShowSample(Ferr2DT_TerrainMaterial aMat, Ferr2DT_TerrainDirection aDir, float aWidth)
    {
        if (aMat.edgeMaterial == null || aMat.edgeMaterial.mainTexture == null)
        {
            return;
        }

        Ferr2DT_SegmentDescription desc = aMat.GetDescriptor(aDir);
        float totalWidth   = desc.leftCap.width + desc.rightCap.width + (desc.body[0].width * 3);
        float sourceHeight = MaxHeight(desc);

        float scale = Mathf.Min(aWidth / totalWidth, 64 / sourceHeight);

        GUILayout.Space(sourceHeight * scale);
        float x = GUILayoutUtility.GetLastRect().x;
        float y = GUILayoutUtility.GetLastRect().y;

        if (desc.leftCap.width != 0)
        {
            float yOff = ((sourceHeight - desc.leftCap.height) / 2) * scale;
            GUI.DrawTextureWithTexCoords(new Rect(x, y + yOff, desc.leftCap.width * scale, desc.leftCap.height * scale), aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture, aMat.ToUV(desc.leftCap));
            x += desc.leftCap.width * scale;
        }
        for (int i = 0; i < 3; i++)
        {
            int   id   = (2 - i) % desc.body.Length;
            float yOff = ((sourceHeight - desc.body[id].height) / 2) * scale;
            GUI.DrawTextureWithTexCoords(new Rect(x, y + yOff, desc.body[id].width * scale, desc.body[id].height * scale), aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture, aMat.ToUV(desc.body[id]));
            x += desc.body[id].width * scale;
        }
        if (desc.leftCap.width != 0)
        {
            float yOff = ((sourceHeight - desc.rightCap.height) / 2) * scale;
            GUI.DrawTextureWithTexCoords(new Rect(x, y + yOff, desc.rightCap.width * scale, desc.rightCap.height * scale), aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture, aMat.ToUV(desc.rightCap));
        }
    }
    void ShowDirection(Ferr2DT_TerrainMaterial aMat, Ferr2DT_TerrainDirection aDir)
    {
        Ferr2DT_SegmentDescription desc = aMat.descriptors[(int)aDir];

        desc.zOffset   = EditorGUILayout.FloatField( "Z Offset",   desc.zOffset  );
        desc.yOffset   = EditorGUILayout.FloatField( "Y Offset",   desc.yOffset  );
        desc.capOffset = EditorGUILayout.FloatField( "Cap Offset", desc.capOffset);

        Ferr2DT_TerrainMaterialUtility.ShowSample(aMat, aDir, width);

        simpleUVs = EditorGUILayout.Toggle("Simple", simpleUVs);
        if (simpleUVs) {
            Ferr2DT_TerrainMaterialUtility.EditUVsSimple(desc);
        } else {
            Ferr2DT_TerrainMaterialUtility.EditUVsComplex(aMat, desc, width, ref currBody);
        }
    }
    public static void ShowSample(Ferr2DT_TerrainMaterial aMat, Ferr2DT_TerrainDirection aDir, float aWidth)
    {
        if (aMat.edgeMaterial == null || aMat.edgeMaterial.mainTexture == null)  return;

        Ferr2DT_SegmentDescription desc = aMat.descriptors[(int)aDir];
        float totalWidth                = desc.leftCap.width + desc.rightCap.width + (desc.body[0].width * 3);
        float sourceHeight              = MaxHeight(desc);

        float scale = Mathf.Min(aWidth/totalWidth, 64 / sourceHeight);

        GUILayout.Space(sourceHeight* scale);
        float x = 0;
        float y = GUILayoutUtility.GetLastRect().y;
        if (desc.leftCap.width != 0) {
            float yOff = ((sourceHeight - desc.leftCap.height) / 2) * scale;
            GUI.DrawTextureWithTexCoords(new Rect(0,y+yOff,desc.leftCap.width * scale, desc.leftCap.height * scale), aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture, aMat.ToUV(desc.leftCap));
            x += desc.leftCap.width * scale;
        }
        for (int i = 0; i < 3; i++)
        {
            int id = (2-i) % desc.body.Length;
            float yOff = ((sourceHeight - desc.body[id].height) / 2) * scale;
            GUI.DrawTextureWithTexCoords(new Rect(x,y+yOff,desc.body[id].width * scale, desc.body[id].height * scale), aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture, aMat.ToUV(desc.body[id]));
            x += desc.body[id].width * scale;
        }
        if (desc.leftCap.width != 0) {
            float yOff = ((sourceHeight - desc.rightCap.height) / 2) * scale;
            GUI.DrawTextureWithTexCoords(new Rect(x,y+yOff,desc.rightCap.width * scale, desc.rightCap.height * scale), aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture, aMat.ToUV(desc.rightCap));
        }
    }
 public static void Show(Ferr2DT_TerrainMaterial aMaterial)
 {
     Ferr2DT_TerrainMaterialWindow window = EditorWindow.GetWindow<Ferr2DT_TerrainMaterialWindow>();
     window.material       = aMaterial;
     window.wantsMouseMove = true;
     window.title          = "Ferr2DT Editor";
     if (aMaterial != null && aMaterial.edgeMaterial != null) {
         window.minSize = new Vector2(width + aMaterial.edgeMaterial.mainTexture.width +10, aMaterial.edgeMaterial.mainTexture.height+10);
     }
     window.foldoutStyle           = EditorStyles.foldout;
     window.foldoutStyle.fontStyle = FontStyle.Bold;
     window.currDir                = Ferr2DT_TerrainDirection.None;
 }
Beispiel #28
0
 static void AddPhysicalTerrain(Ferr2DT_TerrainMaterial aMaterial)
 {
     GameObject obj = CreateBaseTerrain(aMaterial, true);
     Selection.activeGameObject = obj;
     EditorGUIUtility.PingObject(obj);
 }
    public static void ShowPreviewDirection(Ferr2DT_TerrainMaterial aMat, Ferr2DT_TerrainDirection aDir, Rect aBounds, bool aSimpleUVs, bool aEditable)
    {
        Ferr2DT_SegmentDescription desc = aMat.descriptors[(int)aDir];
        if (!aMat.Has(aDir)) return;

        if (!aEditable) {
            for (int i = 0; i < desc.body.Length; i++)
            {
                Ferr_EditorTools.DrawRect(aMat.ToScreen( desc.body[i]  ), aBounds);
            }
            Ferr_EditorTools.DrawRect(aMat.ToScreen( desc.leftCap  ), aBounds);
            Ferr_EditorTools.DrawRect(aMat.ToScreen( desc.rightCap ), aBounds);
        }
        else if (aSimpleUVs) {
            float   height    = MaxHeight(desc);
            float   capWidth  = Mathf.Max(desc.leftCap.width, desc.rightCap.width);
            float   bodyWidth = desc.body[0].width;
            int     bodyCount = desc.body.Length;
            Vector2 pos       = new Vector2(desc.leftCap.x, desc.leftCap.y);
            if (desc.leftCap.width == 0 && desc.leftCap.height == 0) pos = new Vector2(desc.body[0].x, desc.body[0].y);

            Rect bounds = new Rect(pos.x, pos.y, capWidth*2+bodyWidth*bodyCount, height);
            bounds = Ferr_EditorTools.UVRegionRect(bounds,  aBounds);
            bounds = ClampRect(bounds, (Texture2D)aMat.edgeMaterial.mainTexture);
            Ferr_EditorTools.DrawVLine(new Vector2(pos.x + capWidth + aBounds.x, pos.y+1), height);
            for (int i = 1; i <= desc.body.Length; i++) {
                Ferr_EditorTools.DrawVLine(new Vector2(pos.x + capWidth + bodyWidth*i + aBounds.x, pos.y+1), height);
            }

            height    = bounds.height;
            bodyWidth = (bounds.width - capWidth * 2) / bodyCount;
            pos.x     = bounds.x;
            pos.y     = bounds.y;

            float currX = pos.x;
            desc.leftCap.x      = currX;
            desc.leftCap.y      = pos.y;
            desc.leftCap.width  = capWidth;
            desc.leftCap.height = capWidth == 0 ? 0 : height;
            currX += capWidth;

            for (int i = 0; i < desc.body.Length; i++)
            {
                desc.body[i].x      = currX;
                desc.body[i].y      = pos.y;
                desc.body[i].width  = bodyWidth;
                desc.body[i].height = height;
                currX += bodyWidth;
            }

            desc.rightCap.x      = currX;
            desc.rightCap.y      = pos.y;
            desc.rightCap.width  = capWidth;
            desc.rightCap.height = capWidth == 0 ? 0 : height;

        } else {
            for (int i = 0; i < desc.body.Length; i++) {
                desc.body[i]  = ClampRect(Ferr_EditorTools.UVRegionRect(desc.body[i], aBounds), (Texture2D)aMat.edgeMaterial.mainTexture);
            }
            if (desc.leftCap.width != 0 && desc.leftCap.height != 0)
                desc.leftCap  = ClampRect(Ferr_EditorTools.UVRegionRect(desc.leftCap,  aBounds), (Texture2D)aMat.edgeMaterial.mainTexture);
            if (desc.rightCap.width != 0 && desc.rightCap.height != 0)
                desc.rightCap = ClampRect(Ferr_EditorTools.UVRegionRect(desc.rightCap, aBounds), (Texture2D)aMat.edgeMaterial.mainTexture);
        }
    }
Beispiel #30
0
    /// <summary>
    /// This will allow you to set the terrain material regardless of whether it's marked as the current material already or not. Also calls RecreatePath when finished.
    /// </summary>
    /// <param name="aMaterial">The terrain material! Usually from a terrain material prefab.</param>
    /// <param name="aForceUpdate">Force it to set the material, even if it's already the set material, or no?</param>
    /// <param name="aRecreate">Should we recreate the mesh? Usually, this is what you want (only happens if the material changes, or is forced to change)</param>
    public  void                        ForceMaterial   (Ferr2DT_TerrainMaterial aMaterial, bool aForceUpdate, bool aRecreate = true)
    {
        if (terrainMaterial != aMaterial || aForceUpdate)
        {
            terrainMaterial = aMaterial;

            // copy the materials into the renderer
            Material[] newMaterials = null;
            if (fill == Ferr2DT_FillMode.Closed || fill == Ferr2DT_FillMode.InvertedClosed || fill == Ferr2DT_FillMode.Skirt) {
                newMaterials = new Material[] {
                    aMaterial.fillMaterial,
                    aMaterial.edgeMaterial
                };
            } else if (fill == Ferr2DT_FillMode.None) {
                newMaterials = new Material[] {
                    aMaterial.edgeMaterial
                };
            } else if (fill == Ferr2DT_FillMode.FillOnlyClosed || fill == Ferr2DT_FillMode.FillOnlySkirt) {
                newMaterials = new Material[] {
                    aMaterial.fillMaterial
                };
            }
            GetComponent<Renderer>().sharedMaterials = newMaterials;

            // make sure we update the units per UV
            if (terrainMaterial.edgeMaterial != null && terrainMaterial.edgeMaterial.mainTexture != null) {
                unitsPerUV.x = terrainMaterial.edgeMaterial.mainTexture.width  / pixelsPerUnit;
                unitsPerUV.y = terrainMaterial.edgeMaterial.mainTexture.height / pixelsPerUnit;
            }

            if (aRecreate) {
                Build(true);
            }
        }
    }
Beispiel #31
0
 /// <summary>
 /// Sets the material of the mesh. Calls ForceMaterial with an aForceUpdate of false.
 /// </summary>
 /// <param name="aMaterial">The terrain material! Usually from a terrain material prefab.</param>
 public  void                        SetMaterial     (Ferr2DT_TerrainMaterial aMaterial) { 
     ForceMaterial(aMaterial, false); 
 }
    public static void EditUVsSimple(Ferr2DT_TerrainMaterial    aMat, Ferr2DT_SegmentDescription desc)
    {
        Rect cap  = aMat.ToPixels(desc.leftCap);
        Rect body = aMat.ToPixels(desc.body[0]);

        float   height    = body.height;
        float   capWidth  = cap .width;
        float   bodyWidth = body.width;
        int     bodyCount = desc.body.Length;
        Vector2 pos       = new Vector2(cap.x, cap.y);
        if (cap.width == 0 && cap.height == 0) pos = new Vector2(body.x, body.y);

        pos       = EditorGUILayout.Vector2Field("Position",    pos      );
        height    = EditorGUILayout.FloatField  ("Height",      height   );
        capWidth  = EditorGUILayout.FloatField  ("Cap Width",   capWidth );
        bodyWidth = EditorGUILayout.FloatField  ("Body Width",  bodyWidth);
        bodyCount = Mathf.Max(1, EditorGUILayout.IntField    ("Body slices", bodyCount));

        if (bodyCount != desc.body.Length) {
            Array.Resize<Rect>(ref desc.body, bodyCount);
        }

        float currX = pos.x;
        desc.leftCap.x      = currX;
        desc.leftCap.y      = pos.y;
        desc.leftCap.width  = capWidth;
        desc.leftCap.height = capWidth == 0 ? 0 : height;
        desc.leftCap = aMat.ToNative(desc.leftCap);
        currX += capWidth;

        for (int i = 0; i < desc.body.Length; i++)
        {
            desc.body[i].x      = currX;
            desc.body[i].y      = pos.y;
            desc.body[i].width  = bodyWidth;
            desc.body[i].height = height;
            desc.body[i] = aMat.ToNative(desc.body[i]);
            currX += bodyWidth;
        }

        desc.rightCap.x      = currX;
        desc.rightCap.y      = pos.y;
        desc.rightCap.width  = capWidth;
        desc.rightCap.height = capWidth == 0 ? 0 : height;
        desc.rightCap = aMat.ToNative(desc.rightCap);
    }
Beispiel #33
0
 /// <summary>
 /// Sets the material of the mesh. Calls ForceMaterial with an aForceUpdate of false.
 /// </summary>
 /// <param name="aMaterial">The terrain material! Usually from a terrain material prefab.</param>
 public void                        SetMaterial(Ferr2DT_TerrainMaterial aMaterial)
 {
     ForceMaterial(aMaterial, false);
 }
 public static void Show(Ferr2DT_TerrainMaterial aMaterial)
 {
     Ferr2DT_TerrainMaterialWindow window = EditorWindow.GetWindow<Ferr2DT_TerrainMaterialWindow>();
     window.material       = aMaterial;
     window.wantsMouseMove = true;
     window.title          = "Ferr2DT Editor";
     if (aMaterial != null && aMaterial.edgeMaterial != null) {
         window.minSize = new Vector2(400, 400);
         Ferr2DT_TerrainMaterialUtility.CheckMaterialRepeat(aMaterial.fillMaterial);
     }
     window.foldoutStyle           = EditorStyles.foldout;
     window.foldoutStyle.fontStyle = FontStyle.Bold;
     window.currDir                = Ferr2DT_TerrainDirection.None;
     window.prevDir                = Ferr2DT_TerrainDirection.None;
 }
    private void ShowPreview(Ferr2DT_TerrainMaterial aMat)
    {
        if (aMat.edgeMaterial == null || aMat.edgeMaterial.mainTexture == null) return;

        GUILayout.Label(aMat.edgeMaterial.mainTexture, GUILayout.Width(Screen.width-25));

        Rect texRect = GUILayoutUtility.GetLastRect();
        //texRect.width = aMat.edgeMaterial.mainTexture.width;
        texRect.width = Mathf.Min(Screen.width-25, aMat.edgeMaterial.mainTexture.width);
        texRect.height = (texRect.width / aMat.edgeMaterial.mainTexture.width) * aMat.edgeMaterial.mainTexture.height;

        if (topFold   ) ShowPreviewDirection(aMat, Ferr2DT_TerrainDirection.Top,    texRect);
        if (rightFold ) ShowPreviewDirection(aMat, Ferr2DT_TerrainDirection.Right,  texRect);
        if (leftFold  ) ShowPreviewDirection(aMat, Ferr2DT_TerrainDirection.Left,   texRect);
        if (bottomFold) ShowPreviewDirection(aMat, Ferr2DT_TerrainDirection.Bottom, texRect);
    }
    private void ShowDirection(Ferr2DT_TerrainMaterial aMat, Ferr2DT_TerrainDirection aDir)
    {
        Ferr2DT_SegmentDescription desc = aMat.descriptors[(int)aDir];
        desc.zOffset   = EditorGUILayout.FloatField( "Z Offset",   desc.zOffset  );
        desc.yOffset   = EditorGUILayout.FloatField( "Y Offset",   desc.yOffset  );
        desc.capOffset = EditorGUILayout.FloatField( "Cap Offset", desc.capOffset);

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Body", GUILayout.Width(40f));

        int bodyID = Mathf.Clamp(currBody, 0, desc.body.Length);
        if (GUILayout.Button("<", GUILayout.Width(20f))) currBody = Mathf.Clamp(currBody - 1, 0, desc.body.Length - 1);
        EditorGUILayout.LabelField("" + bodyID, GUILayout.Width(12f));
        if (GUILayout.Button(">", GUILayout.Width(20f))) currBody = Mathf.Clamp(currBody + 1, 0, desc.body.Length - 1);
        bodyID = Mathf.Clamp(currBody, 0, desc.body.Length-1);
        int length = Math.Max(1, EditorGUILayout.IntField(desc.body.Length, GUILayout.Width(32f)));
        EditorGUILayout.LabelField("Total", GUILayout.Width(40f));
        if (length != desc.body.Length) Array.Resize<Rect>(ref desc.body, length);

        EditorGUILayout.EndHorizontal();

        desc.body[bodyID]  = AtlasField(aMat, desc.body[bodyID] , aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
        EditorGUILayout.LabelField("Left Cap");
        desc.leftCap  = AtlasField(aMat, desc.leftCap , aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
        EditorGUILayout.LabelField("Right Cap");
        desc.rightCap = AtlasField(aMat, desc.rightCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
    }
    public static void EditUVsComplex(Ferr2DT_TerrainMaterial aMat, Ferr2DT_SegmentDescription desc, float aWidth, ref int aCurrBody)
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Body", GUILayout.Width(40f));

        int bodyID = Mathf.Clamp(aCurrBody, 0, desc.body.Length);

        if (GUILayout.Button("<", GUILayout.Width(20f)))
        {
            aCurrBody = Mathf.Clamp(aCurrBody - 1, 0, desc.body.Length - 1);
        }
        EditorGUILayout.LabelField("" + (bodyID + 1), GUILayout.Width(12f));
        if (GUILayout.Button(">", GUILayout.Width(20f)))
        {
            aCurrBody = Mathf.Clamp(aCurrBody + 1, 0, desc.body.Length - 1);
        }
        bodyID = Mathf.Clamp(aCurrBody, 0, desc.body.Length - 1);
        int length = Math.Max(1, EditorGUILayout.IntField(desc.body.Length, GUILayout.Width(32f)));

        EditorGUILayout.LabelField("Total", GUILayout.Width(40f));
        if (length != desc.body.Length)
        {
            Array.Resize <Rect>(ref desc.body, length);
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();
        desc.body[bodyID] = AtlasField(aMat, desc.body[bodyID], aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
        if (desc.leftCap.width == 0 && desc.leftCap.height == 0)
        {
            if (EditorGUILayout.Toggle("Left Cap", false))
            {
                desc.leftCap = new Rect(0, 0, 30, 30);
            }
        }
        else
        {
            if (EditorGUILayout.Toggle("Left Cap", true))
            {
                desc.leftCap = AtlasField(aMat, desc.leftCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
            }
            else
            {
                desc.leftCap = new Rect(0, 0, 0, 0);
            }
        }
        if (desc.innerLeftCap.width == 0 && desc.innerLeftCap.height == 0)
        {
            if (EditorGUILayout.Toggle("Inner Left Cap", false))
            {
                desc.innerLeftCap = new Rect(0, 0, 30, 30);
            }
        }
        else
        {
            if (EditorGUILayout.Toggle("Inner Left Cap", true))
            {
                desc.innerLeftCap = AtlasField(aMat, desc.innerLeftCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
            }
            else
            {
                desc.innerLeftCap = new Rect(0, 0, 0, 0);
            }
        }

        if (desc.rightCap.width == 0 && desc.rightCap.height == 0)
        {
            if (EditorGUILayout.Toggle("Right Cap", false))
            {
                desc.rightCap = new Rect(0, 0, 30, 30);
            }
        }
        else
        {
            if (EditorGUILayout.Toggle("Right Cap", true))
            {
                desc.rightCap = AtlasField(aMat, desc.rightCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
            }
            else
            {
                desc.rightCap = new Rect(0, 0, 0, 0);
            }
        }
        if (desc.innerRightCap.width == 0 && desc.innerRightCap.height == 0)
        {
            if (EditorGUILayout.Toggle("Inner Right Cap", false))
            {
                desc.innerRightCap = new Rect(0, 0, 30, 30);
            }
        }
        else
        {
            if (EditorGUILayout.Toggle("Inner Right Cap", true))
            {
                desc.innerRightCap = AtlasField(aMat, desc.innerRightCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture);
            }
            else
            {
                desc.innerRightCap = new Rect(0, 0, 0, 0);
            }
        }
    }
    public static void ShowPreviewDirection(Ferr2DT_TerrainMaterial aMat, Ferr2DT_TerrainDirection aDir, Rect aBounds, bool aSimpleUVs, bool aEditable)
    {
        Ferr2DT_SegmentDescription desc = aMat.GetDescriptor(aDir);

        if (!aMat.Has(aDir))
        {
            return;
        }

        if (!aEditable)
        {
            for (int i = 0; i < desc.body.Length; i++)
            {
                Ferr.EditorTools.DrawRect(aMat.ToScreen(desc.body[i]), aBounds);
            }
            Ferr.EditorTools.DrawRect(aMat.ToScreen(desc.leftCap), aBounds);
            Ferr.EditorTools.DrawRect(aMat.ToScreen(desc.rightCap), aBounds);
            Ferr.EditorTools.DrawRect(aMat.ToScreen(desc.innerLeftCap), aBounds);
            Ferr.EditorTools.DrawRect(aMat.ToScreen(desc.innerRightCap), aBounds);
        }
        else if (aSimpleUVs)
        {
            float   height    = MaxHeight(desc);
            float   capWidth  = Mathf.Max(desc.leftCap.width, desc.rightCap.width);
            float   bodyWidth = desc.body[0].width;
            int     bodyCount = desc.body.Length;
            float   texWidth  = aMat.edgeMaterial.mainTexture != null ? aMat.edgeMaterial.mainTexture.width  : 1;
            float   texHeight = aMat.edgeMaterial.mainTexture != null ? aMat.edgeMaterial.mainTexture.height : 1;
            Vector2 pos       = new Vector2(desc.leftCap.x, desc.leftCap.y);
            if (desc.leftCap.width == 0 && desc.leftCap.height == 0)
            {
                pos = new Vector2(desc.body[0].x, desc.body[0].y);
            }

            Rect bounds = new Rect(pos.x, pos.y, capWidth * 2 + bodyWidth * bodyCount, height);
            bounds = aMat.ToNative(Ferr.EditorTools.UVRegionRect(aMat.ToPixels(bounds), aBounds));
            bounds = ClampRect(bounds, (Texture2D)aMat.edgeMaterial.mainTexture);

            Ferr.EditorTools.DrawVLine(new Vector2((pos.x + capWidth) * texWidth + aBounds.x, (pos.y * texHeight) + 2), height * texHeight);
            for (int i = 1; i <= desc.body.Length; i++)
            {
                Ferr.EditorTools.DrawVLine(new Vector2((pos.x + capWidth + bodyWidth * i) * texWidth + aBounds.x, (pos.y * texHeight) + 2), height * texHeight);
            }

            height    = bounds.height;
            bodyWidth = (bounds.width - capWidth * 2) / bodyCount;
            pos.x     = bounds.x;
            pos.y     = bounds.y;

            float currX = pos.x;
            desc.leftCap.x      = currX;
            desc.leftCap.y      = pos.y;
            desc.leftCap.width  = capWidth;
            desc.leftCap.height = capWidth == 0 ? 0 : height;
            currX += capWidth;

            for (int i = 0; i < desc.body.Length; i++)
            {
                desc.body[i].x      = currX;
                desc.body[i].y      = pos.y;
                desc.body[i].width  = bodyWidth;
                desc.body[i].height = height;
                currX += bodyWidth;
            }

            desc.rightCap.x      = currX;
            desc.rightCap.y      = pos.y;
            desc.rightCap.width  = capWidth;
            desc.rightCap.height = capWidth == 0 ? 0 : height;
        }
        else
        {
            for (int i = 0; i < desc.body.Length; i++)
            {
                desc.body[i] = ClampRect(aMat.ToNative(Ferr.EditorTools.UVRegionRect(aMat.ToPixels(desc.body[i]), aBounds)), (Texture2D)aMat.edgeMaterial.mainTexture);
            }
            if (desc.leftCap.width != 0 && desc.leftCap.height != 0)
            {
                desc.leftCap = ClampRect(aMat.ToNative(Ferr.EditorTools.UVRegionRect(aMat.ToPixels(desc.leftCap), aBounds)), (Texture2D)aMat.edgeMaterial.mainTexture);
            }
            if (desc.rightCap.width != 0 && desc.rightCap.height != 0)
            {
                desc.rightCap = ClampRect(aMat.ToNative(Ferr.EditorTools.UVRegionRect(aMat.ToPixels(desc.rightCap), aBounds)), (Texture2D)aMat.edgeMaterial.mainTexture);
            }

            if (desc.innerLeftCap.width != 0 && desc.innerLeftCap.height != 0)
            {
                desc.innerLeftCap = ClampRect(aMat.ToNative(Ferr.EditorTools.UVRegionRect(aMat.ToPixels(desc.innerLeftCap), aBounds)), (Texture2D)aMat.edgeMaterial.mainTexture);
            }
            if (desc.innerRightCap.width != 0 && desc.innerRightCap.height != 0)
            {
                desc.innerRightCap = ClampRect(aMat.ToNative(Ferr.EditorTools.UVRegionRect(aMat.ToPixels(desc.innerRightCap), aBounds)), (Texture2D)aMat.edgeMaterial.mainTexture);
            }
        }
    }