Type CreateNodeTypeDropdown(BTNode node) { int selectedType = (node != null ? Array.IndexOf <Type>(nodeTypes, node.GetType()) : Array.IndexOf <Type>(nodeTypes, typeof(BTActionBlank))); Rect rect = new Rect(0, 0, _nodeWidth - 40.0f, 20.0f); selectedType = EditorGUI.Popup(rect, selectedType, nodeTypeNames); return(nodeTypes[selectedType]); }
public virtual void Save(XmlDocument doc, XmlElement xe) { this.SaveAttribute(doc, xe); for (int i = 0; i < m_Children.Count; i++) { BTNode node = m_Children[i]; XmlElement child = doc.CreateElement(node.GetType().Name); node.Save(doc, child); xe.AppendChild(child); } }
void DrawNodeWindow(int id) { // Get EditorNode EditorData nodeData = _editorData[id]; BTNode node = nodeData.node; Type selectedType = CreateNodeTypeDropdown(node); if (selectedType != node.GetType()) { ReplaceNode(nodeData, selectedType); node = nodeData.node; } if (node is BTComposite) { BTComposite compositor = (BTComposite)node; Rect rect = new Rect(0, 20, _nodeWidth, 20); if (GUI.Button(rect, "Add Child")) { BTNode childNode = CreateNodeWithParent(typeof(BTActionBlank), compositor); compositor.children.Add(childNode); } } else if (node is BTLeaf) { if (node == null) { // Passing null to Editor.CreateEditor() causes the whole editor to hard crash, // so we throw an exception to keep that from happening. node should never be // null in this case, anyway, but if it is we don't want the whole editor to shut down. throw new NullReferenceException(); } Editor editor = Editor.CreateEditor(node); editor.OnInspectorGUI(); } // Drag window last because otherwise you can't click on things GUI.DragWindow(); }
Type CreateNodeTypeDropdown( BTNode node ) { int selectedType = ( node != null ? Array.IndexOf<Type>( nodeTypes, node.GetType() ) : Array.IndexOf<Type>( nodeTypes, typeof( BTActionBlank ) ) ); Rect rect = new Rect( 0, 0, _nodeWidth - 40.0f, 20.0f ); selectedType = EditorGUI.Popup( rect, selectedType, nodeTypeNames ); return nodeTypes[selectedType]; }