File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments