Пример #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             rType  = source.ReturnType();
            FilterAttribute filter = new FilterAttribute {
                VoidType          = true,
                MaxMethodParam    = int.MaxValue,
                Public            = true,
                Instance          = true,
                Static            = false,
                UnityReference    = false,
                InvalidTargetType = MemberData.TargetType.Null | MemberData.TargetType.Values,
                // DisplayDefaultStaticType = false
                ValidateMember = (member) => {
                    if (member is System.Reflection.MethodInfo)
                    {
                        var parameters = (member as System.Reflection.MethodInfo).GetParameters();
                        for (int i = 0; i < parameters.Length; i++)
                        {
                            if (rType.IsCastableTo(parameters[i].ParameterType))
                            {
                                return(true);
                            }
                        }
                    }
                    return(false);
                },
            };
            List <ItemSelector.CustomItem> customItems = null;

            if (rType.IsCastableTo(typeof(IGraphSystem)) && source is MultipurposeNode)
            {
                MultipurposeNode multipurposeNode = source as MultipurposeNode;
                if (multipurposeNode.target != null && multipurposeNode.target.target != null && (multipurposeNode.target.target.targetType == MemberData.TargetType.SelfTarget || multipurposeNode.target.target.targetType == MemberData.TargetType.Values))
                {
                    var sTarget = multipurposeNode.target.target.startTarget;
                    if (sTarget is IGraphSystem)
                    {
                        customItems = ItemSelector.MakeCustomItems(sTarget as Object);
                        customItems.AddRange(ItemSelector.MakeCustomItems(typeof(uNodeRoot), sTarget, filter, "Inherit Member"));
                    }
                }
            }
            bool flag = false;

            if (customItems == null)
            {
                if (rType is RuntimeType)
                {
                    customItems = ItemSelector.MakeCustomItems((rType as RuntimeType).GetRuntimeMembers(), filter);
                    if (rType.BaseType != null)
                    {
                        customItems.AddRange(ItemSelector.MakeCustomItems(rType.BaseType, filter, "Inherit Member"));
                    }
                }
                else
                {
                    customItems = ItemSelector.MakeCustomItems(rType, filter, " " + rType.PrettyName());
                }
                var usedNamespaces = source.owner.GetNamespaces().ToHashSet();
                if (usedNamespaces != null)
                {
                    customItems.AddRange(ItemSelector.MakeExtensionItems(rType, usedNamespaces, filter, "Extensions"));
                    flag = true;
                }

                var customInputItems = NodeEditorUtility.FindCustomInputPortItems();
                if (customInputItems != null && customInputItems.Count > 0)
                {
                    var mData = new MemberData(source, MemberData.TargetType.ValueNode);
                    foreach (var c in customInputItems)
                    {
                        c.graph = graph;
                        c.mousePositionOnCanvas = mousePositionOnCanvas;
                        if (c.IsValidPort(rType, PortAccessibility.OnlyGet))
                        {
                            var items = c.GetItems(source, mData, rType);
                            if (items != null)
                            {
                                customItems.AddRange(items);
                            }
                        }
                    }
                }
            }
            if (customItems != null)
            {
                filter.Static = false;
                customItems.Sort((x, y) => {
                    if (x.category != y.category)
                    {
                        return(string.Compare(x.category, y.category));
                    }
                    return(string.Compare(x.name, y.name));
                });
                ItemSelector w = ItemSelector.ShowWindow(source, MemberData.none, filter, delegate(MemberData value) {
                    flag = flag && value.targetType == MemberData.TargetType.Method && !rType.IsCastableTo(value.startType);
                    if (!flag && !value.isStatic)
                    {
                        value.instance = new MemberData(source, MemberData.TargetType.ValueNode);
                    }
                    NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, delegate(MultipurposeNode n) {
                        if (n.target == null)
                        {
                            n.target = new MultipurposeMember();
                        }
                        n.target.target = value;
                        MemberDataUtility.UpdateMultipurposeMember(n.target);
                        if (flag)
                        {
                            var pTypes = value.ParameterTypes;
                            if (pTypes != null)
                            {
                                int paramIndex   = 0;
                                MemberData param = null;
                                for (int i = 0; i < pTypes.Length; i++)
                                {
                                    var types = pTypes[i];
                                    if (types != null)
                                    {
                                        for (int y = 0; y < types.Length; y++)
                                        {
                                            if (rType.IsCastableTo(types[y]))
                                            {
                                                param = new MemberData(source, MemberData.TargetType.ValueNode);
                                                break;
                                            }
                                            paramIndex++;
                                        }
                                        if (param != null)
                                        {
                                            break;
                                        }
                                    }
                                }
                                if (n.target.parameters.Length > paramIndex && param != null)
                                {
                                    n.target.parameters[paramIndex] = param;
                                }
                            }
                        }
                    });
                    graph.Refresh();
                }, customItems).ChangePosition(GUIUtility.GUIToScreenPoint(mousePosition));
                w.displayRecentItem = false;
                w.displayNoneOption = false;
            }
        }
Пример #3
0
        public override void OnClick(Node source, PortCommandData data, Vector2 mousePosition)
        {
            Type            type   = data.portType;
            FilterAttribute filter = new FilterAttribute {
                VoidType          = true,
                MaxMethodParam    = int.MaxValue,
                Public            = true,
                Instance          = true,
                Static            = false,
                UnityReference    = false,
                InvalidTargetType = MemberData.TargetType.Null | MemberData.TargetType.Values,
                // DisplayDefaultStaticType = false
                ValidateMember = (member) => {
                    if (member is System.Reflection.MethodInfo)
                    {
                        var parameters = (member as System.Reflection.MethodInfo).GetParameters();
                        for (int i = 0; i < parameters.Length; i++)
                        {
                            if (type.IsCastableTo(parameters[i].ParameterType))
                            {
                                return(true);
                            }
                        }
                    }
                    return(false);
                },
            };
            List <ItemSelector.CustomItem> customItems;

            if (type is RuntimeType)
            {
                customItems = ItemSelector.MakeCustomItems((type as RuntimeType).GetRuntimeMembers(), filter);
                if (type.BaseType != null)
                {
                    customItems.AddRange(ItemSelector.MakeCustomItems(type.BaseType, filter, "Inherit Member"));
                }
            }
            else
            {
                customItems = ItemSelector.MakeCustomItems(type, filter);
            }
            var usingNamespaces = source.owner.GetNamespaces().ToHashSet();

            if (usingNamespaces != null && usingNamespaces.Count > 0)
            {
                customItems.AddRange(ItemSelector.MakeExtensionItems(type, usingNamespaces, filter, "Extensions"));
            }
            {            //Custom input port items.
                if (customItems == null)
                {
                    customItems = new System.Collections.Generic.List <ItemSelector.CustomItem>();
                }
                var customInputItems = NodeEditorUtility.FindCustomInputPortItems();
                if (customInputItems != null && customInputItems.Count > 0)
                {
                    var mData = data.getConnection();
                    foreach (var c in customInputItems)
                    {
                        c.graph = graph;
                        c.mousePositionOnCanvas = mousePositionOnCanvas;
                        if (c.IsValidPort(type, PortAccessibility.OnlyGet))
                        {
                            var items = c.GetItems(source, mData, type);
                            if (items != null)
                            {
                                customItems.AddRange(items);
                            }
                        }
                    }
                }
            }
            if (customItems != null)
            {
                filter.Static = true;
                customItems.Sort((x, y) => {
                    if (x.category != y.category)
                    {
                        return(string.Compare(x.category, y.category));
                    }
                    return(string.Compare(x.name, y.name));
                });
                ItemSelector w = ItemSelector.ShowWindow(source, MemberData.none, filter, (MemberData mData) => {
                    bool flag = mData.targetType == MemberData.TargetType.Method && !type.IsCastableTo(mData.startType);
                    if (!flag && !mData.isStatic)
                    {
                        mData.instance = data.getConnection();
                    }
                    NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (MultipurposeNode nod) => {
                        if (nod.target == null)
                        {
                            nod.target = new MultipurposeMember();
                        }
                        nod.target.target = mData;
                        MemberDataUtility.UpdateMultipurposeMember(nod.target);
                        if (flag)
                        {
                            var pTypes = mData.ParameterTypes;
                            if (pTypes != null)
                            {
                                int paramIndex   = 0;
                                MemberData param = null;
                                for (int i = 0; i < pTypes.Length; i++)
                                {
                                    var types = pTypes[i];
                                    if (types != null)
                                    {
                                        for (int y = 0; y < types.Length; y++)
                                        {
                                            if (type.IsCastableTo(types[y]))
                                            {
                                                param = data.getConnection();
                                                break;
                                            }
                                            paramIndex++;
                                        }
                                        if (param != null)
                                        {
                                            break;
                                        }
                                    }
                                }
                                if (nod.target.parameters.Length > paramIndex && param != null)
                                {
                                    nod.target.parameters[paramIndex] = param;
                                }
                            }
                        }
                        graph.Refresh();
                    });
                }, customItems).ChangePosition(GUIUtility.GUIToScreenPoint(mousePosition));
                w.displayRecentItem = false;
                w.displayNoneOption = false;
            }
        }