public NodeWindow(NodeEditorObject nodeObj) { var ohBehave = EditorWindow.GetWindow <OhBehaveEditorWindow>(); treeBlueprint = ohBehave.treeBlueprint; nodeObject = nodeObj; nodeName = nodeObj.displayName; switch (nodeObj.nodeType) { case NodeType.Leaf: nodeStyle = OhBehaveEditorWindow.LeafNodeStyle; bgColor = NodeStyle.LeafColor; labelStyle = NodeStyle.LeafLabelStyle; break; case NodeType.Selector: nodeStyle = OhBehaveEditorWindow.SelectorNodeStyle; bgColor = NodeStyle.SelectorColor; labelStyle = NodeStyle.SelectorLabelStyle; outPoint = new ConnectionPoint(this, ConnectionPointType.Out, ConnectionControls.OnClickOutPoint); break; case NodeType.Sequence: nodeStyle = OhBehaveEditorWindow.SequenceNodeStyle; bgColor = NodeStyle.SequenceColor; labelStyle = NodeStyle.SequencerLabelStyle; outPoint = new ConnectionPoint(this, ConnectionPointType.Out, ConnectionControls.OnClickOutPoint); break; case NodeType.Inverter: nodeStyle = OhBehaveEditorWindow.InverterNodeStyle; bgColor = NodeStyle.InverterColor; labelStyle = NodeStyle.InverterLabelStyle; outPoint = new ConnectionPoint(this, ConnectionPointType.Out, ConnectionControls.OnClickOutPoint); break; } currentStyle = nodeStyle.defaultStyle; if (nodeObject.index != OhBehaveTreeBlueprint.ROOT_INDEX) { inPoint = new ConnectionPoint(this, ConnectionPointType.In, ConnectionControls.OnClickInPoint); } NodeEditorObject prntObj = nodeObject.Parent; if (prntObj != null) { parent = (IParentNodeWindow)prntObj.GetWindow(); if (parent == null) { refreshConnection = true; } } else { bgColor = NodeStyle.RootColor; } }
public ConnectionPoint(NodeWindow node, ConnectionPointType type, Action <ConnectionPoint> OnClickConnectionPoint) { var ohBehave = EditorWindow.GetWindow <OhBehaveEditorWindow>(); blueprint = ohBehave.treeBlueprint; this.nodeWindow = node; this.type = type; if (type == ConnectionPointType.In) { unConnectedstyle = OhBehaveEditorWindow.InPointStyle; } else { unConnectedstyle = OhBehaveEditorWindow.OutPointStyle; } this.OnClickConnectionPoint = OnClickConnectionPoint; connectedStyle = new GUIStyle(); connectedStyle.normal.background = unConnectedstyle.hover.background; rect = new Rect(0, 0, unConnectedstyle.normal.background.width, unConnectedstyle.normal.background.height); }
public bool Open(OhBehaveAI ohBehaveAI) { currentAIBehaviour = ohBehaveAI; treeBlueprint = GetBlueprintFor(ohBehaveAI); if (treeBlueprint == null) { Repaint(); return(false); } treeBlueprint.ohBehaveAI = ohBehaveAI; treeBlueprint.ConstructNodes(); if (zoomer != null) { zoomer.Reset(treeBlueprint.zoomerSettings); } window.Show(); Repaint(); return(true); }
void Update() { if (Selection.activeGameObject != null) { OhBehaveAI ohBehaveSM = Selection.activeGameObject.GetComponent <OhBehaveAI>(); if (ohBehaveSM != null && ohBehaveSM != currentAIBehaviour) { // switch to the currently selected gameobjects behavior tree Open(ohBehaveSM); return; } } if (openFileChooser) { openFileChooser = false; string path = EditorUtility.OpenFilePanelWithFilters( "Choose new OhBehave file", "Assets/StreamingAssets/" + userNodeFolder, new string[] { "OhBehaveTree Json file", "OhJson" }); if (!string.IsNullOrEmpty(path)) { string relativePath = path.Replace(Application.streamingAssetsPath, ""); chooseNewJsonFor.jsonFilepath = relativePath; Open(chooseNewJsonFor); } chooseNewJsonFor = null; } if (treeBlueprint == null) { if (Selection.activeObject != null) { OhBehaveTreeBlueprint testIfTree = Selection.activeObject as OhBehaveTreeBlueprint; if (testIfTree != null) { treeBlueprint = testIfTree; Repaint(); } } } else { treeBlueprint.PendingDeletes(); Repaint(); } if (openSaveFileChooser) { if (!AssetDatabase.IsValidFolder("Assets/StreamingAssets/" + userNodeFolder)) { if (!AssetDatabase.IsValidFolder("Assets/StreamingAssets/")) { AssetDatabase.CreateFolder("Assets", "StreamingAssets"); } if (!AssetDatabase.IsValidFolder("Assets/StreamingAssets/" + DefaultNodeFolder)) { AssetDatabase.CreateFolder("Assets/StreamingAssets", DefaultNodeFolder); } userNodeFolder = DefaultNodeFolder; EditorPrefs.SetString(UserNodeFolderKey, userNodeFolder); } string nodename = "NewOhBehaveTree"; int num = AssetDatabase.FindAssets(nodename, new string[] { "Assets/StreamingAssets/" + userNodeFolder }).Length; if (num != 0) { nodename += " (" + num + ")"; } var path = EditorUtility.SaveFilePanelInProject( "Create New Json Behavior State Machine", nodename, "OhJson", "Where to save json file?", "Assets/StreamingAssets/" + userNodeFolder); if (path.Length != 0) { // check if user is using a folder that isn't the default if (Path.GetFileName(Path.GetDirectoryName(path)) != userNodeFolder) { userNodeFolder = Path.GetFileName(Path.GetDirectoryName(path)); EditorPrefs.SetString(UserNodeFolderKey, userNodeFolder); } var machineBlueprint = CreateInstance <OhBehaveTreeBlueprint>(); machineBlueprint.Initialize(aiRequestingNewBlueprint, path); Open(aiRequestingNewBlueprint); } aiRequestingNewBlueprint = null; openSaveFileChooser = false; } }