21 [AddComponentMenu(
"UI/Extensions/Primitives/Cut Corners")]
26 [Header(
"Corners to cut")]
28 private bool m_cutUL =
true;
36 [Tooltip(
"Up-Down colors become Left-Right colors")]
38 private bool m_makeColumns;
40 [Header(
"Color the cut bars differently")]
42 private bool m_useColorUp;
44 private Color32 m_colorUp;
46 private bool m_useColorDown;
48 private Color32 m_colorDown;
52 get {
return m_cutUL; }
53 set { m_cutUL = value; SetAllDirty(); }
58 get {
return m_cutUR; }
59 set { m_cutUR = value; SetAllDirty(); }
64 get {
return m_cutLL; }
65 set { m_cutLL = value; SetAllDirty(); }
70 get {
return m_cutLR; }
71 set { m_cutLR = value; SetAllDirty(); }
76 get {
return m_makeColumns; }
77 set { m_makeColumns = value; SetAllDirty(); }
82 get {
return m_useColorUp; }
83 set { m_useColorUp = value; }
88 get {
return m_colorUp; }
89 set { m_colorUp = value; }
94 get {
return m_useColorDown; }
95 set { m_useColorDown = value; }
100 get {
return m_colorDown; }
101 set { m_colorDown = value; }
106 var rect = rectTransform.rect;
109 Color32 color32 = color;
110 bool up = m_cutUL | m_cutUR;
111 bool down = m_cutLL | m_cutLR;
112 bool left = m_cutLL | m_cutUL;
113 bool right = m_cutLR | m_cutUR;
114 bool any = up | down;
131 Vector2 ul, ur, ll, lr;
135 ul =
new Vector2(rect.xMin, m_cutUL ? rectNew.yMax : rect.yMax);
136 ur =
new Vector2(rect.xMax, m_cutUR ? rectNew.yMax : rect.yMax);
137 ll =
new Vector2(rect.xMin, m_cutLL ? rectNew.yMin : rect.yMin);
138 lr =
new Vector2(rect.xMax, m_cutLR ? rectNew.yMin : rect.yMin);
143 new Vector2(rectNew.xMin, rect.yMax),
144 new Vector2(rectNew.xMin, rect.yMin),
145 rect, m_useColorUp ? m_colorUp : color32, vh);
149 new Vector2(rectNew.xMax, rect.yMin),
150 new Vector2(rectNew.xMax, rect.yMax),
151 rect, m_useColorDown ? m_colorDown : color32, vh);
155 ul =
new Vector2(m_cutUL ? rectNew.xMin : rect.xMin, rect.yMax);
156 ur =
new Vector2(m_cutUR ? rectNew.xMax : rect.xMax, rect.yMax);
157 ll =
new Vector2(m_cutLL ? rectNew.xMin : rect.xMin, rect.yMin);
158 lr =
new Vector2(m_cutLR ? rectNew.xMax : rect.xMax, rect.yMin);
162 new Vector2(rect.xMin, rectNew.yMin),
163 new Vector2(rect.xMax, rectNew.yMin),
164 rect, m_useColorDown ? m_colorDown : color32, vh);
168 new Vector2(rect.xMax, rectNew.yMax),
169 new Vector2(rect.xMin, rectNew.yMax),
170 rect, m_useColorUp ? m_colorUp : color32, vh);
175 AddSquare(
new Rect(rectNew.xMin, rect.yMin, rectNew.width, rect.height), rect, color32, vh);
177 AddSquare(
new Rect(rect.xMin, rectNew.yMin, rect.width, rectNew.height), rect, color32, vh);
182 private static void AddSquare(Rect rect, Rect rectUV, Color32 color32, VertexHelper vh) {
183 int v0 = AddVert(rect.xMin, rect.yMin, rectUV, color32, vh);
184 int v1 = AddVert(rect.xMin, rect.yMax, rectUV, color32, vh);
185 int v2 = AddVert(rect.xMax, rect.yMax, rectUV, color32, vh);
186 int v3 = AddVert(rect.xMax, rect.yMin, rectUV, color32, vh);
188 vh.AddTriangle(v0, v1, v2);
189 vh.AddTriangle(v2, v3, v0);
192 private static void AddSquare(Vector2 a, Vector2 b, Vector2 c, Vector2 d, Rect rectUV, Color32 color32, VertexHelper vh) {
193 int v0 = AddVert(a.x, a.y, rectUV, color32, vh);
194 int v1 = AddVert(b.x, b.y, rectUV, color32, vh);
195 int v2 = AddVert(c.x, c.y, rectUV, color32, vh);
196 int v3 = AddVert(d.x, d.y, rectUV, color32, vh);
198 vh.AddTriangle(v0, v1, v2);
199 vh.AddTriangle(v2, v3, v0);
210 private static int AddVert(
float x,
float y, Rect area, Color32 color32, VertexHelper vh) {
211 var uv =
new Vector2(
212 Mathf.InverseLerp(area.xMin, area.xMax, x),
213 Mathf.InverseLerp(area.yMin, area.yMax, y)
215 vh.AddVert(
new Vector3(x, y), color32, uv);
216 return vh.currentVertCount - 1;
override void OnPopulateMesh(VertexHelper vh)
Credit Erdener Gonenc - @PixelEnvision.