TreePrototype BlueprintToTreePrototype(TreeBlueprint blueprint) { TreePrototype prototype = new TreePrototype(); prototype.prefab = blueprint.prefab; prototype.bendFactor = blueprint.bendFactor; return(prototype); }
void DeleteBlueprint() { if (blueprintToLoad != null) { AssetDatabase.DeleteAsset("Assets/BeeHIVE/Trees/" + blueprintToLoad.name + "_tree.asset"); AssetDatabase.DeleteAsset("Assets/BeeHIVE/Blueprints/" + blueprintToLoad.name + ".asset"); blueprintToLoad = null; skipNodeDrawing = true; AssetDatabase.Refresh(); NewTree(); } }
void CreateConnectionMatrix(TreeBlueprint bluePrint) { bluePrint.connectionMatrix = new bool[nodes.Count * nodes.Count]; for (int i = 0; i < nodes.Count; i++) { for (int j = 0; j < nodes.Count; j++) { if (nodes[i].children.Contains(nodes[j])) { bluePrint.connectionMatrix[i * nodes.Count + j] = true; } else { bluePrint.connectionMatrix[i * nodes.Count + j] = false; } } } }
void SaveBlueprint(string name) { string filepath = "Assets/BeeHIVE/Blueprints/" + name + ".asset"; TreeBlueprint bluePrint = ScriptableObject.CreateInstance <TreeBlueprint> (); bluePrint.sourceName = typeOptions[typeIndex]; bluePrint.nodes = new List <BlueprintNode>(); for (int i = 0; i < nodes.Count; i++) { bluePrint.nodes.Add(new BlueprintNode(nodes[i])); } CreateConnectionMatrix(bluePrint); AssetDatabase.CreateAsset(bluePrint, filepath); AssetDatabase.SaveAssets(); }
void LoadBlueprint(TreeBlueprint blueprint) { if (blueprint == null) { return; } typeIndex = 0; for (int i = 0; i < typeOptions.Count; i++) { if (typeOptions[i] == blueprint.sourceName) { typeIndex = i; break; } } for (int i = 0; i < blueprint.nodes.Count; i++) { CreateNewNode(blueprint.nodes[i]); } for (int i = 0; i < nodes.Count; i++) { for (int j = 0; j < nodes.Count; j++) { if (blueprint.connectionMatrix[i * nodes.Count + j] == true) { nodes[i].AddChild(nodes[j]); } } } btName = blueprint.name; UpdateMethodOptions(); }
TreePrototype BlueprintToTreePrototype(TreeBlueprint blueprint) { TreePrototype prototype = new TreePrototype(); prototype.prefab = blueprint.prefab; prototype.bendFactor = blueprint.bendFactor; return prototype; }
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(); }