Beispiel #1
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();
 }
Beispiel #2
0
 public Node GetTargetNode()
 {
     if (targetNode != null)
     {
         target     = MemberData.CreateConnection(targetNode, true);
         targetNode = null;
     }
     return(target.GetTargetNode());
 }
Beispiel #3
0
 protected override void InitializeView()
 {
     base.InitializeView();
     Nodes.EventHook node = targetNode as Nodes.EventHook;
     if (node.target.isAssigned)
     {
         Type            targetType     = node.target.type;
         Type[]          parameterTypes = null;
         ParameterInfo[] parameterInfos = null;
         if (targetType == null)
         {
             return;
         }
         if (targetType.IsCastableTo(typeof(Delegate)))
         {
             parameterInfos = targetType.GetMethod("Invoke").GetParameters();
             parameterTypes = parameterInfos.Select(i => i.ParameterType).ToArray();
         }
         else if (targetType.IsCastableTo(typeof(UnityEventBase)))
         {
             var method = targetType.GetMethod("AddListener");
             parameterTypes = method.GetParameters()[0].ParameterType.GetGenericArguments();
         }
         if (parameterTypes == null)
         {
             return;
         }
         while (node.parameters.Count != parameterTypes.Length)
         {
             if (node.parameters.Count > parameterTypes.Length)
             {
                 node.parameters.RemoveAt(node.parameters.Count - 1);
             }
             else
             {
                 node.parameters.Add(null);
             }
         }
         for (int i = 0; i < parameterTypes.Length; i++)
         {
             int  x    = i;
             Type type = parameterTypes[i];
             AddOutputValuePort(
                 new PortData()
             {
                 portID        = "parameters#" + x,
                 getPortName   = () => parameterInfos != null ? parameterInfos[x].Name : "Parameter " + x,
                 getPortType   = () => type,
                 getPortValue  = () => parameterTypes[x],
                 getConnection = () => {
                     return(MemberData.CreateConnection(node, "parameters", x, type));
                 },
             }
                 );
         }
     }
 }
Beispiel #4
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;
     });
 }
Beispiel #5
0
        protected override void InitializeView()
        {
            base.InitializeView();
            Nodes.NodeLambda node = targetNode as Nodes.NodeLambda;
            var delegateType      = node.delegateType.Get <Type>();

            if (delegateType == null)
            {
                return;
            }
            var methodInfo = delegateType.GetMethod("Invoke");
            var parameters = methodInfo?.GetParameters();

            if (methodInfo == null || parameters == null)
            {
                return;
            }
            while (node.parameterValues.Count != parameters.Length)
            {
                if (node.parameterValues.Count > parameters.Length)
                {
                    node.parameterValues.RemoveAt(node.parameterValues.Count - 1);
                }
                else
                {
                    node.parameterValues.Add(null);
                }
            }
            for (int i = 0; i < parameters.Length; i++)
            {
                int  x    = i;
                Type type = parameters[i].ParameterType;
                //var port =
                AddOutputValuePort(
                    new PortData()
                {
                    portID        = nameof(node.parameterValues) + "#" + x,
                    getPortName   = () => $"P {x}",
                    getPortType   = () => type,
                    getPortValue  = () => type,
                    getConnection = () => {
                        return(MemberData.CreateConnection(node, nameof(node.parameterValues), x, type));
                    },
                }
                    );
            }
            if (methodInfo.ReturnType == typeof(void))
            {
                AddOutputFlowPort(nameof(node.body));
            }
            else
            {
                AddInputValuePort(nameof(node.input), () => methodInfo.ReturnType);
            }
        }
Beispiel #6
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;
     });
 }
Beispiel #7
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();
        }
Beispiel #8
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();
        }
 protected void CreateOverrideMembers(uNodeRoot graph)
 {
     foreach (var member in graphOverrideMembers)
     {
         if (member is MethodInfo method)
         {
             var func = CreateComponent <uNodeFunction>(method.Name, GetRootTransfrom(graph), (val) => {
                 val.Name       = method.Name;
                 val.returnType = MemberData.CreateFromType(method.ReturnType);
                 val.parameters = method.GetParameters().Select(p => new ParameterData(p.Name, p.ParameterType)
                 {
                     value = p.DefaultValue
                 }).ToArray();
                 val.genericParameters = method.GetGenericArguments().Select(p => new GenericParameterData(p.Name)).ToArray();
             });
             CreateComponent <Nodes.NodeAction>("Entry", func, node => {
                 func.startNode = node;
             });
         }
         else if (member is PropertyInfo property)
         {
             var prop = CreateComponent <uNodeProperty>(property.Name, GetRootTransfrom(graph), (val) => {
                 val.Name = property.Name;
                 val.type = MemberData.CreateFromType(property.PropertyType);
             });
             var getMethod = property.GetGetMethod(true);
             var setMethod = property.GetSetMethod(true);
             if (getMethod != null)
             {
                 var func = CreateComponent <uNodeFunction>("Getter", GetRootTransfrom(graph), (val) => {
                     val.Name       = getMethod.Name;
                     val.returnType = MemberData.CreateFromType(getMethod.ReturnType);
                     val.parameters = getMethod.GetParameters().Select(p => new ParameterData(p.Name, p.ParameterType)
                     {
                         value = p.DefaultValue
                     }).ToArray();
                     val.genericParameters = getMethod.GetGenericArguments().Select(p => new GenericParameterData(p.Name)).ToArray();
                 });
                 CreateComponent <Nodes.NodeAction>("Entry", func, node => {
                     func.startNode = node;
                     CreateComponent <NodeReturn>("Return", func, returnNode => {
                         node.onFinished        = MemberData.CreateConnection(returnNode, true);
                         returnNode.returnValue = MemberData.CreateFromValue(null, property.PropertyType);
                     });
                 });
                 prop.getRoot = func;
             }
             if (setMethod != null)
             {
                 var func = CreateComponent <uNodeFunction>("Setter", GetRootTransfrom(graph), (val) => {
                     val.Name       = setMethod.Name;
                     val.returnType = MemberData.CreateFromType(setMethod.ReturnType);
                     val.parameters = setMethod.GetParameters().Select(p => new ParameterData(p.Name, p.ParameterType)
                     {
                         value = p.DefaultValue
                     }).ToArray();
                     val.genericParameters = setMethod.GetGenericArguments().Select(p => new GenericParameterData(p.Name)).ToArray();
                 });
                 CreateComponent <Nodes.NodeAction>("Entry", func, node => {
                     func.startNode = node;
                 });
                 prop.setRoot = func;
             }
         }
     }
 }
Beispiel #10
0
        protected override void InitializeView()
        {
            base.InitializeView();
            Nodes.NodeTry node = targetNode as Nodes.NodeTry;
            while (node.Exceptions.Count != node.ExceptionTypes.Count)
            {
                if (node.Exceptions.Count > node.ExceptionTypes.Count)
                {
                    node.Exceptions.RemoveAt(node.Exceptions.Count - 1);
                }
                else
                {
                    node.Exceptions.Add(null);
                }
            }
            while (node.Flows.Count != node.ExceptionTypes.Count)
            {
                if (node.Flows.Count > node.ExceptionTypes.Count)
                {
                    node.Flows.RemoveAt(node.Flows.Count - 1);
                }
                else
                {
                    node.Flows.Add(null);
                }
            }
            for (int i = 0; i < node.ExceptionTypes.Count; i++)
            {
                int  x      = i;
                var  member = node.ExceptionTypes[i];
                Type type   = typeof(Exception);
                if (member.isAssigned)
                {
                    type = member.Get <Type>();
                }
                AddOutputValuePort(
                    new PortData()
                {
                    getPortName   = () => "Ex " + x.ToString(),
                    getPortType   = () => type,
                    getPortValue  = () => node.Exceptions[x],
                    getConnection = () => {
                        return(MemberData.CreateConnection(node, "Exceptions", x, type));
                    },
                }
                    );
                ControlView controlType = new ControlView();
                //controlType.Add(new Label(x.ToString()));
                controlType.Add(new MemberControl(
                                    new ControlConfig()
                {
                    owner          = this,
                    type           = typeof(MemberData),
                    value          = member,
                    onValueChanged = (obj) => {
                        node.ExceptionTypes[x] = obj as MemberData;
                    },
                    filter = filter,
                },
                                    true
                                    ));
                AddControl(Direction.Input, controlType);
                AddOutputFlowPort(
                    new PortData()
                {
                    getPortName    = () => x.ToString(),
                    getPortValue   = () => node.Flows[x],
                    onValueChanged = (val) => {
                        node.Flows[x] = val as MemberData;
                    },
                }
                    );
            }
            ControlView control = new ControlView();

            control.style.alignSelf = Align.Center;
            control.Add(new Button(() => {
                if (node.ExceptionTypes.Count > 0)
                {
                    RegisterUndo();
                    node.ExceptionTypes.RemoveAt(node.ExceptionTypes.Count - 1);
                    node.Exceptions.RemoveAt(node.Exceptions.Count - 1);
                    node.Flows.RemoveAt(node.Flows.Count - 1);
                    MarkRepaint();
                }
            })
            {
                text = "-"
            });
            control.Add(new Button(() => {
                RegisterUndo();
                node.ExceptionTypes.Add(MemberData.none);
                node.Exceptions.Add(null);
                node.Flows.Add(MemberData.none);
                MarkRepaint();
            })
            {
                text = "+"
            });
            AddControl(Direction.Input, control);

            AddOutputFlowPort("Finally");
            AddOutputFlowPort("onFinished", "Next");
        }
Beispiel #11
0
        protected override void InitializeView()
        {
            base.InitializeView();
            Nodes.NodeAnonymousFunction node = targetNode as Nodes.NodeAnonymousFunction;
            while (node.parameterValues.Count != node.parameterTypes.Count)
            {
                if (node.parameterValues.Count > node.parameterTypes.Count)
                {
                    node.parameterValues.RemoveAt(node.parameterValues.Count - 1);
                }
                else
                {
                    node.parameterValues.Add(null);
                }
            }
            for (int i = 0; i < node.parameterTypes.Count; i++)
            {
                int  x      = i;
                var  member = node.parameterTypes[i];
                Type type   = typeof(object);
                if (member.isAssigned)
                {
                    type = member.startType;
                }
                //var port =
                AddOutputValuePort(
                    new PortData()
                {
                    portID        = "parameterValues#" + x,
                    getPortName   = () => "",
                    getPortType   = () => type,
                    getPortValue  = () => node.parameterTypes[x],
                    getConnection = () => {
                        return(MemberData.CreateConnection(node, "parameterValues", x, type));
                    },
                }
                    );
                ControlView controlType = new ControlView();
                controlType.style.flexDirection = FlexDirection.RowReverse;
                controlType.Add(new Label("P " + x));
                controlType.Add(new MemberControl(
                                    new ControlConfig()
                {
                    owner  = this,
                    type   = typeof(MemberData),
                    filter = new FilterAttribute()
                    {
                        OnlyGetType = true
                    },
                    value          = member,
                    onValueChanged = (obj) => {
                        node.parameterTypes[x] = obj as MemberData;
                    },
                }
                                    ));
                //port.SetControl(controlType);
                AddControl(Direction.Input, controlType);
            }
            ControlView control = new ControlView();

            control.style.alignSelf = Align.FlexEnd;
            control.Add(new Button(() => {
                if (node.parameterTypes.Count > 0)
                {
                    RegisterUndo();
                    node.parameterTypes.RemoveAt(node.parameterTypes.Count - 1);
                    node.parameterValues.RemoveAt(node.parameterValues.Count - 1);
                    MarkRepaint();
                }
            })
            {
                text = "-"
            });
            control.Add(new Button(() => {
                RegisterUndo();
                node.parameterTypes.Add(new MemberData(typeof(object), MemberData.TargetType.Type));
                node.parameterValues.Add(null);
                MarkRepaint();
            })
            {
                text = "+"
            });
            AddControl(Direction.Input, control);
        }