private void DrawNode(Node node)
        {
            NodeViewData viewData = this.GetViewDataForNode(node);
            Rect         nodeRect = this.GetNodeRect(node);

            if (this.IsNodeSelected(node))
            {
                Rect     expandedNodeRect  = RectUtil.Expand(nodeRect, kNodeSelectedLineWeight);
                GUIStyle nodeSelectedStyle = GUIStyleUtil.StyleWithTexture(GUI.skin.box, kNodeSelectedTexture);
                GUI.Box(expandedNodeRect, "", nodeSelectedStyle);
            }

            Rect nodeShadowRect = nodeRect;

            nodeShadowRect.position = nodeShadowRect.position + new Vector2(kNodeShadowOffset, kNodeShadowOffset);
            GUI.Box(nodeShadowRect, "", (GUIStyle)"NodeShadow");

            GUIStyle nodeStyle = (GUIStyle)"Node";

            if (this.TargetGraph.IsStartingNode(node))
            {
                nodeStyle = (GUIStyle)"StartingNode";
            }

            GUI.Box(nodeRect, viewData.name, nodeStyle);
        }
Beispiel #2
0
        private NodeViewData MakeNewNodeViewData(Node node)
        {
            NodeViewData newViewData = new NodeViewData(node);

            this._nodeViewDatas.Add(newViewData);
            this.ClearCached();
            return(newViewData);
        }
Beispiel #3
0
        private void MakeNode(object mousePosition)
        {
            Node         newNode      = this.TargetGraph.MakeNode();
            NodeViewData nodeViewData = this.TargetGraphViewData.LoadViewDataForNode(newNode);

            nodeViewData.position = this._grid.SnapToGrid((Vector2)mousePosition + this._panner.Position);

            this.SetTargetDirty();
        }
        private void DrawTransitionFromNodeToNode(TransitionViewData transitionViewData, Node node, Node targetNode, TransitionViewStyle style)
        {
            NodeViewData nodeViewData       = this.GetViewDataForNode(node);
            NodeViewData targetNodeViewData = this.GetViewDataForNode(targetNode);

            this.DrawTransitionFromPointToPoint(transitionViewData,
                                                nodeViewData.position + this._panner.Position,
                                                targetNodeViewData.position + this._panner.Position,
                                                style);
        }
Beispiel #5
0
        // PRAGMA MARK - Public Interface
        public NodeViewData LoadViewDataForNode(Node node)
        {
            NodeViewData viewData = this.CachedNodeViewDataMapping.SafeGet(node.Id);

            if (viewData == null)
            {
                viewData = this.MakeNewNodeViewData(node);
            }
            return(viewData);
        }
        private void DrawTransitionsForNode(Node node)
        {
            NodeViewData           nodeViewData    = this.GetViewDataForNode(node);
            IList <NodeTransition> nodeTransitions = this.TargetGraph.GetOutgoingTransitionsForNode(node);

            foreach (NodeTransition nodeTransition in nodeTransitions)
            {
                TransitionViewStyle transitionStyle    = this.GetStyleForTransition(node, nodeTransition);
                TransitionViewData  transitionViewData = nodeViewData.GetViewDataForTransition(nodeTransition.transition);

                IList <Node> targetNodes = nodeTransition.targets.Select(targetId => this.TargetGraph.LoadNodeById(targetId)).ToList();
                foreach (Node targetNode in targetNodes)
                {
                    this.DrawTransitionFromNodeToNode(transitionViewData, node, targetNode, transitionStyle);
                }
            }
        }
Beispiel #7
0
            private void DrawEditingTransitionToMousePoint()
            {
                if (this._node == null)
                {
                    Debug.LogError("DrawEditingTransitionToMousePoint - node is null!");
                    return;
                }

                Vector2            mousePosition      = Event.current.mousePosition;
                NodeViewData       nodeViewData       = this.Context.GetViewDataForNode(this._node);
                TransitionViewData transitionViewData = nodeViewData.GetViewDataForTransition(this._nodeTransition.transition);

                this.Context.DrawTransitionFromPointToPoint(transitionViewData,
                                                            nodeViewData.position + this.Context._panner.Position,
                                                            mousePosition,
                                                            TransitionViewStyle.HIGHLIGHTED);
            }
        private void DrawInspectorWindow()
        {
            Node selectedNode = this.GetSelectedNode();

            if (selectedNode == null)
            {
                return;
            }

            NodeViewData selectedNodeViewData = this.GetViewDataForNode(selectedNode);

            float heightSoFar = 0.0f;

            Rect inspectorHideButtonRect = new Rect(kInspectorWindowPosition, new Vector2(kInspectorWindowWidth, kInspectorHideButtonHeight));

            EditorGUIUtility.AddCursorRect(inspectorHideButtonRect, MouseCursor.Link);
            if (GUI.Button(inspectorHideButtonRect, ""))
            {
                this._inspectorCollapsed = !this._inspectorCollapsed;
            }
            heightSoFar += kInspectorHideButtonHeight;

            if (!this._inspectorCollapsed)
            {
                Vector2 inspectorRectPosition = kInspectorWindowPosition + new Vector2(0.0f, heightSoFar);

                Rect inspectorRect = new Rect(inspectorRectPosition, new Vector2(kInspectorWindowWidth, kInspectorViewHeight));
                GUILayout.BeginArea(inspectorRect, "", (GUIStyle)"InspectorWindow");
                // Scroll View
                this._inspectorScrollPos = EditorGUILayout.BeginScrollView(this._inspectorScrollPos, GUILayout.Height(kInspectorViewHeight));
                this.DrawNodeInspector(selectedNode, selectedNodeViewData);
                EditorGUILayout.EndScrollView();
                // End Scroll View
                GUILayout.EndArea();
            }
        }
        private void DrawNodeInspector(Node node, NodeViewData nodeViewData)
        {
            nodeViewData.name = EditorGUILayout.TextField(nodeViewData.name);

            // Node Delegate Button + Fields
            EditorGUILayout.BeginVertical((GUIStyle)"InspectorBigBox");
            EditorGUILayout.LabelField("Node Delegates:");
            foreach (INodeDelegate nodeDelegate in node.GetNodeDelegates())
            {
                Type nodeDelegateType = nodeDelegate.GetType();
                EditorGUILayout.BeginVertical((GUIStyle)"InspectorBox");
                EditorGUILayout.LabelField(nodeDelegateType.Name, EditorStyles.boldLabel);

                FieldInfo[] fields = TypeUtil.GetInspectorFields(nodeDelegateType);
                foreach (FieldInfo field in fields)
                {
                    EditorGUILayoutUtil.DynamicField(field, nodeDelegate);
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("", (GUIStyle)"AddButton", GUILayout.Width(20.0f), GUILayout.Height(20.0f)))
            {
                GenericMenu nodeDelegateMenu = new GenericMenu();
                foreach (Type nodeDelegateType in INodeDelegateUtil.ImplementationTypes)
                {
                    nodeDelegateMenu.AddItem(new GUIContent(nodeDelegateType.Name), false, this.AddNodeDelegateToNode, Tuple.Create(node, nodeDelegateType));
                }
                nodeDelegateMenu.ShowAsContext();
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            // Node Transitions
            EditorGUILayout.BeginVertical((GUIStyle)"InspectorBigBox");
            EditorGUILayout.LabelField("Transitions:");
            IList <NodeTransition> nodeTransitions = this.TargetGraph.GetOutgoingTransitionsForNode(node);

            foreach (NodeTransition nodeTransition in nodeTransitions)
            {
                GUIStyle transitionStyle = this.IsNodeTransitionSelected(nodeTransition) ? (GUIStyle)"SelectedInspectorBox" : (GUIStyle)"InspectorBox";
                Rect     transitionRect  = EditorGUILayout.BeginVertical(transitionStyle, GUILayout.MinHeight(30.0f));
                string   targetText      = "";
                targetText += (nodeTransition.targets.Length > 1) ? "Targets: " : "Target: ";
                targetText += StringUtil.Join(", ", nodeTransition.targets.Select(id => this.GetViewDataForNode(this.TargetGraph.LoadNodeById(id)).name));

                EditorGUILayout.LabelField(targetText, GUILayout.Height(30.0f));

                Rect editButtonRect = new Rect(new Vector2(transitionRect.x + transitionRect.width - 25.0f,
                                                           transitionRect.y + 5.0f),
                                               new Vector2(20.0f, 20.0f));
                if (GUI.Button(editButtonRect, "", (GUIStyle)"EditButton"))
                {
                    this.StartEditingNodeTransition(node, nodeTransition);
                }

                Rect removeButtonRect = new Rect(new Vector2(transitionRect.x + transitionRect.width - 50.0f,
                                                             transitionRect.y + 5.0f),
                                                 new Vector2(20.0f, 20.0f));
                if (GUI.Button(removeButtonRect, "", (GUIStyle)"RemoveButton"))
                {
                    this.AddPendingNodeTransitionRemoval(node, nodeTransition);
                }

                EditorGUILayout.LabelField("Conditions: ");
                Transition transition = nodeTransition.transition;
                transition.WaitForManualExit = EditorGUILayout.Toggle("WaitForManualExit: ", transition.WaitForManualExit);
                foreach (ITransitionCondition transitionCondition in transition.GetTransitionConditions())
                {
                    EditorGUILayout.BeginVertical(transitionStyle);
                    Type transitionConditionType = transitionCondition.GetType();
                    EditorGUILayout.LabelField(transitionConditionType.Name, EditorStyles.boldLabel);

                    FieldInfo[] fields = TypeUtil.GetInspectorFields(transitionConditionType);
                    foreach (FieldInfo field in fields)
                    {
                        EditorGUILayoutUtil.DynamicField(field, transitionCondition);
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.Space();
                }

                if (GUILayout.Button("", (GUIStyle)"AddButton", GUILayout.Width(20.0f), GUILayout.Height(20.0f)))
                {
                    GenericMenu nodeDelegateMenu = new GenericMenu();
                    foreach (Type transitionConditionType in TypeUtil.GetImplementationTypes(typeof(ITransitionCondition)))
                    {
                        nodeDelegateMenu.AddItem(new GUIContent(transitionConditionType.Name), false, this.AddTransitionCondition, Tuple.Create(nodeTransition, transitionConditionType));
                    }
                    nodeDelegateMenu.ShowAsContext();
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("", (GUIStyle)"AddButton", GUILayout.Width(20.0f), GUILayout.Height(20.0f)))
            {
                this.MakeTransition(node);
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();
        }
        private Rect GetNodeRect(Node node)
        {
            NodeViewData viewData = this.GetViewDataForNode(node);

            return(RectUtil.MakeRect(viewData.position + this._panner.Position, kNodeSize, kNodePivot));
        }
Beispiel #11
0
        public NodeDragger(NodeViewData nodeViewData, IGrid grid)
        {
            this._nodeViewData = nodeViewData;

            this._grid = grid;
        }