Skip to content

Commit 5d8929f

Browse files
Update GizmoDrawer.cs
Added a method to override the gizmoColour property.
1 parent 9a5f086 commit 5d8929f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Editor/GizmoDrawer.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ public class GizmoDrawer : MonoBehaviour
6666
[HideInInspector] public Material mat;
6767
#endregion
6868

69+
#region Public Methods
70+
public void SetColour(string hexCode) => SetColour(HexToColor(hexCode));
71+
72+
public void SetColour(Color colour)
73+
{
74+
gizmoColor = colour;
75+
}
76+
#endregion
77+
6978
private void OnDrawGizmosSelected()
7079
{
7180
if (drawOnSelectOnly)
@@ -77,6 +86,25 @@ private void OnDrawGizmos()
7786
if (!drawOnSelectOnly)
7887
GizmoTool.DrawGizmo(this);
7988
}
89+
90+
private static Color HexToColor(string hex)
91+
{
92+
if (hex.StartsWith("#"))
93+
{
94+
hex = hex.Substring(1);
95+
}
96+
97+
if (hex.Length != 6)
98+
{
99+
Debug.LogError("Invalid hex color code");
100+
}
101+
102+
byte r = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
103+
byte g = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
104+
byte b = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
105+
106+
return new Color(r / 255f, g / 255f, b / 255f);
107+
}
80108
}
81109
}
82110
#endif

0 commit comments

Comments
 (0)