示例#1
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            FilterAttribute filter = new FilterAttribute();

            filter.HideTypes.Add(typeof(void));
            filter.MaxMethodParam           = int.MaxValue;
            filter.SetMember                = true;
            filter.Public                   = true;
            filter.Instance                 = true;
            filter.Static                   = false;
            filter.DisplayDefaultStaticType = false;
            var customItems = ItemSelector.MakeCustomItems(source.ReturnType(), filter, source.ReturnType().PrettyName());

            if (customItems != null)
            {
                ItemSelector w = ItemSelector.ShowWindow(source, MemberData.none, filter, delegate(MemberData value) {
                    value.instance = new MemberData(source, MemberData.TargetType.ValueNode);
                    NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (MultipurposeNode n) => {
                        if (n.target == null)
                        {
                            n.target = new MultipurposeMember();
                        }
                        n.target.target = value;
                        MemberDataUtility.UpdateMultipurposeMember(n.target);
                        NodeEditorUtility.AddNewNode(graph.editorData, null, null,
                                                     new Vector2(mousePositionOnCanvas.x + n.editorRect.width + 150, mousePositionOnCanvas.y),
                                                     (NodeSetValue SV) => {
                            SV.target = new MemberData(n, MemberData.TargetType.ValueNode);
                        });
                    });
                    graph.Refresh();
                }, customItems).ChangePosition(GUIUtility.GUIToScreenPoint(mousePosition));
                w.displayDefaultItem = false;
            }
        }
示例#2
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            var type = source.ReturnType();

            if (type.IsSubclassOf(typeof(System.MulticastDelegate)))
            {
                NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, delegate(EventHook n) {
                    n.target = new MemberData(source, MemberData.TargetType.ValueNode);
                });
            }
            else
            {
                NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, delegate(NodeSetValue n) {
                    n.target = new MemberData(source, MemberData.TargetType.ValueNode);
                    if (type.IsSubclassOf(typeof(System.MulticastDelegate)))
                    {
                        NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, delegate(NodeLambda node) {
                            n.value           = new MemberData(node, MemberData.TargetType.ValueNode);
                            n.setType         = SetType.Add;
                            node.delegateType = MemberData.CreateFromType(type);
                        });
                    }
                    else if (ReflectionUtils.CanCreateInstance(type))
                    {
                        n.value = new MemberData(ReflectionUtils.CreateInstance(type), MemberData.TargetType.Values);
                    }
                });
            }
            graph.Refresh();
        }
示例#3
0
        public override void OnClick(Node source, PortCommandData data, Vector2 mousePosition)
        {
            if (source.owner)
            {
                Undo.SetCurrentGroupName("Assign to anonymous function");
                Undo.RegisterFullObjectHierarchyUndo(source.owner, "Assign to anonymous function");
            }
            MemberData m = data.member;

            NodeEditorUtility.AddNewNode <NodeAnonymousFunction>(graph.editorData, null, null,
                                                                 new Vector2(source.editorRect.x - 100, source.editorRect.y),
                                                                 (node) => {
                var method = type.GetMethod("Invoke");
                if (method != null)
                {
                    node.returnType = new MemberData(method.ReturnType);
                    foreach (var p in method.GetParameters())
                    {
                        node.parameterTypes.Add(new MemberData(p.ParameterType));
                    }
                }
                m.CopyFrom(new MemberData(node, MemberData.TargetType.ValueNode));
                graph.Refresh();
            });
            graph.Refresh();
        }
示例#4
0
        public override void OnClick(Node source, PortCommandData data, Vector2 mousePosition)
        {
            if (source.owner)
            {
                Undo.SetCurrentGroupName("Promote to node");
                Undo.RegisterFullObjectHierarchyUndo(source.owner, "Promote to node");
            }
            MemberData m = data.member;

            if (data.portType != null && (!m.isAssigned || m.type == null))
            {
                if (ReflectionUtils.CanCreateInstance(data.portType))
                {
                    m.CopyFrom(new MemberData(ReflectionUtils.CreateInstance(data.portType)));
                }
                else
                {
                    m.CopyFrom(MemberData.CreateFromValue(null, data.portType));
                }
            }
            NodeEditorUtility.AddNewNode <MultipurposeNode>(graph.editorData, null, null, new Vector2(source.editorRect.x - 100, source.editorRect.y), (node) => {
                node.target.target = new MemberData(m);
                MemberDataUtility.UpdateMultipurposeMember(node.target);
                m.CopyFrom(new MemberData(node, MemberData.TargetType.ValueNode));
            });
            graph.Refresh();
        }
示例#5
0
 public override void OnClick(Node source, Vector2 mousePosition)
 {
     NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (CacheNode n) => {
         n.target = MemberData.CreateConnection(source, false);
     });
     graph.Refresh();
 }
示例#6
0
 public override void OnClick(Vector2 mousePosition)
 {
     NodeEditorUtility.AddNewNode <MacroPortNode>(graph.editorData, null, null, mousePositionOnCanvas, (node) => {
         node.gameObject.name = "flow" + Random.Range(0, 255);
         node.kind            = PortKind.FlowInput;
     });
     graph.Refresh();
 }
示例#7
0
 public override void OnClick(Node source, PortCommandData data, Vector2 mousePosition)
 {
     NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, delegate(MacroPortNode n) {
         data.member.CopyFrom(MemberData.CreateConnection(n, true));
         n.gameObject.name = data.portName;
         n.kind            = uNode.PortKind.FlowOutput;
         n.editorRect      = source.editorRect;
         n.editorRect.y   += source.editorRect.height + 100;
     });
 }
示例#8
0
 public override void OnClick(Node source, PortCommandData data, Vector2 mousePosition)
 {
     NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, delegate(MacroPortNode n) {
         data.member.CopyFrom(MemberData.CreateConnection(n, false));
         n.type            = new MemberData(data.portType);
         n.gameObject.name = data.portName;
         n.kind            = uNode.PortKind.ValueInput;
         n.editorRect      = source.editorRect;
         n.editorRect.x   -= 100;
     });
 }
示例#9
0
 public override void OnClick(Node source, PortCommandData data, Vector2 mousePosition)
 {
     NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, delegate(MacroPortNode n) {
         n.type            = new MemberData(data.portType);
         n.target          = data.getConnection();
         n.gameObject.name = data.portName;
         n.kind            = uNode.PortKind.ValueOutput;
         n.editorRect      = source.editorRect;
         n.editorRect.x   += source.editorRect.width + 100;
     });
 }
示例#10
0
 public override void OnClick(Node source, PortCommandData data, Vector2 mousePosition)
 {
     NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, delegate(MacroPortNode n) {
         n.target          = data.getConnection();
         n.gameObject.name = data.portName;
         n.kind            = uNode.PortKind.FlowInput;
         n.editorRect      = source.editorRect;
         n.editorRect.y   -= 100;
     });
     graph.Refresh();
 }
示例#11
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            ComparisonNode node = source as ComparisonNode;

            NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (ConditionNode n) => {
                n.Condition.AddBlockRange(BlockUtility.GetConditionBlockFromNode(source));
                n.editorRect = node.editorRect;
                RefactorUtility.RetargetNode(node, n);
            });
            NodeEditorUtility.RemoveNode(graph.editorData, node);
            graph.Refresh();
        }
示例#12
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            ORNode node = source as ORNode;

            NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (MultiORNode n) => {
                n.targets[0] = node.targetA;
                n.targets[1] = node.targetB;
                n.editorRect = node.editorRect;
                RefactorUtility.RetargetValueNode(node, n);
            });
            NodeEditorUtility.RemoveNode(graph.editorData, node);
            graph.Refresh();
        }
示例#13
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            MultipurposeNode node = source as MultipurposeNode;

            NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (NodeAction n) => {
                n.Action.AddBlockRange(BlockUtility.GetActionBlockFromNode(source));
                n.onFinished = node.onFinished;
                n.editorRect = node.editorRect;
                RefactorUtility.RetargetNode(node, n);
            });
            NodeEditorUtility.RemoveNode(graph.editorData, node);
            graph.Refresh();
        }
示例#14
0
        public virtual Node Setup(Vector2 mousePosition)
        {
            Node node = null;

            NodeEditorUtility.AddNewNode <T>(
                graph.editorData,
                mousePosition,
                (n) => {
                OnNodeCreated(n);
                node = n;
                graph.Refresh();
            });
            return(node);
        }
示例#15
0
        public override Node CreateNode()
        {
            Node node = leftNode;

            NodeEditorUtility.AddNewNode <MakeArrayNode>(
                NodeGraph.openedGraph.editorData,
                new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                (nod) => {
                nod.elementType = new MemberData(rightType.GetElementType());
                nod.values[0]   = new MemberData(node, MemberData.TargetType.ValueNode);
                node            = nod;
            });
            return(node);
        }
示例#16
0
        public override Node CreateNode()
        {
            Node node = leftNode;

            NodeEditorUtility.AddNewNode <ASNode>(
                NodeGraph.openedGraph.editorData,
                new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                (nod) => {
                nod.compactDisplay = true;
                nod.type           = new MemberData(rightType);
                nod.target         = new MemberData(node, MemberData.TargetType.ValueNode);
                node = nod;
            });
            return(node);
        }
示例#17
0
        public override IList <ItemSelector.CustomItem> GetItems(Node source, MemberData data, System.Type type)
        {
            var items = new List <ItemSelector.CustomItem>();

            items.Add(new ItemSelector.CustomItem("IF", () => {
                NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (NodeIf n) => {
                    n.condition = data;
                    graph.Refresh();
                });
            }, "Flows")
            {
                icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon))
            });
            return(items);
        }
示例#18
0
        public override void OnClick(Node source, PortCommandData data, Vector2 mousePosition)
        {
            if (source.owner)
            {
                Undo.SetCurrentGroupName("To value node");
                Undo.RegisterFullObjectHierarchyUndo(source.owner, "To value node");
            }
            var member = data.member;

            NodeEditorUtility.AddNewNode <MultipurposeNode>(graph.editorData, null, null, new Vector2(source.editorRect.x - 100, source.editorRect.y), (node) => {
                node.target.target = MemberData.CreateFromValue(ReflectionUtils.CreateInstance(filter.Types[0]), filter.Types[0]);
                MemberDataUtility.UpdateMultipurposeMember(node.target);
                member.CopyFrom(MemberData.CreateConnection(node, false));
            });
            graph.Refresh();
        }
示例#19
0
        public override Node CreateNode()
        {
            Node node = leftNode;

            if (rightType.IsCastableTo(typeof(Vector3)))
            {
                NodeEditorUtility.AddNewNode <MultipurposeNode>(
                    NodeGraph.openedGraph.editorData,
                    new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                    (nod) => {
                    nod.target.target          = new MemberData(typeof(Quaternion).GetProperty("eulerAngles"));
                    nod.target.target.instance = new MemberData(node, MemberData.TargetType.ValueNode);
                    node = nod;
                });
            }
            return(node);
        }
示例#20
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            NodeIf node = source as NodeIf;

            NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (NodeValidation n) => {
                var action    = new EqualityCompare();
                action.target = new MultipurposeMember(node.condition);
                action.value  = new MemberData(true);
                n.Validation.AddBlock(action, EventActionData.EventType.Event);
                n.onTrue     = node.onTrue;
                n.onFalse    = node.onFalse;
                n.onFinished = node.onFinished;
                n.editorRect = node.editorRect;
                RefactorUtility.RetargetNode(node, n);
            });
            NodeEditorUtility.RemoveNode(graph.editorData, node);
            graph.Refresh();
        }
示例#21
0
        public override void OnClick(Node source, PortCommandData data, Vector2 mousePosition)
        {
            if (source.owner)
            {
                Undo.SetCurrentGroupName("Assign to lambda");
                Undo.RegisterFullObjectHierarchyUndo(source.owner, "Assign to lambda");
            }
            MemberData m = data.member;

            NodeEditorUtility.AddNewNode <NodeLambda>(graph.editorData, null, null,
                                                      new Vector2(source.editorRect.x - 100, source.editorRect.y),
                                                      (node) => {
                node.delegateType = MemberData.CreateFromType(type);
                m.CopyFrom(new MemberData(node, MemberData.TargetType.ValueNode));
                graph.Refresh();
            });
            graph.Refresh();
        }
示例#22
0
 public void RefreshEventNodes()
 {
     eventNodes = null;
     if (!editorData.selectedGroup && !editorData.selectedRoot && editorData.targetStateGraph != null || editorData.selectedGroup as StateNode)
     {
         if (!editorData.selectedGroup && !editorData.selectedRoot && editorData.targetStateGraph != null)
         {
             eventNodes = new List <BaseEventNode>();
             foreach (var n in editorData.targetStateGraph.eventNodes)
             {
                 eventNodes.Add(n);
             }
         }
         else if (editorData.selectedGroup as StateNode)
         {
             eventNodes = new List <BaseEventNode>(NodeEditorUtility.FindChildNode <StateEventNode>(editorData.selectedGroup.transform).Select(item => item as BaseEventNode));
         }
     }
 }
示例#23
0
 public override bool IsValidNode(Node source)
 {
     if (source is MultipurposeNode)
     {
         MultipurposeNode node = source as MultipurposeNode;
         if (node.CanGetValue() && node.ReturnType() == typeof(bool))
         {
             if (node.IsFlowNode())
             {
                 var nodes = NodeEditorUtility.FindConnectedNodeToFlowNode(node);
                 if (nodes.Count > 0)
                 {
                     return(false);
                 }
             }
             return(true);
         }
     }
     return(false);
 }
示例#24
0
        public override Node CreateNode()
        {
            Node node = leftNode;

            if (rightType == typeof(Quaternion))
            {
                NodeEditorUtility.AddNewNode <MultipurposeNode>(
                    NodeGraph.openedGraph.editorData,
                    new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                    (nod) => {
                    nod.target.target = new MemberData(
                        typeof(Quaternion).GetMethod("Euler", new Type[] { typeof(Vector3) })
                        );
                    nod.target.parameters = new MemberData[] {
                        new MemberData(node, MemberData.TargetType.ValueNode)
                    };
                    node = nod;
                });
            }
            return(node);
        }
示例#25
0
 private ItemSelector.CustomItem GetItem(Type type, Type param1, Type param2, Type returnType, MemberData data, ComparisonType operatorType)
 {
     return(new ItemSelector.CustomItem(string.Format(operatorType.ToString() + " ({0}, {1})", param1.PrettyName(), param2.PrettyName()), () => {
         NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (ComparisonNode n) => {
             if (param1.IsCastableTo(type))
             {
                 n.targetA = data;
                 n.targetB = new MemberData(ReflectionUtils.CreateInstance(param1));
             }
             else
             {
                 n.targetA = new MemberData(ReflectionUtils.CreateInstance(param2));
                 n.targetB = data;
             }
             n.operatorType = operatorType;
             graph.Refresh();
         });
     }, "Operator")
     {
         icon = uNodeEditorUtility.GetTypeIcon(returnType)
     });
 }
示例#26
0
        public override void OnClick(Node source, PortCommandData data, Vector2 mousePosition)
        {
            if (source.owner)
            {
                Undo.SetCurrentGroupName("Assign to contructor node");
                Undo.RegisterFullObjectHierarchyUndo(source.owner, "Assign to contructor node");
            }
            var member = data.member;

            NodeEditorUtility.AddNewNode <MultipurposeNode>(graph.editorData, null, null, new Vector2(source.editorRect.x - 100, source.editorRect.y), (node) => {
                var type  = filter.GetActualType();
                var ctors = type.GetConstructors();
                if (ctors != null && ctors.Length > 0)
                {
                    System.Reflection.ConstructorInfo ctor = null;
                    foreach (var c in ctors)
                    {
                        if (ctor == null)
                        {
                            ctor = c;
                        }
                        else if (ctor.GetParameters().Length < c.GetParameters().Length)
                        {
                            ctor = c;
                        }
                    }
                    node.target.target = new MemberData(ctor);
                }
                else
                {
                    node.target.target = new MemberData(type.Name + ".ctor", type, MemberData.TargetType.Constructor);
                }
                MemberDataUtility.UpdateMultipurposeMember(node.target);
                member.CopyFrom(new MemberData(node, MemberData.TargetType.ValueNode));
            });
            graph.Refresh();
        }
示例#27
0
        public void ShowNodeMenu(Vector2 position, FilterAttribute filter = null, Action <Node> onAddNode = null, bool flowNodes = true)
        {
            var valueMenuPos = GetMenuPosition();

            if (filter == null)
            {
                filter = new FilterAttribute();
                //filter.CanSelectType = true;
                //filter.HideTypes.Add(typeof(void));
            }
            else
            {
                filter = new FilterAttribute(filter);
            }
            filter.DisplayInstanceOnStatic = true;
            filter.MaxMethodParam          = int.MaxValue;
            filter.Public   = true;
            filter.Instance = true;
            if (flowNodes)
            {
                filter.VoidType = true;
            }
            ItemSelector w = ItemSelector.ShowWindow(editorData.selectedGroup ?? editorData.selectedRoot as UnityEngine.Object ?? editorData.graph, new MemberData(editorData.selectedGroup ?? editorData.selectedRoot as UnityEngine.Object ?? editorData.graph, MemberData.TargetType.SelfTarget), filter, delegate(MemberData value) {
                NodeEditorUtility.AddNewNode <MultipurposeNode>(editorData, null, null, position, delegate(MultipurposeNode n) {
                    if (n.target == null)
                    {
                        n.target = new MultipurposeMember();
                    }
                    n.target.target = value;
                    MemberDataUtility.UpdateMultipurposeMember(n.target);
                    if (onAddNode != null)
                    {
                        onAddNode(n);
                    }
                    Refresh();
                });
            }).ChangePosition(valueMenuPos);

            w.displayNoneOption     = false;
            w.displayCustomVariable = false;
            if (filter.SetMember)
            {
                return;                //Return on set member is true.
            }
            List <ItemSelector.CustomItem> customItems = new List <ItemSelector.CustomItem>();

            foreach (NodeMenu menuItem in NodeEditorUtility.FindNodeMenu())
            {
                if (filter.OnlyGetType && menuItem.type != typeof(Type))
                {
                    continue;
                }
                bool isFlowNode = !menuItem.type.IsSubclassOf(typeof(ValueNode));
                if (editorData.selectedRoot && menuItem.HideOnFlow || !flowNodes && isFlowNode)
                {
                    continue;
                }
                if (isFlowNode && filter.SetMember || !filter.IsValidTarget(MemberData.TargetType.FlowNode))
                {
                    continue;
                }
                if (!isFlowNode && !filter.IsValidTarget(MemberData.TargetType.ValueNode))
                {
                    continue;
                }
                if (editorData.selectedGroup && (menuItem.HideOnGroup))
                {
                    continue;
                }
                if (menuItem.HideOnStateMachine && !editorData.selectedRoot && !editorData.selectedGroup)
                {
                    continue;
                }
                if (menuItem.returnType != null && menuItem.returnType != typeof(object) && !filter.IsValidType(menuItem.returnType))
                {
                    continue;
                }
                if (menuItem.IsCoroutine && !editorData.supportCoroutine)
                {
                    continue;
                }
                customItems.Add(new ItemSelector.CustomItem(menuItem.name, delegate() {
                    NodeEditorUtility.AddNewNode <Node>(editorData, menuItem.name.Split(' ')[0], menuItem.type, position, onAddNode);
                    Refresh();
                }, menuItem.category.Replace("/", "."))
                {
                    icon    = isFlowNode ? uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)) : null,
                    tooltip = new GUIContent(menuItem.tooltip),
                });
            }
            #region Flow
            if (flowNodes && !filter.SetMember && filter.IsValidType(typeof(void)))
            {
                if (!(!editorData.selectedRoot && !editorData.selectedGroup))
                {
                    customItems.Add(new ItemSelector.CustomItem("Continue", delegate() {
                        NodeEditorUtility.AddNewNode <NodeJumpStatement>(
                            editorData,
                            "Continue",
                            position,
                            delegate(NodeJumpStatement n) {
                            n.statementType = JumpStatementType.Continue;
                        });
                        Refresh();
                    }, "JumpStatement")
                    {
                        icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)),
                    });
                    customItems.Add(new ItemSelector.CustomItem("Break", delegate() {
                        NodeEditorUtility.AddNewNode <NodeJumpStatement>(
                            editorData,
                            "Break",
                            position,
                            delegate(NodeJumpStatement n) {
                            n.statementType = JumpStatementType.Break;
                        });
                        Refresh();
                    }, "JumpStatement")
                    {
                        icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)),
                    });
                }
                if (editorData.selectedRoot)
                {
                    customItems.Add(new ItemSelector.CustomItem("Return", delegate() {
                        NodeEditorUtility.AddNewNode <NodeReturn>(
                            editorData,
                            "Return",
                            position,
                            delegate(NodeReturn n) {
                        });
                        Refresh();
                    }, "Return")
                    {
                        icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon)),
                    });
                }
            }
            #endregion
            if (filter.IsValidTarget(MemberData.TargetType.ValueNode))
            {
                if (filter.IsValidType(typeof(Type)))
                {
                    customItems.Add(new ItemSelector.CustomItem("typeof()", delegate() {
                        var win = TypeSelectorWindow.ShowWindow(Vector2.zero, new FilterAttribute()
                        {
                            OnlyGetType = true, DisplayRuntimeType = false
                        }, delegate(MemberData[] types) {
                            NodeEditorUtility.AddNewNode <MultipurposeNode>(
                                editorData,
                                position,
                                delegate(MultipurposeNode n) {
                                if (n.target == null)
                                {
                                    n.target = new MultipurposeMember();
                                }
                                n.target.target = types[0];
                                if (onAddNode != null)
                                {
                                    onAddNode(n);
                                }
                                Refresh();
                            });
                        });
                        win.targetObject = editorData.selectedGroup ?? editorData.selectedRoot as UnityEngine.Object ?? editorData.graph;
                        win.ChangePosition(valueMenuPos);
                    }, "Data"));
                }
                var nodeMenuItems = NodeEditorUtility.FindCreateNodeCommands();
                foreach (var n in nodeMenuItems)
                {
                    n.graph  = this;
                    n.filter = filter;
                    if (!n.IsValid())
                    {
                        continue;
                    }
                    customItems.Add(new ItemSelector.CustomItem(n.name, () => {
                        var createdNode = n.Setup(position);
                        if (onAddNode != null)
                        {
                            onAddNode(createdNode);
                        }
                    }, n.category)
                    {
                        icon = uNodeEditorUtility.GetTypeIcon(n.icon),
                    });
                }
            }
            w.customItems = customItems;
        }
示例#28
0
        public void PasteNode(Vector3 position)
        {
            if (nodeToCopy == null || nodeToCopy.Count == 0)
            {
                return;
            }
            if (uNodeEditorUtility.IsPrefab(editorData.graph.gameObject))
            {
                throw new Exception("Editing graph prefab dirrectly is not supported.");
            }
            uNodeEditorUtility.RegisterUndo(editorData.graph, "Paste Node");
            uNodeRoot UNR       = editorData.graph;
            float     progress  = 0;
            int       loopIndex = 0;

            if (nodeToCopy.Count > 5)
            {
                EditorUtility.DisplayProgressBar("Loading", "", progress);
            }
            Vector2 center       = Vector2.zero;
            int     centerLength = 0;
            Dictionary <uNodeComponent, uNodeComponent> CopyedObjectMap = new Dictionary <uNodeComponent, uNodeComponent>(EqualityComparer <uNodeComponent> .Default);

            foreach (uNodeComponent comp in nodeToCopy)
            {
                if (comp == null || comp is EventNode && editorData.selectedGroup != null)
                {
                    continue;
                }
                Node node = comp as Node;
                if (!CopyedObjectMap.ContainsKey(comp))
                {
                    uNodeComponent com = Object.Instantiate(comp);
                    com.gameObject.name = com.gameObject.name.Replace("(Clone)", "");
                    if (editorData.selectedGroup == null)
                    {
                        if (editorData.selectedRoot)
                        {
                            com.transform.parent = editorData.selectedRoot.transform;
                        }
                        else
                        {
                            com.transform.parent = NodeEditorUtility.GetNodeRoot(UNR).transform;
                        }
                    }
                    else
                    {
                        com.transform.parent = editorData.selectedGroup.transform;
                    }
                    int    index = 0;
                    string nm    = com.gameObject.name.TrimEnd(numberChar);
                    while (true)
                    {
                        bool   flag  = false;
                        string gName = com.gameObject.name;
                        foreach (Transform t in com.transform.parent)
                        {
                            if (t != com.transform)
                            {
                                if (t.gameObject.name.Equals(gName))
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        if (flag)
                        {
                            com.gameObject.name = nm + index.ToString();
                            index++;
                            continue;
                        }
                        break;
                    }
                    CopyedObjectMap.Add(comp, com);
                    if (comp is IMacro || comp is ISuperNode)
                    {
                        var fields = EditorReflectionUtility.GetFields(comp.GetType());
                        foreach (var field in fields)
                        {
                            if (field.FieldType == typeof(List <Nodes.MacroPortNode>))
                            {
                                var value = field.GetValueOptimized(comp) as List <Nodes.MacroPortNode>;
                                if (value != null)
                                {
                                    var sourceValue = field.GetValueOptimized(com) as List <Nodes.MacroPortNode>;
                                    for (int i = 0; i < value.Count; i++)
                                    {
                                        if (value[i] == null)
                                        {
                                            continue;
                                        }
                                        CopyedObjectMap.Add(value[i], sourceValue[i]);
                                    }
                                }
                            }
                        }
                    }
                }
                if (node != null)
                {
                    center.x += node.editorRect.x;
                    center.y += node.editorRect.y;
                    centerLength++;
                }
                else
                {
                    BaseEventNode met = comp as BaseEventNode;
                    if (met != null)
                    {
                        center.x += met.editorRect.x;
                        center.y += met.editorRect.y;
                        centerLength++;
                    }
                }
                loopIndex++;
                progress = (float)loopIndex / (float)nodeToCopy.Count;
                if (nodeToCopy.Count > 5)
                {
                    EditorUtility.DisplayProgressBar("Loading", "", progress);
                }
            }
            progress = 0;
            center  /= centerLength;
            HashSet <uNodeComponent> needReflectedComponent = new HashSet <uNodeComponent>();
            uNodeRoot compEvent = null;

            foreach (uNodeComponent com in nodeToCopy)
            {
                uNodeComponent comp = null;
                if (CopyedObjectMap.ContainsKey(com))
                {
                    comp = CopyedObjectMap[com];
                    if (comp == null)
                    {
                        loopIndex++;
                        progress = (float)loopIndex / (float)nodeToCopy.Count;
                        if (nodeToCopy.Count > 5)
                        {
                            EditorUtility.DisplayProgressBar("Loading", "", progress);
                        }
                        continue;
                    }
                    if (comp as Node)
                    {
                        Node node = comp as Node;
                        Func <object, bool> validation = delegate(object o) {
                            if (o is MemberData)
                            {
                                MemberData member = o as MemberData;
                                if (member.IsTargetingPinOrNode)
                                {
                                    NodeComponent n = member.GetInstance() as NodeComponent;
                                    if (n && n is uNodeComponent)
                                    {
                                        if (CopyedObjectMap.ContainsKey(n))
                                        {
                                            member.instance = CopyedObjectMap[n] as NodeComponent;
                                            n.owner         = UNR;
                                            return(true);
                                        }
                                        else if (n.owner != UNR || n.transform.parent != node.transform.parent)
                                        {
                                            member.instance = null;
                                            n.owner         = UNR;
                                            return(true);
                                        }
                                        //return true;
                                    }
                                }
                            }
                            return(false);
                        };
                        if (node as StateNode)
                        {
                            StateNode         eventNode = node as StateNode;
                            TransitionEvent[] TE        = eventNode.GetTransitions();
                            foreach (TransitionEvent n in TE)
                            {
                                var tn = n.GetTargetNode();
                                if (tn == null)
                                {
                                    continue;
                                }
                                if (CopyedObjectMap.ContainsKey(tn))
                                {
                                    n.target = MemberData.CreateConnection(CopyedObjectMap[tn] as Node, true);
                                    n.owner  = UNR;
                                }
                                else if (n.owner != UNR || tn != null && tn.owner != UNR ||
                                         tn != null && tn.transform.parent != node.transform.parent)
                                {
                                    n.target = MemberData.none;
                                    n.owner  = UNR;
                                }
                            }
                        }
                        else if (node is IMacro || node is ISuperNode)
                        {
                            var fields = EditorReflectionUtility.GetFields(comp.GetType());
                            foreach (var field in fields)
                            {
                                if (field.FieldType == typeof(List <Nodes.MacroPortNode>))
                                {
                                    var value = field.GetValueOptimized(comp) as List <Nodes.MacroPortNode>;
                                    if (value != null)
                                    {
                                        foreach (var v in value)
                                        {
                                            AnalizerUtility.AnalizeObject(v, validation);
                                        }
                                    }
                                }
                            }
                        }
                        AnalizerUtility.AnalizeObject(node, validation);
                        node.editorRect = new Rect(node.editorRect.x - center.x + position.x, node.editorRect.y - center.y + position.y, node.editorRect.width, node.editorRect.height);
                        if (node.owner != UNR)
                        {
                            node.owner = UNR;
                        }
                    }
                    else if (comp is BaseEventNode)
                    {
                        BaseEventNode method = comp as BaseEventNode;
                        var           flows  = method.GetFlows();
                        for (int i = 0; i < flows.Count; i++)
                        {
                            var tn = flows[i].GetTargetNode();
                            if (tn != null && CopyedObjectMap.ContainsKey(tn))
                            {
                                flows[i] = new MemberData(CopyedObjectMap[flows[i].GetTargetNode()], MemberData.TargetType.FlowNode);
                            }
                            else if (method.owner != UNR)
                            {
                                flows[i] = MemberData.none;
                            }
                        }
                        method.owner      = UNR;
                        method.editorRect = new Rect(method.editorRect.x - center.x + position.x, method.editorRect.y - center.y + position.y, method.editorRect.width, method.editorRect.height);
                    }
                }
                loopIndex++;
                progress = (float)loopIndex / (float)nodeToCopy.Count;
                if (nodeToCopy.Count > 5)
                {
                    EditorUtility.DisplayProgressBar("Loading", "", progress);
                }
            }
            if (nodeToCopy.Count > 5)
            {
                EditorUtility.ClearProgressBar();
            }
            if (needReflectedComponent.Count > 0)
            {
                NodeEditorUtility.PerformReflectComponent(needReflectedComponent.ToList(), compEvent, UNR);
            }
            foreach (KeyValuePair <uNodeComponent, uNodeComponent> keys in CopyedObjectMap)
            {
                if (keys.Value != null)
                {
                    Undo.RegisterCreatedObjectUndo(keys.Value.gameObject, "Paste Node");
                }
            }
            //allCopyedEvent.Clear();
            Refresh();
        }
示例#29
0
 public override void OnClick(Vector2 mousePosition)
 {
     NodeEditorUtility.AddNewNode <Nodes.ActivateTransition>(graph.editorData, null, null, mousePositionOnCanvas, null);
     graph.Refresh();
 }
示例#30
0
        public override Node CreateNode()
        {
            Node node = leftNode;

            #region RaycastHit2D
            if (rightType == typeof(Collider2D))
            {
                NodeEditorUtility.AddNewNode <MultipurposeNode>(
                    NodeGraph.openedGraph.editorData,
                    new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                    (nod) => {
                    nod.target.target = new MemberData(
                        typeof(RaycastHit2D).GetProperty("collider")
                        );
                    nod.target.target.instance = new MemberData(node, MemberData.TargetType.ValueNode);
                    node = nod;
                });
            }
            else if (rightType == typeof(Transform))
            {
                NodeEditorUtility.AddNewNode <MultipurposeNode>(
                    NodeGraph.openedGraph.editorData,
                    new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                    (nod) => {
                    nod.target.target = new MemberData(
                        typeof(RaycastHit2D).GetProperty("transform")
                        );
                    nod.target.target.instance = new MemberData(node, MemberData.TargetType.ValueNode);
                    node = nod;
                });
            }
            else if (rightType == typeof(Rigidbody2D))
            {
                NodeEditorUtility.AddNewNode <MultipurposeNode>(
                    NodeGraph.openedGraph.editorData,
                    new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                    (nod) => {
                    nod.target.target = new MemberData(
                        typeof(RaycastHit2D).GetProperty("rigidbody")
                        );
                    nod.target.target.instance = new MemberData(node, MemberData.TargetType.ValueNode);
                    node = nod;
                });
            }
            else if (rightType == typeof(GameObject))
            {
                NodeEditorUtility.AddNewNode <MultipurposeNode>(
                    NodeGraph.openedGraph.editorData,
                    new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                    (nod) => {
                    nod.target.target = new MemberData(
                        new MemberInfo[] {
                        typeof(RaycastHit2D),
                        typeof(RaycastHit2D).GetProperty("collider"),
                        typeof(Collider).GetProperty("gameObject"),
                    }
                        );
                    nod.target.target.instance = new MemberData(node, MemberData.TargetType.ValueNode);
                    node = nod;
                });
            }
            else if (rightType.IsCastableTo(typeof(Component)))
            {
                NodeEditorUtility.AddNewNode <MultipurposeNode>(
                    NodeGraph.openedGraph.editorData,
                    new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                    (nod) => {
                    nod.target.target = new MemberData(
                        new MemberInfo[] {
                        typeof(RaycastHit2D),
                        typeof(RaycastHit2D).GetProperty("collider"),
                        typeof(Collider).GetMethod("GetComponent", Type.EmptyTypes).MakeGenericMethod(rightType),
                    }
                        );
                    nod.target.target.instance = new MemberData(node, MemberData.TargetType.ValueNode);
                    node = nod;
                });
            }
            else if (rightType == typeof(float))
            {
                NodeEditorUtility.AddNewNode <MultipurposeNode>(
                    NodeGraph.openedGraph.editorData,
                    new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                    (nod) => {
                    nod.target.target = new MemberData(
                        typeof(RaycastHit2D).GetProperty("distance")
                        );
                    nod.target.target.instance = new MemberData(node, MemberData.TargetType.ValueNode);
                    node = nod;
                });
            }
            else if (rightType == typeof(Vector3))
            {
                NodeEditorUtility.AddNewNode <MultipurposeNode>(
                    NodeGraph.openedGraph.editorData,
                    new Vector2(rightNode.editorRect.x - 250, rightNode.editorRect.y),
                    (nod) => {
                    nod.target.target = new MemberData(
                        typeof(RaycastHit2D).GetProperty("point")
                        );
                    nod.target.target.instance = new MemberData(node, MemberData.TargetType.ValueNode);
                    node = nod;
                });
            }
            #endregion
            return(node);
        }