示例#1
0
        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);
        }
示例#2
0
        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();
        }
示例#3
0
        public void AddChildNode(BHiveNodeConfig node, bool isNegative)
        {
            if (focusedNode.isCondition)
            {
                if (isNegative)
                {
                    focusedNode.negativeChild = node.Id;
                }
                else
                {
                    focusedNode.positiveChild = node.Id;
                }
            }

            isSeekingChild = false;
        }
示例#4
0
        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;
            }
        }
示例#5
0
        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();
        }
示例#6
0
        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);
        }
示例#7
0
        /*
         * 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;
        }
示例#8
0
        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();
            }
        }