Hi
Here’s the issue:
I have a FreeMoveHandle in the Scene
I have a Vector3Field in the Inspector.
The trick is getting one to drive the other and not override each other.
When I update the scene handle, the inspector field updates with the values of the handle’s position.
When I change the field values, the position of the handle changes accordingly.
I have this MOSTLY working with the exception of one terrible detail.
I cannot enter new values in the Vector3Field.
I can drag the field values and the handle will update along with the values.
I can move the handle and the fields will update.
But I cannot enter the numeric values in the Vector3Field
If I manually enter a value and press ENTER… the value will not change.
What am I missing here?
And… Am I doing this correctly?
using UnityEditor;
using UnityEngine;
public class TestWindow : EditorWindow
{
private Vector3 _inspectorVector3;
private Vector3 _sceneVector3;
private Vector3 _interimVector3;
[MenuItem("Tools/Test")]
public static void OpenWindow()
{
var window = GetWindow<TestWindow>();
window.titleContent = new GUIContent("Test");
}
protected void OnEnable()
{
SceneView.onSceneGUIDelegate += OnSceneGUI;
}
protected void OnDisable()
{
SceneView.onSceneGUIDelegate -= OnSceneGUI;
}
protected void OnGUI()
{
_inspectorVector3 = EditorGUILayout.Vector3Field("Position", _inspectorVector3);
if (GUILayout.Button("Reset"))
{
_inspectorVector3 = Vector3.zero;
}
}
protected void OnInspectorUpdate()
{
if (SceneView.lastActiveSceneView != null)
{
SceneView.lastActiveSceneView.Repaint();
}
_interimVector3 = _inspectorVector3;
if (_sceneVector3 != _inspectorVector3)
{
_sceneVector3 = _interimVector3;
}
Repaint();
}
private void OnSceneGUI(SceneView sceneview)
{
_sceneVector3 = Handles.FreeMoveHandle(_sceneVector3, Quaternion.identity, 0.2f, Vector3.one, Handles.CubeCap);
_interimVector3 = _sceneVector3;
if (_inspectorVector3 != _sceneVector3)
{
_inspectorVector3 = _interimVector3;
}
}
}