public static void OpenWindow() { editor = GetWindow <BehaviourEditorWindow>(); editor.minSize = new Vector2(600, 300); editor.titleContent = new GUIContent("Behaviour Editor"); editor._curWindowSize = editor.position.size; editor._menuRect = editor.GetMenuRect(); nodeCanvas = new NodeCanvas(editor.GetCanvasRect()); nodeInspector = new NodeInspector(editor.GetInspectorRect(), nodeCanvas); Selection.selectionChanged += TryLoadSelectedAsset; NodeFactory.FetchNodes(); NodePanelFactory.FetchCustomPanels(); CustomFieldDrawerManager.FetchCustomFieldDrawers(); // tries to load the selected asset if it is a behaviour tree when the window is open // and also when the assembly is reloaded TryLoadSelectedAsset(); }
void DrawInspector() { if (selectedNode == null) { return; } // Debug.Log (selectedNode); // if (Event.current.type != EventType.Repaint || Event.current.type != EventType.Layout || Event.current.type != ) // return; GUIStyle nodeTypeStyle = new GUIStyle(EditorStyles.label); nodeTypeStyle.alignment = TextAnchor.UpperCenter; nodeTypeStyle.fontStyle = FontStyle.Bold; EditorGUILayout.LabelField(selectedNode.Id, nodeTypeStyle); DrawId(); if (_fields != null) { for (int i = 0; i < _fields.Count; i++) { EditorGUILayout.Separator(); EditorGUILayout.BeginVertical(); FieldInfo field = _fields[i]; string fieldName = field.Name; NodeField nodeField = _fieldToAttributeDict[field]; if (nodeField.GetType() == typeof(NodeField)) { CustomFieldDrawer customFieldDrawer = CustomFieldDrawerManager.GetCustomFieldDrawer(field.FieldType); if (customFieldDrawer == null) { // draw normally if you can...? if (field.FieldType == typeof(bool)) { field.SetValue(selectedNode, EditorGUILayout.ToggleLeft(nodeField.label, (bool)field.GetValue(selectedNode))); } } else { customFieldDrawer.targetField = field; customFieldDrawer.targetNode = selectedNode; customFieldDrawer.Draw(); } } else if (nodeField.GetType() == typeof(VariableGetter)) { VariableGetter getterAttr = (VariableGetter)nodeField; if (getterAttr.overrideField == null) { // no override just draw normal DrawVariableDropdown(field, getterAttr); } else { string fieldValue = (string)field.GetValue(selectedNode); if (fieldValue == null) { // draw field normally } } } else if (nodeField.GetType() == typeof(VariableSetter)) { VariableSetter setterAttr = (VariableSetter)nodeField; DrawVariableDropdown(field, setterAttr); } EditorGUILayout.EndVertical(); } // EditorGUILayout.BeginVertical(EditorStyles.textArea); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Comments"); GUIStyle commentStyle = new GUIStyle(EditorStyles.textArea); commentStyle.fixedHeight = 100; EditorGUILayout.TextArea("", commentStyle); } if (Application.isPlaying) { EditorGUILayout.TextArea(selectedNode.StateMessage, GUILayout.Height(60)); } if (redrawInspector) { GUI.FocusControl(null); redrawInspector = false; } }