public static void EditUVsSimple(IFerr2DTMaterial 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); }
public static Rect AtlasField(IFerr2DTMaterial 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); }
public static void ShowPreviewDirection(IFerr2DTMaterial 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); } } }
public static void EditUVsComplex(IFerr2DTMaterial aMat, Ferr2DT_SegmentDescription desc, float aWidth, ref int aCurrBody) { int currBody = aCurrBody; int bodyID = 0; Ferr.EditorTools.Box(2, () => { if (desc.leftCap.width == 0 && desc.leftCap.height == 0 && desc.rightCap.width == 0 && desc.rightCap.height == 0) { desc.EditorLeftCapOffset = EditorGUILayout.Slider("Left Offset", desc.EditorLeftCapOffset, -1, 1); desc.EditorRightCapOffset = EditorGUILayout.Slider("Right Offset", desc.EditorRightCapOffset, -1, 1); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Body", GUILayout.Width(40f)); 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 + 1), 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) { Rect[] bodies = desc.body; Array.Resize <Rect>(ref bodies, length); desc.body = bodies; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); desc.body[bodyID] = AtlasField(aMat, desc.body[bodyID], aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture); float pixelWidth = aMat.edgeMaterial == null || aMat.edgeMaterial.mainTexture == null ? 1f / 256 : 1f / aMat.edgeMaterial.mainTexture.width; if (desc.body[bodyID].width < pixelWidth) { desc.body[bodyID].width = pixelWidth; } }); aCurrBody = currBody; EditorGUILayout.Space(); Ferr.EditorTools.Box(2, () => { if (desc.leftCap.width == 0 && desc.leftCap.height == 0) { if (EditorGUILayout.Toggle("Left Cap", false)) { desc.leftCap = aMat.ToNative(new Rect(0, 0, 50, 50)); } } else { if (EditorGUILayout.Toggle("Left Cap", true)) { desc.EditorLeftCapOffset = EditorGUILayout.Slider("Cap Offset", desc.EditorLeftCapOffset, -1, 1); desc.leftCap = AtlasField(aMat, desc.leftCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture); } else { desc.leftCap = new Rect(0, 0, 0, 0); } } EditorGUI.indentLevel += 1; desc.EditorLeftCapType = Convert.ToInt32(EditorGUILayout.EnumPopup("Collider Type", (Ferr2D_CapColliderType)desc.EditorLeftCapType)); desc.EditorLeftCapColliderSize = EditorGUILayout.Slider("Collider Size", desc.EditorLeftCapColliderSize, -1, 2); EditorGUI.indentLevel -= 1; }); EditorGUILayout.Space(); Ferr.EditorTools.Box(2, () => { if (desc.innerLeftCap.width == 0 && desc.innerLeftCap.height == 0) { if (EditorGUILayout.Toggle("Inner Left Cap", false)) { desc.innerLeftCap = aMat.ToNative(new Rect(0, 0, 50, 50)); } } else { if (EditorGUILayout.Toggle("Inner Left Cap", true)) { Ferr.EditorTools.Box(2, () => { desc.EditorInnerLeftCapOffset = EditorGUILayout.Slider("Cap Offset", desc.EditorInnerLeftCapOffset, -1, 1); desc.innerLeftCap = AtlasField(aMat, desc.innerLeftCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture); }); } else { desc.innerLeftCap = new Rect(0, 0, 0, 0); } } EditorGUI.indentLevel += 1; desc.EditorInnerLeftCapType = Convert.ToInt32(EditorGUILayout.EnumPopup("Collider Type", (Ferr2D_CapColliderType)desc.EditorInnerLeftCapType)); desc.EditorInnerLeftCapColliderSize = EditorGUILayout.Slider("Collider Size", desc.EditorInnerLeftCapColliderSize, -1, 2); EditorGUI.indentLevel -= 1; }); EditorGUILayout.Space(); Ferr.EditorTools.Box(2, () => { if (desc.rightCap.width == 0 && desc.rightCap.height == 0) { if (EditorGUILayout.Toggle("Right Cap", false)) { desc.rightCap = aMat.ToNative(new Rect(0, 0, 50, 50)); } } else { if (EditorGUILayout.Toggle("Right Cap", true)) { Ferr.EditorTools.Box(2, () => { desc.EditorRightCapOffset = EditorGUILayout.Slider("Cap Offset", desc.EditorRightCapOffset, -1, 1); desc.rightCap = AtlasField(aMat, desc.rightCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture); }); } else { desc.rightCap = new Rect(0, 0, 0, 0); } } EditorGUI.indentLevel += 1; desc.EditorRightCapType = Convert.ToInt32(EditorGUILayout.EnumPopup("Collider Type", (Ferr2D_CapColliderType)desc.EditorRightCapType)); desc.EditorRightCapColliderSize = EditorGUILayout.Slider("Collider Size", desc.EditorRightCapColliderSize, -1, 2); EditorGUI.indentLevel -= 1; }); EditorGUILayout.Space(); Ferr.EditorTools.Box(2, () => { if (desc.innerRightCap.width == 0 && desc.innerRightCap.height == 0) { if (EditorGUILayout.Toggle("Inner Right Cap", false)) { desc.innerRightCap = aMat.ToNative(new Rect(0, 0, 50, 50)); } } else { if (EditorGUILayout.Toggle("Inner Right Cap", true)) { Ferr.EditorTools.Box(2, () => { desc.EditorInnerRightCapOffset = EditorGUILayout.Slider("Cap Offset", desc.EditorInnerRightCapOffset, -1, 1); desc.innerRightCap = AtlasField(aMat, desc.innerRightCap, aMat.edgeMaterial != null ? aMat.edgeMaterial.mainTexture : EditorGUIUtility.whiteTexture); }); } else { desc.innerRightCap = new Rect(0, 0, 0, 0); } } EditorGUI.indentLevel += 1; desc.EditorInnerRightCapType = Convert.ToInt32(EditorGUILayout.EnumPopup("Collider Type", (Ferr2D_CapColliderType)desc.EditorInnerRightCapType)); desc.EditorInnerRightCapColliderSize = EditorGUILayout.Slider("Collider Size", desc.EditorInnerRightCapColliderSize, -1, 2); EditorGUI.indentLevel -= 1; }); }
public static void EditUVsSimple(IFerr2DTMaterial 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); } Ferr.EditorTools.Box(2, () => { pos = EditorGUILayout.Vector2Field("Position", pos); height = EditorGUILayout.FloatField("Height", height); capWidth = EditorGUILayout.FloatField("Cap Width", capWidth); desc.SingleColliderCapOffset = EditorGUILayout.Slider("Cap Offset", desc.SingleColliderCapOffset, -1, 1); bodyWidth = Mathf.Max(1, EditorGUILayout.FloatField("Body Width", bodyWidth)); bodyCount = Mathf.Max(1, EditorGUILayout.IntField("Body slices", bodyCount)); EditorGUILayout.Space(); EditorGUILayout.LabelField("Colliders", EditorStyles.boldLabel); desc.SingleColliderCapType = (Ferr2D_CapColliderType)EditorGUILayout.EnumPopup("Collider Type", desc.SingleColliderCapType); desc.SingleColliderCapSize = EditorGUILayout.Slider("Collider Size", desc.SingleColliderCapSize, -1, 2); if (bodyCount != desc.body.Length) { Rect[] bodies = desc.body; Array.Resize <Rect>(ref bodies, bodyCount); desc.body = bodies; } float currX = pos.x; Rect leftCap = desc.leftCap; leftCap.x = currX; leftCap.y = pos.y; leftCap.width = capWidth; leftCap.height = capWidth == 0 ? 0 : height; desc.leftCap = aMat.ToNative(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; } Rect rightCap = desc.rightCap; rightCap.x = currX; rightCap.y = pos.y; rightCap.width = capWidth; rightCap.height = capWidth == 0 ? 0 : height; desc.rightCap = aMat.ToNative(rightCap); }); }