I’m implementing a custom editor for a RectTransform helper script that makes working with RectTransforms easier for designers. I have all the logic correct, but my final step is drawing additional helper gizmos that look like the blue 2d RectTransform Anchor gizmos. Does anyone know how to draw these in the scene view? There seems to be no documentation on how to do this?

I think they’re just using OnDrawGizmo and Gizmo.DrawTexture with a little blue dot, but I could be wrong.
Ah yes. Unity Gizmos and Handles. One of their most poorly documented features.
If I had to hazard a guess, it’s probably done using Editor.OnSceneGUI:
1 Like
I’m aware of OnSceneGUI, but there seems to be no documentation on Unity Gizmos/Handles for the RectTransforms/Anchors.
I opened up the UI source code (thankfully it’s open source), and the logic appears to be in SelectableEditor.cs:
private static void DrawNavigationArrow(Vector2 direction, Selectable fromObj, Selectable toObj)
{
if (fromObj == null || toObj == null)
return;
Transform fromTransform = fromObj.transform;
Transform toTransform = toObj.transform;
Vector2 sideDir = new Vector2(direction.y, -direction.x);
Vector3 fromPoint = fromTransform.TransformPoint(GetPointOnRectEdge(fromTransform as RectTransform, direction));
Vector3 toPoint = toTransform.TransformPoint(GetPointOnRectEdge(toTransform as RectTransform, -direction));
float fromSize = HandleUtility.GetHandleSize(fromPoint) * 0.05f;
float toSize = HandleUtility.GetHandleSize(toPoint) * 0.05f;
fromPoint += fromTransform.TransformDirection(sideDir) * fromSize;
toPoint += toTransform.TransformDirection(sideDir) * toSize;
float length = Vector3.Distance(fromPoint, toPoint);
Vector3 fromTangent = fromTransform.rotation * direction * length * 0.3f;
Vector3 toTangent = toTransform.rotation * -direction * length * 0.3f;
Handles.DrawBezier(fromPoint, toPoint, fromPoint + fromTangent, toPoint + toTangent, Handles.color, null, kArrowThickness);
Handles.DrawAAPolyLine(kArrowThickness, toPoint, toPoint + toTransform.rotation * (-direction - sideDir) * toSize * kArrowHeadSize);
Handles.DrawAAPolyLine(kArrowThickness, toPoint, toPoint + toTransform.rotation * (-direction + sideDir) * toSize * kArrowHeadSize);
}
I think you’re on to something with looking at the open source, but I think this logic just shows how to draw lines, and not the blue anchor handles. I’ll look more at the open source.
1 Like
I’ve looked through the UI open source, and it looks like the answer is not there. I believe the gizmos are for the RectTransform component. So, we would have to see the source for how that is done to draw the Anchor gizmos.
Has this changed in Unity 2017.1 or Unity 2017.2?