diff --git a/Assets/SplineMesh/Scripts/Editor/SplineEditor.cs b/Assets/SplineMesh/Scripts/Editor/SplineEditor.cs index 3e80321..e82025c 100644 --- a/Assets/SplineMesh/Scripts/Editor/SplineEditor.cs +++ b/Assets/SplineMesh/Scripts/Editor/SplineEditor.cs @@ -49,11 +49,19 @@ private void OnEnable() { t.Apply(); upButtonStyle = new GUIStyle(); upButtonStyle.normal.background = t; - selection = null; + selection = getSelectedNode(); Undo.undoRedoPerformed -= spline.RefreshCurves; Undo.undoRedoPerformed += spline.RefreshCurves; + + // why? - see: https://answers.unity.com/questions/1418211/onscenegui-not-called.html + SceneView.onSceneGUIDelegate += this.OnSceneGUIDel; } + + private void OnDisable() + { + SceneView.onSceneGUIDelegate -= this.OnSceneGUIDel; + } SplineNode AddClonedNode(SplineNode node) { int index = spline.nodes.IndexOf(node); @@ -65,6 +73,24 @@ SplineNode AddClonedNode(SplineNode node) { } return res; } + + protected SplineNode getSelectedNode() + { + if (spline != null && selection == null && Selection.activeGameObject == spline.gameObject) + { + if (selection == null && spline.nodes.Count > 0) + { + return spline.nodes[0]; + } + } + + return null; + } + + void OnSceneGUIDel(SceneView sceneView) + { + OnSceneGUI(); + } void OnSceneGUI() { Event e = Event.current; @@ -210,7 +236,7 @@ public override void OnInspectorGUI() { EditorGUILayout.HelpBox("Hold Alt and drag a node to create a new one.", MessageType.Info); if(spline.nodes.IndexOf(selection) < 0) { - selection = null; + selection = getSelectedNode(); } // add button