Visualizing Vector3 in Scene?

Currently, editing a Vector3 requires me to manually adjust the x, y, and z values in the inspector. I need an option to be able to visualize and edit Vector3s like I do with the 3 draggable arrows used to edit transform positions.

I need this option for multiple Vector3s in many different classes. I already use PropertyDrawers extensively but I can’t figure out how to do this with PropertyDrawers. Is there an elegant solution for visualizing and editing Vector3s in the scene?

This will require a combination of using Handles and OnSceneGUI

If those bits of information aint enough, lemme know and ill elaborate. But they are the main API you’ll need to understand to get the functionality working.

2 Likes

I’m not sure how to use handles in a property drawer.

Handles are a scene view thing…

ie Handles.ArrowCap () draws an arrow.

This is how you would visualize your vector… if you want to make those handles clickable…

if(Handles.Button(blah, blah, Handles.ArrowCap))
{
  //do stuff - like capture mouse pos, update current vector values... Handling dragging could be fun :p

}

Do you know how to setup your scene view delegate? Heres a link if not sure…

Hopefully that clarifies it for you a little…

1 Like

I’m looking for a way to do something like this:

[VisualizeVector3]
Vector3 spawnPosition; //position handle shows for this field in the scene

It’s impractical for me to write a custom editor for every class that needs to visualize a Vector3.

you wont need a custom editor for every class.

one code file will do it all. How you manage whether or not the editor script is running/showing handles is up to you.

I want to use an attribute to signal that a Vector3 should be visualized.

yeah im not sure such a thing exists. If it does, lettuce know :wink:

Wrote a handler wrapper for use in OnGUI: https://github.com/SnpM/SafeHandles.