public void BuildNode(BH_Node node, Vector2 position) { myNode = node; if (myNode is BH_Selector) { myTexture = BTGuiLoader.GetTexture(E_TextureNames.selectorIcon); windowTitle = "Selector"; } else if (myNode is BH_Sequence) { myTexture = BTGuiLoader.GetTexture(E_TextureNames.sequenceIcon); windowTitle = "Sequence"; } else if (myNode is BH_Inverter) { myTexture = BTGuiLoader.GetTexture(E_TextureNames.inverterIcon); windowTitle = "Inverter"; } else if (myNode is BH_Succeeder) { myTexture = BTGuiLoader.GetTexture(E_TextureNames.succederIcon); windowTitle = "Succeder"; } else if (myNode is BH_Repeater) { myTexture = BTGuiLoader.GetTexture(E_TextureNames.repeaterIcon); windowTitle = "Repeater"; } else if (myNode is BH_RepeatUntilFail) { myTexture = BTGuiLoader.GetTexture(E_TextureNames.repeatTilFailIcon); windowTitle = "Until fail"; } else if (myNode is BH_Leaf) { myTexture = BTGuiLoader.GetTexture(E_TextureNames.leafIcon); windowTitle = "Leaf"; windowSize = new Vector2(100, 56); UpdateMethodIndex(); } windowRect = new Rect(position.x, position.y, windowSize.x, windowSize.y); }
void OnValidate() { BTGuiLoader.initGUILoader(); }
static void ShowEditor() { EditorWindow.GetWindow <NodeEditor>(); BTGuiLoader.initGUILoader(); }
void DrawSideMenu() { GUI.backgroundColor = sideMenuColor; GUILayout.BeginVertical(GUI.skin.FindStyle("Box"), GUILayout.Width(sideMenuSize.x), GUILayout.ExpandHeight(true)); GUI.backgroundColor = Color.white; GUILayout.Box(BTGuiLoader.textures[(int)E_TextureNames.logo], GUIStyle.none); EditorGUILayout.BeginVertical(GUI.skin.FindStyle("Box"), GUILayout.ExpandWidth(true)); //------------------------- GUILayout.Label("BEHAVIOR TREE"); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Source:"); EditorGUI.BeginChangeCheck(); typeIndex = EditorGUILayout.Popup(typeIndex, typeOptions.ToArray()); if (EditorGUI.EndChangeCheck()) { UpdateMethodOptions(); UpdateNodesMethodsIndexes(); } EditorGUILayout.Separator(); EditorGUILayout.LabelField("Name:"); EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); btName = GUILayout.TextField(btName); if (GUILayout.Button("Save", GUILayout.ExpandWidth(false))) { if (string.Equals(btName, "")) { EditorUtility.DisplayDialog("ERROR", "You can not save without a name!", "OK"); } else { SaveBlueprint(btName); BuildTree(btName + "_tree"); } } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("New tree")) { NewTree(); skipNodeDrawing = true; } EditorGUILayout.EndVertical(); //---------------------------------------------------- EditorGUILayout.BeginVertical(GUI.skin.FindStyle("Box"), GUILayout.ExpandWidth(true), GUILayout.MinHeight(70)); //------------------------- GUILayout.Label("NODE INSPECTOR"); EditorGUILayout.Separator(); if (selectedNode != null && nodes.Count > 0) { if (selectedNode.parent != null) { EditorGUILayout.LabelField("Parent: " + selectedNode.parent.windowTitle); } if (selectedNode.myNode is BH_Composite) { EditorGUILayout.LabelField("Amount of Childs: " + selectedNode.amountOfChildren.ToString()); } else if (selectedNode.myNode is BH_Decorator) { if (selectedNode.amountOfChildren == 0) { EditorGUILayout.LabelField("Connected Child: FALSE"); } else { EditorGUILayout.LabelField("Connected Child: TRUE"); } } } EditorGUILayout.EndVertical(); //---------------------------------------------------- EditorGUILayout.BeginVertical(GUI.skin.FindStyle("Box"), GUILayout.ExpandWidth(true)); //------------------------- GUILayout.Label("BLUEPRINTS"); EditorGUILayout.Separator(); blueprintToLoad = (EditorGUILayout.ObjectField("", blueprintToLoad, typeof(TreeBlueprint), false)) as TreeBlueprint; EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Load")) { NewTree(); LoadBlueprint(blueprintToLoad); } if (GUILayout.Button("Insert")) { //LoadBlueprint(blueprintToLoad); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Delete")) { if (EditorUtility.DisplayDialog("Warning", "Are you sure that you want to delete this?", "Yes", "No")) { DeleteBlueprint(); } } EditorGUILayout.EndVertical(); //----------------------------------------------------- EditorGUILayout.BeginVertical(GUI.skin.FindStyle("Box"), GUILayout.ExpandWidth(true)); //------------------------- GUILayout.Label("NODES"); if (GUILayout.Button(new GUIContent(BTGuiLoader.GetTexture(E_TextureNames.leafIcon), "Actions. Represent Methods."), GUILayout.Width(120), GUILayout.Height(32))) { CreateNewNode(new BH_Leaf(), new Vector2(UnityEngine.Random.Range(0, 300), UnityEngine.Random.Range(0, 300))); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent(BTGuiLoader.GetTexture(E_TextureNames.selectorIcon), "Return a success if any of its children succeed\nand not process any further children."), GUILayout.Width(50), GUILayout.Height(50))) { CreateNewNode(new BH_Selector(), new Vector2(UnityEngine.Random.Range(0, 300), UnityEngine.Random.Range(0, 300))); } if (GUILayout.Button(new GUIContent(BTGuiLoader.GetTexture(E_TextureNames.sequenceIcon), "Visit each child in order. If any child fails it\nwill immediately return failure to the parent."), GUILayout.Width(50), GUILayout.Height(50))) { CreateNewNode(new BH_Sequence(), new Vector2(UnityEngine.Random.Range(0, 300), UnityEngine.Random.Range(0, 300))); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent(BTGuiLoader.GetTexture(E_TextureNames.inverterIcon), "Invert the result of their child node."), GUILayout.Width(50), GUILayout.Height(50))) { CreateNewNode(new BH_Inverter(), new Vector2(UnityEngine.Random.Range(0, 300), UnityEngine.Random.Range(0, 300))); } if (GUILayout.Button(new GUIContent(BTGuiLoader.GetTexture(E_TextureNames.succederIcon), "Always return success to the parent."), GUILayout.Width(50), GUILayout.Height(50))) { CreateNewNode(new BH_Succeeder(), new Vector2(UnityEngine.Random.Range(0, 300), UnityEngine.Random.Range(0, 300))); } if (GUILayout.Button(new GUIContent(BTGuiLoader.GetTexture(E_TextureNames.repeaterIcon), "Reprocess its child node each time its child\nreturns a result."), GUILayout.Width(50), GUILayout.Height(50))) { CreateNewNode(new BH_Repeater(), new Vector2(UnityEngine.Random.Range(0, 300), UnityEngine.Random.Range(0, 300))); } if (GUILayout.Button(new GUIContent(BTGuiLoader.GetTexture(E_TextureNames.repeatTilFailIcon), "Reprocess their child until the child returns\n a failure, than it will return success to its parent."), GUILayout.Width(50), GUILayout.Height(50))) { CreateNewNode(new BH_RepeatUntilFail(), new Vector2(UnityEngine.Random.Range(0, 300), UnityEngine.Random.Range(0, 300))); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //----------------------------------------------------- GUILayout.EndVertical(); }