Skip to content

Commit 34cb974

Browse files
Add Type - Ray
Add support for ray gizmos.
1 parent 441cf25 commit 34cb974

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# V 1.2.0
2+
- Added support for Ray gizmo type.
3+
14
# v1.1.2
25
- Hid origin transform option for Gui Texture.
36

Editor/GizmoDrawer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public class GizmoDrawer : MonoBehaviour
6464
/// An optional material to apply the texture.
6565
/// </summary>
6666
[HideInInspector] public Material mat;
67+
68+
// Ray
69+
[HideInInspector] public Vector3 rayDirection;
6770
#endregion
6871

6972
#region Public Methods

Editor/GizmoDrawerInspector.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public class GizmoDrawerInspector : Editor
3333
serProp_mat,
3434
serProp_useTransformVals,
3535
serProp_useMeshOnFilter,
36-
serProp_useOriginTransformValues;
36+
serProp_useOriginTransformValues,
37+
serProp_vec3RayDirection;
3738
#endregion
3839

3940
GizmoDrawer gizmoDrawer;
@@ -72,6 +73,8 @@ private void OnEnable()
7273
serProp_useTransformVals = serializedObject.FindProperty("useAttachedTransformValues");
7374
serProp_useMeshOnFilter = serializedObject.FindProperty("useMeshOnFilter");
7475
serProp_useOriginTransformValues = serializedObject.FindProperty("useOriginTransformValues");
76+
77+
serProp_vec3RayDirection = serializedObject.FindProperty("rayDirection");
7578
}
7679

7780
public override void OnInspectorGUI()
@@ -126,22 +129,22 @@ static void DrawInspector(GizmoType type, GizmoDrawerInspector editor, out bool
126129

127130
showColour = true;
128131
EditorGUILayout.PropertyField(editor.serProp_floatRadius);
129-
break;
132+
break;
130133

131134
case GizmoType.Cube or GizmoType.WireCube:
132135
enableUseOriginTransform = true;
133136

134137
showColour = true;
135138
EditorGUILayout.PropertyField(editor.serProp_vec3Scale);
136-
break;
139+
break;
137140

138141
case GizmoType.Icon:
139142
enableUseOriginTransform = true;
140143
showColour = true;
141144

142145
EditorGUILayout.PropertyField(editor.serProp_filePathString);
143146
EditorGUILayout.PropertyField(editor.serProp_allowScalingBool);
144-
break;
147+
break;
145148

146149
case GizmoType.Mesh or GizmoType.WireMesh:
147150
enableUseOriginTransform = true;
@@ -171,7 +174,7 @@ static void DrawInspector(GizmoType type, GizmoDrawerInspector editor, out bool
171174

172175
EditorGUILayout.PropertyField(editor.serProp_meshRot);
173176
EditorGUILayout.PropertyField(editor.serProp_vec3Scale);
174-
break;
177+
break;
175178

176179
case GizmoType.Line:
177180
enableUseOriginTransform = true;
@@ -184,7 +187,7 @@ static void DrawInspector(GizmoType type, GizmoDrawerInspector editor, out bool
184187
{
185188
EditorGUILayout.PropertyField(editor.serProp_targetPos);
186189
}
187-
break;
190+
break;
188191

189192
case GizmoType.LineList or GizmoType.LineStrip:
190193
enableUseOriginTransform = false;
@@ -203,7 +206,7 @@ static void DrawInspector(GizmoType type, GizmoDrawerInspector editor, out bool
203206
{
204207
EditorGUILayout.PropertyField(editor.serProp_linePointArray, true);
205208
}
206-
break;
209+
break;
207210

208211
case GizmoType.GuiTexture:
209212
enableUseOriginTransform = false;
@@ -213,7 +216,13 @@ static void DrawInspector(GizmoType type, GizmoDrawerInspector editor, out bool
213216
EditorGUILayout.PropertyField(editor.serProp_screenRect);
214217
EditorGUILayout.Space();
215218
EditorGUILayout.PropertyField(editor.serProp_mat);
216-
break;
219+
break;
220+
221+
case GizmoType.Ray:
222+
enableUseOriginTransform = true;
223+
showColour = true;
224+
EditorGUILayout.PropertyField(editor.serProp_vec3RayDirection);
225+
break;
217226
}
218227
}
219228

Editor/GizmoTool.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public enum GizmoType
2222

2323
Icon,
2424
GuiTexture,
25+
26+
Ray,
2527
}
2628

2729
internal static class GizmoTool
@@ -88,6 +90,10 @@ internal static void DrawGizmo(GizmoDrawer drawer)
8890
if (drawer.texture != null)
8991
Gizmos.DrawGuiTexture(drawer.screenRect, drawer.texture, drawer.mat);
9092
break;
93+
94+
case GizmoType.Ray:
95+
Gizmos.DrawRay(GetOriginPosition(drawer), drawer.rayDirection, drawer.gizmoColor);
96+
break;
9197
}
9298
}
9399

Editor/Gizmos.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ internal static void DrawGuiTexture(Rect screenRect, Texture texture, Material m
8484
{
8585
UnityEngine.Gizmos.DrawGUITexture(screenRect, texture, mat);
8686
}
87+
88+
internal static void DrawRay(Vector3 originPos, Vector3 direction, Color color)
89+
{
90+
UnityEngine.Gizmos.color = color;
91+
UnityEngine.Gizmos.DrawRay(originPos, direction);
92+
}
8793
}
8894
}
8995
#endif

0 commit comments

Comments
 (0)