diff --git a/Scripts/Primitives/DiamondGraph.cs b/Scripts/Primitives/DiamondGraph.cs index e2fe86c..f242a23 100644 --- a/Scripts/Primitives/DiamondGraph.cs +++ b/Scripts/Primitives/DiamondGraph.cs @@ -8,26 +8,56 @@ namespace UnityEngine.UI.Extensions [AddComponentMenu("UI/Extensions/Primitives/Diamond Graph")] public class DiamondGraph : UIPrimitiveBase { - public float a = 1; - public float b = 1; - public float c = 1; - public float d = 1; + [SerializeField] + private float m_a = 1; + [SerializeField] + private float m_b = 1; + [SerializeField] + private float m_c = 1; + [SerializeField] + private float m_d = 1; + + + public float A + { + get { return m_a; } + set { m_a = value; } + } + + public float B + { + get { return m_b; } + set { m_b = value; } + } + + public float C + { + get { return m_c; } + set { m_c = value; } + } + + public float D + { + get { return m_d; } + set { m_d = value; } + } + protected override void OnPopulateMesh(VertexHelper vh) { vh.Clear(); float wHalf = rectTransform.rect.width / 2; //float hHalf = rectTransform.rect.height / 2; - a = Math.Min(1, Math.Max(0, a)); - b = Math.Min(1, Math.Max(0, b)); - c = Math.Min(1, Math.Max(0, c)); - d = Math.Min(1, Math.Max(0, d)); + m_a = Math.Min(1, Math.Max(0, m_a)); + m_b = Math.Min(1, Math.Max(0, m_b)); + m_c = Math.Min(1, Math.Max(0, m_c)); + m_d = Math.Min(1, Math.Max(0, m_d)); Color32 color32 = color; - vh.AddVert(new Vector3(-wHalf * a, 0), color32, new Vector2(0f, 0f)); - vh.AddVert(new Vector3(0, wHalf * b), color32, new Vector2(0f, 1f)); - vh.AddVert(new Vector3(wHalf * c, 0), color32, new Vector2(1f, 1f)); - vh.AddVert(new Vector3(0, -wHalf * d), color32, new Vector2(1f, 0f)); + vh.AddVert(new Vector3(-wHalf * m_a, 0), color32, new Vector2(0f, 0f)); + vh.AddVert(new Vector3(0, wHalf * m_b), color32, new Vector2(0f, 1f)); + vh.AddVert(new Vector3(wHalf * m_c, 0), color32, new Vector2(1f, 1f)); + vh.AddVert(new Vector3(0, -wHalf * m_d), color32, new Vector2(1f, 0f)); vh.AddTriangle(0, 1, 2); vh.AddTriangle(2, 3, 0); diff --git a/Scripts/Primitives/UICircle.cs b/Scripts/Primitives/UICircle.cs index 8b65156..5321f58 100644 --- a/Scripts/Primitives/UICircle.cs +++ b/Scripts/Primitives/UICircle.cs @@ -9,26 +9,56 @@ namespace UnityEngine.UI.Extensions { [Tooltip("The circular fill percentage of the primitive, affected by FixedToSegments")] [Range(0, 100)] - public int fillPercent = 100; + [SerializeField] + private int m_fillPercent = 100; [Tooltip("Should the primitive fill draw by segments or absolute percentage")] public bool FixedToSegments = false; [Tooltip("Draw the primitive filled or as a line")] - public bool fill = true; + [SerializeField] + private bool m_fill = true; [Tooltip("If not filled, the thickness of the primitive line")] - public float thickness = 5; + [SerializeField] + private float m_thickness = 5; [Tooltip("The number of segments to draw the primitive, more segments = smoother primitive")] [Range(0, 360)] - public int segments = 360; + [SerializeField] + private int m_segments = 360; + + + public int FillPercent + { + get { return m_fillPercent; } + set { m_fillPercent = value; SetAllDirty(); } + } + + public bool Fill + { + get { return m_fill; } + set { m_fill = value; SetAllDirty(); } + } + + public float Thickness + { + get { return m_thickness; } + set { m_thickness = value; SetAllDirty(); } + } + void Update() { - this.thickness = (float)Mathf.Clamp(this.thickness, 0, rectTransform.rect.width / 2); + this.m_thickness = (float)Mathf.Clamp(this.m_thickness, 0, rectTransform.rect.width / 2); } - + + public int Segments + { + get { return m_segments; } + set { m_segments = value; SetAllDirty(); } + } + protected override void OnPopulateMesh(VertexHelper vh) { float outer = -rectTransform.pivot.x * rectTransform.rect.width; - float inner = -rectTransform.pivot.x * rectTransform.rect.width + this.thickness; + float inner = -rectTransform.pivot.x * rectTransform.rect.width + this.m_thickness; vh.Clear(); @@ -45,9 +75,9 @@ namespace UnityEngine.UI.Extensions if (FixedToSegments) { - float f = (this.fillPercent / 100f); - float degrees = 360f / segments; - int fa = (int)((segments + 1) * f); + float f = (this.m_fillPercent / 100f); + float degrees = 360f / m_segments; + int fa = (int)((m_segments + 1) * f); for (int i = 0; i < fa; i++) @@ -71,9 +101,9 @@ namespace UnityEngine.UI.Extensions float tw = rectTransform.rect.width; float th = rectTransform.rect.height; - float angleByStep = (fillPercent / 100f * (Mathf.PI * 2f)) / segments; + float angleByStep = (m_fillPercent / 100f * (Mathf.PI * 2f)) / m_segments; float currentAngle = 0f; - for (int i = 0; i < segments + 1; i++) + for (int i = 0; i < m_segments + 1; i++) { float c = Mathf.Cos(currentAngle); @@ -98,7 +128,7 @@ namespace UnityEngine.UI.Extensions pos0 = prevX; pos1 = new Vector2(outer * c, outer * s); - if (fill) + if (m_fill) { pos2 = Vector2.zero; pos3 = Vector2.zero; diff --git a/Scripts/Primitives/UICornerCut.cs b/Scripts/Primitives/UICornerCut.cs index fda0c44..c5fe498 100644 --- a/Scripts/Primitives/UICornerCut.cs +++ b/Scripts/Primitives/UICornerCut.cs @@ -23,22 +23,82 @@ namespace UnityEngine.UI.Extensions { public Vector2 cornerSize = new Vector2(16, 16); [Header("Corners to cut")] - public bool cutUL = true; - public bool cutUR; - public bool cutLL; - public bool cutLR; - + [SerializeField] + private bool m_cutUL = true; + [SerializeField] + private bool m_cutUR; + [SerializeField] + private bool m_cutLL; + [SerializeField] + private bool m_cutLR; + [Tooltip("Up-Down colors become Left-Right colors")] - public bool makeColumns = false; - + [SerializeField] + private bool m_makeColumns; + [Header("Color the cut bars differently")] - public bool useColorUp; -// [HideUnless("useColorUp")] - public Color32 colorUp = Color.blue; - - public bool useColorDown; -// [HideUnless("useColorDown")] - public Color32 colorDown = Color.green; + [SerializeField] + private bool m_useColorUp; + [SerializeField] + private Color32 m_colorUp; + [SerializeField] + private bool m_useColorDown; + [SerializeField] + private Color32 m_colorDown; + + public bool CutUL + { + get { return m_cutUL; } + set { m_cutUL = value; SetAllDirty(); } + } + + public bool CutUR + { + get { return m_cutUR; } + set { m_cutUR = value; SetAllDirty(); } + } + + public bool CutLL + { + get { return m_cutLL; } + set { m_cutLL = value; SetAllDirty(); } + } + + public bool CutLR + { + get { return m_cutLR; } + set { m_cutLR = value; SetAllDirty(); } + } + + public bool MakeColumns + { + get { return m_makeColumns; } + set { m_makeColumns = value; SetAllDirty(); } + } + + public bool UseColorUp + { + get { return m_useColorUp; } + set { m_useColorUp = value; } + } + + public Color32 ColorUp + { + get { return m_colorUp; } + set { m_colorUp = value; } + } + + public bool UseColorDown + { + get { return m_useColorDown; } + set { m_useColorDown = value; } + } + + public Color32 ColorDown + { + get { return m_colorDown; } + set { m_colorDown = value; } + } protected override void OnPopulateMesh(VertexHelper vh) { @@ -46,10 +106,10 @@ namespace UnityEngine.UI.Extensions { var rectNew = rect; Color32 color32 = color; - bool up = cutUL | cutUR; - bool down = cutLL | cutLR; - bool left = cutLL | cutUL; - bool right = cutLR | cutUR; + bool up = m_cutUL | m_cutUR; + bool down = m_cutLL | m_cutLR; + bool left = m_cutLL | m_cutUL; + bool right = m_cutLR | m_cutUR; bool any = up | down; if (any && cornerSize.sqrMagnitude > 0) @@ -69,48 +129,48 @@ namespace UnityEngine.UI.Extensions { //add two squares to the main square Vector2 ul, ur, ll, lr; - if (makeColumns) + if (m_makeColumns) { - ul = new Vector2(rect.xMin, cutUL ? rectNew.yMax : rect.yMax); - ur = new Vector2(rect.xMax, cutUR ? rectNew.yMax : rect.yMax); - ll = new Vector2(rect.xMin, cutLL ? rectNew.yMin : rect.yMin); - lr = new Vector2(rect.xMax, cutLR ? rectNew.yMin : rect.yMin); + ul = new Vector2(rect.xMin, m_cutUL ? rectNew.yMax : rect.yMax); + ur = new Vector2(rect.xMax, m_cutUR ? rectNew.yMax : rect.yMax); + ll = new Vector2(rect.xMin, m_cutLL ? rectNew.yMin : rect.yMin); + lr = new Vector2(rect.xMax, m_cutLR ? rectNew.yMin : rect.yMin); if (left) AddSquare( ll, ul, new Vector2(rectNew.xMin, rect.yMax), new Vector2(rectNew.xMin, rect.yMin), - rect, useColorUp ? colorUp : color32, vh); + rect, m_useColorUp ? m_colorUp : color32, vh); if (right) AddSquare( ur, lr, new Vector2(rectNew.xMax, rect.yMin), new Vector2(rectNew.xMax, rect.yMax), - rect, useColorDown ? colorDown : color32, vh); + rect, m_useColorDown ? m_colorDown : color32, vh); } else { - ul = new Vector2(cutUL ? rectNew.xMin : rect.xMin, rect.yMax); - ur = new Vector2(cutUR ? rectNew.xMax : rect.xMax, rect.yMax); - ll = new Vector2(cutLL ? rectNew.xMin : rect.xMin, rect.yMin); - lr = new Vector2(cutLR ? rectNew.xMax : rect.xMax, rect.yMin); + ul = new Vector2(m_cutUL ? rectNew.xMin : rect.xMin, rect.yMax); + ur = new Vector2(m_cutUR ? rectNew.xMax : rect.xMax, rect.yMax); + ll = new Vector2(m_cutLL ? rectNew.xMin : rect.xMin, rect.yMin); + lr = new Vector2(m_cutLR ? rectNew.xMax : rect.xMax, rect.yMin); if (down) AddSquare( lr, ll, new Vector2(rect.xMin, rectNew.yMin), new Vector2(rect.xMax, rectNew.yMin), - rect, useColorDown ? colorDown : color32, vh); + rect, m_useColorDown ? m_colorDown : color32, vh); if (up) AddSquare( ul, ur, new Vector2(rect.xMax, rectNew.yMax), new Vector2(rect.xMin, rectNew.yMax), - rect, useColorUp ? colorUp : color32, vh); + rect, m_useColorUp ? m_colorUp : color32, vh); } //center - if (makeColumns) + if (m_makeColumns) AddSquare(new Rect(rectNew.xMin, rect.yMin, rectNew.width, rect.height), rect, color32, vh); else AddSquare(new Rect(rect.xMin, rectNew.yMin, rect.width, rectNew.height), rect, color32, vh); diff --git a/Scripts/Primitives/UIPolygon.cs b/Scripts/Primitives/UIPolygon.cs index 2724414..7bbfaa9 100644 --- a/Scripts/Primitives/UIPolygon.cs +++ b/Scripts/Primitives/UIPolygon.cs @@ -22,18 +22,21 @@ namespace UnityEngine.UI.Extensions VerticesDistances = new float[_sides + 1]; for (int i = 0; i < _sides; i++) VerticesDistances[i] = 1; ; rotation = 0; + SetAllDirty(); } public void DrawPolygon(int _sides, float[] _VerticesDistances) { sides = _sides; VerticesDistances = _VerticesDistances; rotation = 0; + SetAllDirty(); } public void DrawPolygon(int _sides, float[] _VerticesDistances, float _rotation) { sides = _sides; VerticesDistances = _VerticesDistances; rotation = _rotation; + SetAllDirty(); } void Update() {