private string GetNodeStyle(BHiveNodeConfig n, int index) { string focused = ""; if (focusedNode != null) { focused = n.Id == focusedNode.Id ? " on" : ""; } int color = 2; if (n.isCondition) { color = 5; } if (Application.isPlaying) { if (currentController.configController.nodeStack.Contains( currentController.configController.AllNodes[n.Id])) { color = 3; } } if (n.IsBroken) { color = 6; } return("flow node " + color + focused); }
public void AddNodeType(object userData) { var myData = userData as BHiveNode.BHiveNodeType; var conf = new BHiveNodeConfig(); conf.Id = currentController.configuration.GetNextNodeId(); conf.isDefault = currentController.configuration.Nodes.Count == 0; conf.Position = actionMousePosition - dragOffset; conf.SetType(myData.type); conf.isCondition = (typeof(BHiveCondition).IsAssignableFrom(myData.type)); conf.CustomDescription = conf.GetDescription(); currentController.configuration.Nodes.Add(conf); Save(); }
public void AddChildNode(BHiveNodeConfig node, bool isNegative) { if (focusedNode.isCondition) { if (isNegative) { focusedNode.negativeChild = node.Id; } else { focusedNode.positiveChild = node.Id; } } isSeekingChild = false; }
void DrawNodeWindow(int id) { var nodeConfig = currentController.configuration.Nodes[id]; if (Event.current.isMouse && Event.current.button == 1) { focusedNode = nodeConfig; OpenContextMenu(nodeConfig); Event.current.Use(); } else if (Event.current.type == EventType.mouseDown && Event.current.button == 0) { if (isSeekingChild) { AddChildNode(nodeConfig, isSeekingNegativeChild); } focusedNode = nodeConfig; } GUI.DragWindow(); GUILayout.BeginArea(new Rect(0, 20, kWindowWidth, kWindowHeight - 20)); if (nodeConfig.IsBroken) { GUILayout.Label(nodeConfig.SerializedTypeName); } GUILayout.Label(nodeConfig.CustomDescription, "WordWrappedMiniLabel"); GUILayout.EndArea(); if (nodeConfig.isDefault) { GUI.Box(new Rect(kWindowWidth - 16, 5, 12, 12), "", "U2D.dragDot"); } if (nodeConfig.isCondition) { GUI.color = green; GUI.Box(new Rect(0, kWindowHeight - 12, 30, 12), "", "flow node hex 0"); GUI.color = red; GUI.Box(new Rect(kWindowWidth - 30, kWindowHeight - 12, 30, 12), "", "flow node hex 0"); GUI.color = Color.white; } }
void OpenContextMenu(BHiveNodeConfig nodeConfig) { GenericMenu gm = new GenericMenu(); if (nodeConfig.isCondition) { gm.AddItem(new GUIContent("Add Positive"), false, AddPositiveChildNode, nodeConfig); gm.AddItem(new GUIContent("Add Negative"), false, AddNegativeChildNode, nodeConfig); gm.AddItem(new GUIContent("Set Default"), false, SetDefaultNode, nodeConfig); } gm.AddItem(new GUIContent("Clear Parent"), false, ClearParent, nodeConfig); gm.AddSeparator(""); gm.AddItem(new GUIContent("Delete Node"), false, DeleteNode, nodeConfig); gm.ShowAsContext(); }
void FocusDefaultNode() { if (currentController == null) { return; } BHiveNodeConfig defaultNode = currentController.configuration.Nodes.Find(x => x.isDefault); if (defaultNode == null && currentController.configuration.Nodes.Count > 0) { defaultNode = currentController.configuration.Nodes[0]; } if (defaultNode == null) { return; } dragOffset = -defaultNode.Position + new Vector2(position.size.x / 2, 25); }
/* * private void PromoteNode(object userData) * { * var nodeConfig = userData as BHiveNodeConfig; * foreach (var n in currentController.configuration.Nodes) * { * if (n.Children.Contains(nodeConfig.Id)) * { * n.SortChild(nodeConfig, -1); * break; * } * } * } * * private void DegradeNode(object userData) * { * var nodeConfig = userData as BHiveNodeConfig; * foreach (var n in currentController.configuration.Nodes) * { * if(n.Children.Contains(nodeConfig.Id)) * { * n.SortChild(nodeConfig, +1); * break; * } * } * } */ private void DeleteNode(object userData) { var nodeConfig = userData as BHiveNodeConfig; foreach (var n in currentController.configuration.Nodes) { if (n.isCondition) { if (n.negativeChild == nodeConfig.Id) { n.negativeChild = 0; } if (n.positiveChild == nodeConfig.Id) { n.positiveChild = 0; } } } currentController.configuration.Nodes.Remove(nodeConfig); focusedNode = null; }
void OnGUI() { if (currentController == null) { var go = Selection.activeGameObject; if (go != null) { currentController = go.GetComponent <BHiveRuntimeController>(); Initialize(); } else { return; } } DrawBackground(); if (currentController == null) { return; } DrawCurves(); BeginWindows(); DrawWindows(); EndWindows(); DrawMenu(); DrawContext(); DragView(); DrawInspector(); if (Event.current.keyCode == KeyCode.Escape) { isSeekingChild = false; } if (Event.current.keyCode == KeyCode.F) { FocusDefaultNode(); Repaint(); } if (Event.current.type == EventType.mouseDown && Event.current.button == 0) { focusedNode = null; Repaint(); } if (Event.current.type == EventType.mouseUp) { Save(); Repaint(); } if (isSeekingChild || Application.isPlaying) { Repaint(); } }