void DrawVariables() { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); GUILayout.FlexibleSpace(); if (GUILayout.Button("+", EditorStyles.toolbarButton, GUILayout.Width(20))) { _nodeCanvas.canvasState.tree.CreateVariable("NewVariable"); } EditorGUILayout.EndHorizontal(); variableScroll = EditorGUILayout.BeginScrollView(variableScroll); string[] variables = _nodeCanvas.canvasState.tree.VariableNames; for (int i = 0; i < variables.Length; i++) { EditorGUILayout.BeginHorizontal(); string newName = EditorGUILayout.TextField(variables[i], EditorStyles.textField); if (newName != variables[i] && newName != "") { RenameVariable(variables[i], newName); } if (GUI.changed) { BehaviourEditorWindow.RepaintWindow(); } if (GUILayout.Button("-", EditorStyles.miniButton)) { if (EditorUtility.DisplayDialog("Delete " + variables[i], "Are you sure you want to delete this variable?", "Yes", "No")) { _nodeCanvas.canvasState.tree.DeleteVariable(variables[i]); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); if (redrawInspector || Event.current.keyCode == KeyCode.Return) { redrawInspector = false; GUI.FocusControl(null); BehaviourEditorWindow.editor.Repaint(); } }
private static void TryLoadSelectedAsset() { UnityEngine.Object activeObject = Selection.activeObject; if (Selection.activeObject == null) { return; } if (Selection.activeObject.GetType() == typeof(BehaviourTree)) { nodeCanvas.Load((BehaviourTree)Selection.activeObject); BehaviourEditorWindow.RepaintWindow(); } else if (Selection.activeObject is GameObject) { var controller = ((GameObject)activeObject).GetComponent <BehaviourController>(); if (controller == null) { return; } if (Application.isPlaying) { nodeCanvas.LoadBehaviourController(controller); } else { var tree = controller.behaviourTree; if (tree == null) { return; } nodeCanvas.Load(tree); BehaviourEditorWindow.RepaintWindow(); } } }