Programming interactive editor viewport elements (ie: the arrows to translate the transform)

Hey guys, how would I go about creating objects who can instantiate editor objects that I can interact with in the viewport?

I initially thought I could go down the route of using mono behaviours that execute in editor, who would instantiate objects that I could interact with in the editor… but this doesn’t appear to be what the built in editor tools for unity seem to do - the scale tool, translate tool and rotate tool all seem to create objects in the scene that the user can click on and move around. How can I do this?

All you need to do is creating a custom inspector for your MonoBehaviour script that implements OnSceneGUI. There you would use the Handles to display a position handle for example.

Here a very simple example:

// C#
public class TranslationAxis : MonoBehaviour
{
    public Vector3 direction = new Vector3(1,1,1);
}

Just create an inspector for this class:

// C#
[CustomEditor(typeof(TranslationAxis))]
public class TranslationAxisEditor : Editor
{
    private TranslationAxis m_Target = null;
    void OnEnable()
    {
        m_Target = (TranslationAxis)target;
    }
    
    void OnSceneGUI()
    {
        m_Target.transform.position = Handles.Slider(m_Target.transform.position, m_Target.direction);
    }
}

When you attach the TranslationAxis script to a gameobject it will have an additional arrow that points along the direction vector you specify in the direction variable.

The object can be moved along this arrow. When editing the direction vector the arrow should change it’s direction.