private void AddEdge() { // split the path into segments based on the split angle List <List <int> > segments = new List <List <int> >(); List <Ferr2DT_TerrainDirection> dirs = new List <Ferr2DT_TerrainDirection>(); List <int> order = new List <int>(); segments = GetSegments(Path.GetVertsRaw(), out dirs); if (dirs.Count < segments.Count) { dirs.Add(directionOverrides[directionOverrides.Count - 1]); } for (int i = 0; i < segments.Count; i++) { order.Add(i); } order.Sort( new Ferr_LambdaComparer <int>( (x, y) => { Ferr2DT_TerrainDirection dirx = dirs[x] == Ferr2DT_TerrainDirection.None ? Ferr2D_Path.GetDirection(Path.pathVerts, segments[x], 0, fill == Ferr2DT_FillMode.InvertedClosed) : dirs[x]; Ferr2DT_TerrainDirection diry = dirs[y] == Ferr2DT_TerrainDirection.None ? Ferr2D_Path.GetDirection(Path.pathVerts, segments[y], 0, fill == Ferr2DT_FillMode.InvertedClosed) : dirs[y]; return(terrainMaterial.GetDescriptor(diry).zOffset.CompareTo(terrainMaterial.GetDescriptor(dirx).zOffset)); } )); // process the segments into meshes for (int i = 0; i < order.Count; i++) { AddSegment(Ferr2D_Path.IndicesToPath(Path.pathVerts, segments[order[i]]), GetScalesFromIndices(segments[order[i]]), order.Count <= 1 && Path.closed, smoothPath, dirs[order[i]]); } }
private void AddSegment(List <Vector2> aSegment, bool aClosed, Ferr2DT_TerrainDirection aDir = Ferr2DT_TerrainDirection.None) { Ferr2DT_SegmentDescription desc = GetDescription(aSegment); if (aDir != Ferr2DT_TerrainDirection.None) { desc = terrainMaterial.GetDescriptor(aDir); } int bodyID = UnityEngine.Random.Range(0, desc.body.Length); Rect body = terrainMaterial.ToUV(desc.body[bodyID]); float bodyWidth = body.width * unitsPerUV.x; int tSeed = UnityEngine.Random.seed; Vector2 capLeftSlideDir = (aSegment[1] - aSegment[0]); Vector2 capRightSlideDir = (aSegment[aSegment.Count - 2] - aSegment[aSegment.Count - 1]); capLeftSlideDir.Normalize(); capRightSlideDir.Normalize(); aSegment[0] -= capLeftSlideDir * desc.capOffset; aSegment[aSegment.Count - 1] -= capRightSlideDir * desc.capOffset; for (int i = 0; i < aSegment.Count - 1; i++) { Vector2 norm1 = Vector2.zero; Vector2 norm2 = Vector2.zero; float length = Vector2.Distance(aSegment[i + 1], aSegment[i]); int repeats = Mathf.Max(1, Mathf.FloorToInt(length / bodyWidth + stretchThreshold)); norm1 = Ferr2D_Path.GetNormal(aSegment, i, aClosed); norm2 = Ferr2D_Path.GetNormal(aSegment, i + 1, aClosed); for (int t = 1; t < repeats + 1; t++) { UnityEngine.Random.seed = (int)(transform.position.x * 100000 + transform.position.y * 10000 + i * 100 + t); body = terrainMaterial.ToUV(desc.body[UnityEngine.Random.Range(0, desc.body.Length)]); Vector2 pos1, pos2, n1, n2; pos1 = Vector2.Lerp(aSegment[i], aSegment[i + 1], (float)(t - 1) / repeats); pos2 = Vector2.Lerp(aSegment[i], aSegment[i + 1], (float)t / repeats); n1 = Vector2.Lerp(norm1, norm2, (float)(t - 1) / repeats); n2 = Vector2.Lerp(norm1, norm2, (float)t / repeats); float d = (body.height / 2) * unitsPerUV.y; float yOff = fill == Ferr2DT_FillMode.InvertedClosed ? -desc.yOffset : desc.yOffset; int v1 = dMesh.AddVertex(pos1.x + n1.x * (d + yOff), pos1.y + n1.y * (d + yOff), desc.zOffset, body.x, fill == Ferr2DT_FillMode.InvertedClosed ? body.yMax : body.y); int v2 = dMesh.AddVertex(pos1.x - n1.x * (d - yOff), pos1.y - n1.y * (d - yOff), desc.zOffset, body.x, fill == Ferr2DT_FillMode.InvertedClosed ? body.y : body.yMax); int v3 = dMesh.AddVertex(pos2.x + n2.x * (d + yOff), pos2.y + n2.y * (d + yOff), desc.zOffset, body.xMax, fill == Ferr2DT_FillMode.InvertedClosed ? body.yMax : body.y); int v4 = dMesh.AddVertex(pos2.x - n2.x * (d - yOff), pos2.y - n2.y * (d - yOff), desc.zOffset, body.xMax, fill == Ferr2DT_FillMode.InvertedClosed ? body.y : body.yMax); dMesh.AddFace(v1, v3, v4, v2); } } if (!aClosed) { AddCap(aSegment, desc, -1); AddCap(aSegment, desc, 1); } UnityEngine.Random.seed = tSeed; }
private void AddEdge() { // split the path into segments based on the split angle List <List <int> > segments = new List <List <int> >(); List <Ferr2DT_TerrainDirection> dirs = new List <Ferr2DT_TerrainDirection>(); List <int> order = new List <int>(); segments = GetSegments(Path.GetVertsRaw(), out dirs); if (dirs.Count < segments.Count) { dirs.Add(directionOverrides[directionOverrides.Count - 1]); } for (int i = 0; i < segments.Count; i++) { order.Add(i); } order.Sort( new Ferr.LambdaComparer <int>( (x, y) => { Ferr2DT_TerrainDirection dirx = dirs[x] == Ferr2DT_TerrainDirection.None ? Ferr2D_Path.GetDirection(Path.pathVerts, segments[x], 0, fill == Ferr2DT_FillMode.InvertedClosed) : dirs[x]; Ferr2DT_TerrainDirection diry = dirs[y] == Ferr2DT_TerrainDirection.None ? Ferr2D_Path.GetDirection(Path.pathVerts, segments[y], 0, fill == Ferr2DT_FillMode.InvertedClosed) : dirs[y]; return(terrainMaterial.GetDescriptor(diry).zOffset.CompareTo(terrainMaterial.GetDescriptor(dirx).zOffset)); } )); // process the segments into meshes for (int i = 0; i < order.Count; i++) { List <int> currSeg = segments[order[i]]; List <int> prevSeg = order[i] - 1 < 0 ? segments[segments.Count - 1] : segments[order[i] - 1]; List <int> nextSeg = segments[(order[i] + 1) % segments.Count]; int curr = currSeg[0]; int prev = prevSeg[prevSeg.Count - 2]; int next = currSeg[1]; Vector2 p1 = Path.pathVerts[prev] - Path.pathVerts[curr]; Vector2 p2 = Path.pathVerts[next] - Path.pathVerts[curr]; bool leftInner = Mathf.Atan2(p1.x * p2.y - p1.y * p2.x, Vector2.Dot(p1, p2)) < 0; curr = currSeg[currSeg.Count - 1]; prev = currSeg[currSeg.Count - 2]; next = nextSeg[1]; p1 = Path.pathVerts[prev] - Path.pathVerts[curr]; p2 = Path.pathVerts[next] - Path.pathVerts[curr]; bool rightInner = Mathf.Atan2(p1.x * p2.y - p1.y * p2.x, Vector2.Dot(p1, p2)) < 0; AddSegment(Ferr2D_Path.IndicesToPath(Path.pathVerts, segments[order[i]]), leftInner, rightInner, GetScalesFromIndices(segments[order[i]]), order.Count <= 1 && Path.closed, smoothPath, dirs[order[i]]); } }
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); } }
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)); } }
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); } } }
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; }
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); } }
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)); } }
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); } 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); } }