Exemplo n.º 1
0
        public GraphElementSearcherDatabase AddGraphVariables(IGraphModel graphModel)
        {
            SearcherItem parent       = null;
            var          vsGraphModel = (VSGraphModel)graphModel;

            foreach (IVariableDeclarationModel declarationModel in vsGraphModel.GraphVariableModels)
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, k_GraphVariables);
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new TypeSearcherItemData(declarationModel.DataType, SearcherItemTarget.Variable),
                                    data => ((VSGraphModel)data.GraphModel).CreateVariableNode(
                                        declarationModel,
                                        data.Position,
                                        data.SpawnFlags
                                        ),
                                    declarationModel.Name.Nicify()
                                    ));
            }

            return(this);
        }
Exemplo n.º 2
0
        public GraphElementSearcherDatabase AddUnaryOperators()
        {
            SearcherItem parent = SearcherItemUtility.GetItemFromPath(Items, k_Operator);

            foreach (UnaryOperatorKind kind in Enum.GetValues(typeof(UnaryOperatorKind)))
            {
                if (kind == UnaryOperatorKind.PostDecrement || kind == UnaryOperatorKind.PostIncrement)
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new UnaryOperatorSearcherItemData(kind),
                                        data => data.CreateUnaryStatementNode(kind),
                                        kind.ToString()
                                        ));
                    continue;
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new UnaryOperatorSearcherItemData(kind),
                                    data => data.CreateUnaryStatementNode(kind),
                                    kind.ToString()
                                    ));
            }

            return(this);
        }
Exemplo n.º 3
0
        public GraphElementSearcherDatabase AddGraphAssetMembers(IGraphModel graph)
        {
            SearcherItem parent         = null;
            TypeHandle   voidTypeHandle = Stencil.GenerateTypeHandle(typeof(void));

            foreach (var functionModel in graph.NodeModels.OfType <FunctionModel>())
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, graph.Name);
                }

                if (functionModel.ReturnType == voidTypeHandle)
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new GraphAssetSearcherItemData(graph.AssetModel),
                                        data => data.CreateFunctionRefCallNode(functionModel),
                                        functionModel.Title
                                        ));
                    continue;
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new GraphAssetSearcherItemData(graph.AssetModel),
                                    data => data.CreateFunctionRefCallNode(functionModel),
                                    functionModel.Title
                                    ));
            }

            return(this);
        }
Exemplo n.º 4
0
        public GraphElementSearcherDatabase AddFunctionMembers(IFunctionModel functionModel)
        {
            if (functionModel == null)
            {
                return(this);
            }

            SearcherItem parent = null;
            IEnumerable <IVariableDeclarationModel> members = functionModel.FunctionParameterModels.Union(
                functionModel.FunctionVariableModels);

            foreach (IVariableDeclarationModel declarationModel in members)
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, k_FunctionMembers);
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new TypeSearcherItemData(declarationModel.DataType, SearcherItemTarget.Variable),
                                    data => data.CreateVariableNode(declarationModel),
                                    declarationModel.Name.Nicify()
                                    ));
            }

            return(this);
        }
Exemplo n.º 5
0
        public GraphElementSearcherDatabase AddConstructors(Type type, BindingFlags bindingFlags)
        {
            SearcherItem parent = null;

            foreach (ConstructorInfo constructorInfo in type.GetConstructors(bindingFlags))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                MethodDetails details = constructorInfo.GetMethodDetails();
                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new ConstructorSearcherItemData(constructorInfo),
                                    data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode(
                                        constructorInfo,
                                        data.Position,
                                        data.SpawnFlags
                                        ),
                                    details.MethodName,
                                    details.Details
                                    ));
            }

            return(this);
        }
Exemplo n.º 6
0
        public GraphElementSearcherDatabase AddMethods(
            Type type,
            BindingFlags bindingFlags,
            Dictionary <string, List <Type> > blackList = null
            )
        {
            SearcherItem parent = null;

            foreach (MethodInfo methodInfo in type.GetMethods(bindingFlags)
                     .Where(m => !m.IsSpecialName &&
                            m.GetCustomAttribute <ObsoleteAttribute>() == null &&
                            m.GetCustomAttribute <HiddenAttribute>() == null &&
                            !m.Name.StartsWith("get_", StringComparison.Ordinal) &&
                            !m.Name.StartsWith("set_", StringComparison.Ordinal) &&
                            !m.GetParameters().Any(p => p.ParameterType.IsByRef || p.IsOut || p.ParameterType.IsPointer) &&
                            !SearcherItemCollectionUtility.IsMethodBlackListed(m, blackList))
                     .OrderBy(m => m.Name))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                MethodDetails details = methodInfo.GetMethodDetails();

                if (methodInfo.ReturnType == typeof(void))
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new MethodSearcherItemData(methodInfo),
                                        data => ((StackBaseModel)data.StackModel).CreateFunctionCallNode(
                                            methodInfo,
                                            data.Index,
                                            data.SpawnFlags
                                            ),
                                        details.MethodName,
                                        details.Details
                                        ));
                    continue;
                }

                if (!methodInfo.ReturnType.IsPointer)
                {
                    parent.AddChild(new GraphNodeModelSearcherItem(
                                        new MethodSearcherItemData(methodInfo),
                                        data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode(
                                            methodInfo,
                                            data.Position,
                                            data.SpawnFlags
                                            ),
                                        details.MethodName,
                                        details.Details
                                        ));
                }
            }

            return(this);
        }
Exemplo n.º 7
0
        public GraphElementSearcherDatabase AddControlFlows()
        {
            AddIfCondition(IfConditionMode.Basic);
            AddIfCondition(IfConditionMode.Advanced);
            AddIfCondition(IfConditionMode.Complete);

            SearcherItem parent    = null;
            var          loopTypes = TypeCache.GetTypesDerivedFrom <LoopStackModel>();

            foreach (var loopType in loopTypes.Where(t => !t.IsAbstract))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, k_ControlFlow);
                }

                var name = $"{VseUtility.GetTitle(loopType)}{k_LoopStack}";
                parent.AddChild(new StackNodeModelSearcherItem(
                                    new ControlFlowSearcherItemData(loopType),
                                    data =>
                {
                    var stackModel = (StackBaseModel)data.StackModel;
                    var elements   = new List <IGraphElementModel>();

                    var graphModel    = (VSGraphModel)stackModel.GraphModel;
                    var stackPosition = new Vector2(
                        stackModel.Position.x + k_StackOffset.x,
                        stackModel.Position.y + k_StackOffset.y
                        );

                    LoopStackModel loopStack = graphModel.CreateLoopStack(
                        loopType,
                        stackPosition,
                        data.SpawnFlags
                        );

                    var node = loopStack.CreateLoopNode(
                        stackModel,
                        data.Index,
                        data.SpawnFlags);

                    elements.Add(node);
                    elements.Add(loopStack);

                    var edge = data.SpawnFlags.IsOrphan()
                            ? graphModel.CreateOrphanEdge(loopStack.InputPort, node.OutputPort)
                            : graphModel.CreateEdge(loopStack.InputPort, node.OutputPort);
                    elements.Add(edge);

                    return(elements.ToArray());
                },
                                    name
                                    ));
            }

            return(this);
        }
        public GraphElementSearcherDatabase AddGraphsMethods()
        {
            string[] assetGUIDs = AssetDatabase.FindAssets($"t:{typeof(VSGraphAssetModel).Name}");
            List <Tuple <IGraphModel, FunctionModel> > methods = assetGUIDs.SelectMany(assetGuid =>
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
                VSGraphAssetModel graphAssetModel = AssetDatabase.LoadAssetAtPath <VSGraphAssetModel>(assetPath);

                if (!graphAssetModel || graphAssetModel.GraphModel == null)
                {
                    return(Enumerable.Empty <Tuple <IGraphModel, FunctionModel> >());
                }

                var functionModels = graphAssetModel.GraphModel.NodeModels.OfExactType <FunctionModel>()
                                     .Select(fm => new Tuple <IGraphModel, FunctionModel>(fm.GraphModel, fm));

                return(functionModels.Concat(graphAssetModel.GraphModel.NodeModels.OfExactType <EventFunctionModel>()
                                             .Select(fm => new Tuple <IGraphModel, FunctionModel>(fm.GraphModel, fm))));
            }).ToList();

            if (methods.Count == 0)
            {
                return(this);
            }

            TypeHandle voidTypeHandle = typeof(void).GenerateTypeHandle(Stencil);

            foreach (Tuple <IGraphModel, FunctionModel> method in methods)
            {
                IGraphModel   graphModel    = method.Item1;
                FunctionModel functionModel = method.Item2;
                string        graphName     = graphModel.AssetModel.Name;
                SearcherItem  graphRoot     = SearcherItemUtility.GetItemFromPath(Items, $"{k_Graphs}/{graphName}");

                if (functionModel.ReturnType == voidTypeHandle)
                {
                    graphRoot.AddChild(new StackNodeModelSearcherItem(
                                           new FunctionRefSearcherItemData(graphModel, functionModel),
                                           data => data.CreateFunctionRefCallNode(functionModel),
                                           () => $"{k_Function} {functionModel.Title}"
                                           ));
                    continue;
                }

                graphRoot.AddChild(new GraphNodeModelSearcherItem(
                                       new FunctionRefSearcherItemData(graphModel, functionModel),
                                       data => data.CreateFunctionRefCallNode(functionModel),
                                       () => $"{k_Function} {functionModel.Title}"
                                       ));
            }

            return(this);
        }
 public static void AddAtPath(this List <SearcherItem> items, SearcherItem item, string path = "")
 {
     if (!string.IsNullOrEmpty(path))
     {
         SearcherItem parent = SearcherItemUtility.GetItemFromPath(items, path);
         parent.AddChild(item);
     }
     else
     {
         items.Add(item);
     }
 }
Exemplo n.º 10
0
        public GraphElementSearcherDatabase AddFields(IEnumerable <FieldInfo> fields)
        {
            foreach (FieldInfo field in fields
                     .Where(f => f.GetCustomAttribute <ObsoleteAttribute>() == null &&
                            f.GetCustomAttribute <HiddenAttribute>() == null)
                     .OrderBy(f => f.Name))
            {
                var parent = SearcherItemUtility.GetItemFromPath(Items, field.ReflectedType.FriendlyName(false));

                if (field.IsConstantOrStatic())
                {
                    parent.AddChild(new GraphNodeModelSearcherItem(
                                        new FieldSearcherItemData(field),
                                        data => data.CreateSystemConstantNode(field.DeclaringType, field.FieldType, field.Name),
                                        field.Name
                                        ));
                    continue;
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new FieldSearcherItemData(field),
                                    data =>
                {
                    var getPropertyGroupModel = data.CreateGetPropertyGroupNode();
                    Undo.RegisterCompleteObjectUndo(getPropertyGroupModel.SerializableAsset, "Add Member");
                    getPropertyGroupModel.AddMember(field.GetUnderlyingType(), field.Name);
                    EditorUtility.SetDirty(getPropertyGroupModel.SerializableAsset);
                    return(getPropertyGroupModel);
                },
                                    field.Name
                                    ));

                if (field.CanWrite())
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new FieldSearcherItemData(field),
                                        data =>
                    {
                        SetPropertyGroupNodeModel nodeModel = data.CreateSetPropertyGroupNode();
                        Undo.RegisterCompleteObjectUndo(nodeModel.SerializableAsset, "Add Member");
                        nodeModel.AddMember(field.GetUnderlyingType(), field.Name);
                        EditorUtility.SetDirty(nodeModel.SerializableAsset);
                        return(nodeModel);
                    },
                                        field.Name
                                        ));
                }
            }

            return(this);
        }
Exemplo n.º 11
0
        public GraphElementSearcherDatabase AddConstants(Type type)
        {
            TypeHandle handle = type.GenerateTypeHandle(Stencil);

            SearcherItem parent = SearcherItemUtility.GetItemFromPath(Items, k_Constant);

            parent.AddChild(new GraphNodeModelSearcherItem(
                                new TypeSearcherItemData(handle, SearcherItemTarget.Constant),
                                data => data.CreateConstantNode("", handle),
                                $"{type.FriendlyName().Nicify()} {k_Constant}"
                                ));

            return(this);
        }
Exemplo n.º 12
0
        public GraphElementSearcherDatabase AddFields(Type type, BindingFlags bindingFlags)
        {
            SearcherItem parent = null;

            foreach (FieldInfo fieldInfo in type.GetFields(bindingFlags)
                     .OrderBy(f => f.Name)
                     .Where(f => f.GetCustomAttribute <ObsoleteAttribute>() == null &&
                            f.GetCustomAttribute <HiddenAttribute>() == null))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new FieldSearcherItemData(fieldInfo),
                                    data =>
                {
                    INodeModel nodeModel = ((VSGraphModel)data.GraphModel).CreateGetPropertyGroupNode(
                        data.Position,
                        data.SpawnFlags
                        );
                    ((GetPropertyGroupNodeModel)nodeModel).AddMember(fieldInfo.GetUnderlyingType(), fieldInfo.Name);
                    return(nodeModel);
                },
                                    fieldInfo.Name
                                    ));

                if (fieldInfo.CanWrite())
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new FieldSearcherItemData(fieldInfo),
                                        data =>
                    {
                        INodeModel nodeModel = ((StackBaseModel)data.StackModel).CreateSetPropertyGroupNode(
                            data.Index
                            );
                        ((SetPropertyGroupNodeModel)nodeModel).AddMember(
                            fieldInfo.GetUnderlyingType(),
                            fieldInfo.Name
                            );
                        return(nodeModel);
                    },
                                        fieldInfo.Name
                                        ));
                }
            }

            return(this);
        }
Exemplo n.º 13
0
        public GraphElementSearcherDatabase AddExtensionMethods(Type type)
        {
            Dictionary <Type, List <MethodInfo> > extensions = TypeSystem.GetExtensionMethods(Stencil.GetAssemblies());

            if (!extensions.TryGetValue(type, out var methodInfos))
            {
                return(this);
            }

            SearcherItem parent = null;

            foreach (MethodInfo methodInfo in methodInfos
                     .Where(m => !m.GetParameters().Any(p => p.ParameterType.IsByRef || p.IsOut)))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                MethodDetails details = methodInfo.GetMethodDetails();

                if (methodInfo.ReturnType != typeof(void))
                {
                    parent.AddChild(new GraphNodeModelSearcherItem(
                                        new MethodSearcherItemData(methodInfo),
                                        data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode(
                                            methodInfo,
                                            data.Position,
                                            data.SpawnFlags
                                            ),
                                        details.MethodName,
                                        details.Details
                                        ));
                    continue;
                }

                parent.AddChild(new StackNodeModelSearcherItem(
                                    new MethodSearcherItemData(methodInfo),
                                    data => ((StackBaseModel)data.StackModel).CreateFunctionCallNode(
                                        methodInfo,
                                        data.Index,
                                        data.SpawnFlags
                                        ),
                                    details.MethodName,
                                    details.Details
                                    ));
            }

            return(this);
        }
Exemplo n.º 14
0
        public GraphElementSearcherDatabase AddConstructors(IEnumerable <ConstructorInfo> constructors)
        {
            foreach (var constructor in constructors)
            {
                var           parent  = SearcherItemUtility.GetItemFromPath(Items, constructor.ReflectedType.FriendlyName(false));
                MethodDetails details = constructor.GetMethodDetails();
                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new ConstructorSearcherItemData(constructor),
                                    data => data.CreateFunctionCallNode(constructor),
                                    details.MethodName
                                    ));
            }

            return(this);
        }
Exemplo n.º 15
0
        public GraphElementSearcherDatabase AddBinaryOperators()
        {
            SearcherItem parent = SearcherItemUtility.GetItemFromPath(Items, k_Operator);

            foreach (BinaryOperatorKind kind in Enum.GetValues(typeof(BinaryOperatorKind)))
            {
                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new BinaryOperatorSearcherItemData(kind),
                                    data => data.CreateBinaryOperatorNode(kind),
                                    kind.ToString()
                                    ));
            }

            return(this);
        }
        public GraphElementSearcherDatabase AddFields(Type type, BindingFlags bindingFlags)
        {
            SearcherItem parent = null;

            foreach (FieldInfo fieldInfo in type.GetFields(bindingFlags)
                     .OrderBy(f => f.Name)
                     .Where(f => f.GetCustomAttribute <ObsoleteAttribute>() == null &&
                            f.GetCustomAttribute <HiddenAttribute>() == null))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new FieldSearcherItemData(fieldInfo),
                                    data =>
                {
                    var getPropertyGroupModel = data.CreateGetPropertyGroupNode();
                    Undo.RegisterCompleteObjectUndo(getPropertyGroupModel.SerializableAsset, "Add Member");
                    getPropertyGroupModel.AddMember(fieldInfo.GetUnderlyingType(), fieldInfo.Name);
                    EditorUtility.SetDirty(getPropertyGroupModel.SerializableAsset);
                    return(getPropertyGroupModel);
                },
                                    fieldInfo.Name
                                    ));

                if (fieldInfo.CanWrite())
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new FieldSearcherItemData(fieldInfo),
                                        data =>
                    {
                        SetPropertyGroupNodeModel nodeModel = data.CreateSetPropertyGroupNode();
                        Undo.RegisterCompleteObjectUndo(nodeModel.SerializableAsset, "Add Member");
                        nodeModel.AddMember(fieldInfo.GetUnderlyingType(), fieldInfo.Name);
                        EditorUtility.SetDirty(nodeModel.SerializableAsset);
                        return(nodeModel);
                    },
                                        fieldInfo.Name
                                        ));
                }
            }

            return(this);
        }
Exemplo n.º 17
0
        public GraphElementSearcherDatabase AddMacros()
        {
            string[] assetGUIDs             = AssetDatabase.FindAssets($"t:{typeof(VSGraphAssetModel).Name}");
            List <VSGraphAssetModel> macros = assetGUIDs.Select(assetGuid =>
                                                                AssetDatabase.LoadAssetAtPath <VSGraphAssetModel>(AssetDatabase.GUIDToAssetPath(assetGuid)))
                                              .Where(x =>
            {
                if (x.GraphModel == null)
                {
                    Debug.Log("No GraphModel");
                }
                else if (x.GraphModel.Stencil == null)
                {
                    Debug.Log("No Stencil");
                }
                else
                {
                    return(x.GraphModel.Stencil.GetType() == typeof(MacroStencil));
                }

                return(false);
            })
                                              .ToList();

            if (macros.Count == 0)
            {
                return(this);
            }

            SearcherItem parent = SearcherItemUtility.GetItemFromPath(Items, k_Macros);

            foreach (VSGraphAssetModel macro in macros)
            {
                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new GraphAssetSearcherItemData(macro),
                                    data => ((VSGraphModel)data.GraphModel).CreateMacroRefNode(
                                        macro.GraphModel as VSGraphModel,
                                        data.Position,
                                        data.SpawnFlags
                                        ),
                                    $"{k_Macro} {macro.name}"
                                    ));
            }

            return(this);
        }
Exemplo n.º 18
0
        public GraphElementSearcherDatabase AddMethods(IEnumerable <MethodInfo> methods)
        {
            SearcherItem parent = null;

            foreach (var method in methods.Where(m => !m.IsSpecialName &&
                                                 !m.Name.StartsWith("get_", StringComparison.Ordinal) &&
                                                 !m.Name.StartsWith("set_", StringComparison.Ordinal) &&
                                                 !m.GetParameters().Any(p => p.ParameterType.IsByRef || p.IsOut || p.ParameterType.IsPointer) &&
                                                 m.GetCustomAttribute <ObsoleteAttribute>() == null &&
                                                 m.GetCustomAttribute <HiddenAttribute>() == null))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, method.ReflectedType.FriendlyName(false));
                }

                MethodDetails details = method.GetMethodDetails();

                if (method.ReturnType == typeof(void))
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new MethodSearcherItemData(method),
                                        data => data.CreateFunctionCallNode(method),
                                        details.MethodName,
                                        details.Details
                                        ));
                    continue;
                }

                if (!method.ReturnType.IsPointer)
                {
                    parent.AddChild(new GraphNodeModelSearcherItem(
                                        new MethodSearcherItemData(method),
                                        data => data.CreateFunctionCallNode(method),
                                        details.MethodName
                                        ));
                }
            }

            return(this);
        }
Exemplo n.º 19
0
        public GraphElementSearcherDatabase AddProperties(IEnumerable <PropertyInfo> properties)
        {
            foreach (var property in properties
                     .Where(p => p.GetCustomAttribute <ObsoleteAttribute>() == null &&
                            p.GetCustomAttribute <HiddenAttribute>() == null)
                     .OrderBy(p => p.Name))
            {
                var parent = SearcherItemUtility.GetItemFromPath(Items, property.ReflectedType.FriendlyName(false));

                if (property.GetIndexParameters().Length > 0) // i.e : Vector2.this[int]
                {
                    parent.AddChild(new GraphNodeModelSearcherItem(
                                        new PropertySearcherItemData(property),
                                        data => data.CreateFunctionCallNode(property.GetMethod),
                                        property.Name
                                        ));
                }
                else
                {
                    if (property.CanRead)
                    {
                        if (property.GetMethod.IsStatic)
                        {
                            if (property.CanWrite)
                            {
                                parent.AddChild(new GraphNodeModelSearcherItem(
                                                    new PropertySearcherItemData(property),
                                                    data => data.CreateFunctionCallNode(property.GetMethod),
                                                    property.Name
                                                    ));
                            }
                            else
                            {
                                parent.AddChild(new GraphNodeModelSearcherItem(
                                                    new PropertySearcherItemData(property),
                                                    data => data.CreateSystemConstantNode(
                                                        property.ReflectedType,
                                                        property.PropertyType,
                                                        property.Name),
                                                    property.Name
                                                    ));
                            }
                        }
                        else
                        {
                            parent.AddChild(new GraphNodeModelSearcherItem(
                                                new PropertySearcherItemData(property),
                                                data =>
                            {
                                var getPropertyGroupModel = data.CreateGetPropertyGroupNode();
                                Undo.RegisterCompleteObjectUndo(getPropertyGroupModel.SerializableAsset, "Add Member");
                                getPropertyGroupModel.AddMember(property.GetUnderlyingType(), property.Name);
                                EditorUtility.SetDirty(getPropertyGroupModel.SerializableAsset);

                                return(getPropertyGroupModel);
                            },
                                                property.Name
                                                ));
                        }
                    }

                    if (property.CanWrite)
                    {
                        parent.AddChild(new StackNodeModelSearcherItem(
                                            new PropertySearcherItemData(property),
                                            data => data.CreateFunctionCallNode(property.SetMethod),
                                            property.Name
                                            ));
                    }
                }
            }

            return(this);
        }
Exemplo n.º 20
0
        public GraphElementSearcherDatabase AddProperties(Type type, BindingFlags bindingFlags)
        {
            SearcherItem parent = null;

            foreach (PropertyInfo propertyInfo in type.GetProperties(bindingFlags)
                     .OrderBy(p => p.Name)
                     .Where(p => p.GetCustomAttribute <ObsoleteAttribute>() == null &&
                            p.GetCustomAttribute <HiddenAttribute>() == null))
            {
                var children = new List <SearcherItem>();

                if (propertyInfo.GetIndexParameters().Length > 0) // i.e : Vector2.this[int]
                {
                    children.Add(new GraphNodeModelSearcherItem(
                                     new PropertySearcherItemData(propertyInfo),
                                     data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode(
                                         propertyInfo.GetMethod,
                                         data.Position,
                                         data.SpawnFlags
                                         ),
                                     propertyInfo.Name
                                     ));
                }
                else
                {
                    if (propertyInfo.CanRead)
                    {
                        if (propertyInfo.GetMethod.IsStatic)
                        {
                            if (propertyInfo.CanWrite)
                            {
                                children.Add(new GraphNodeModelSearcherItem(
                                                 new PropertySearcherItemData(propertyInfo),
                                                 data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode(
                                                     propertyInfo.GetMethod,
                                                     data.Position,
                                                     data.SpawnFlags
                                                     ),
                                                 propertyInfo.Name
                                                 ));
                            }
                            else
                            {
                                children.Add(new GraphNodeModelSearcherItem(
                                                 new PropertySearcherItemData(propertyInfo),
                                                 data => ((VSGraphModel)data.GraphModel).CreateSystemConstantNode(
                                                     type,
                                                     propertyInfo,
                                                     data.Position,
                                                     data.SpawnFlags
                                                     ),
                                                 propertyInfo.Name
                                                 ));
                            }
                        }
                        else
                        {
                            children.Add(new GraphNodeModelSearcherItem(
                                             new PropertySearcherItemData(propertyInfo),
                                             data =>
                            {
                                INodeModel nodeModel = ((VSGraphModel)data.GraphModel).CreateGetPropertyGroupNode(
                                    data.Position,
                                    data.SpawnFlags
                                    );
                                ((GetPropertyGroupNodeModel)nodeModel).AddMember(
                                    propertyInfo.GetUnderlyingType(),
                                    propertyInfo.Name
                                    );
                                return(nodeModel);
                            },
                                             propertyInfo.Name
                                             ));
                        }
                    }

                    if (propertyInfo.CanWrite)
                    {
                        children.Add(new StackNodeModelSearcherItem(
                                         new PropertySearcherItemData(propertyInfo),
                                         data => ((StackBaseModel)data.StackModel).CreateFunctionCallNode(
                                             propertyInfo.SetMethod,
                                             data.Index,
                                             data.SpawnFlags
                                             ),
                                         propertyInfo.Name
                                         ));
                    }
                }

                if (children.Count == 0)
                {
                    continue;
                }

                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                foreach (SearcherItem child in children)
                {
                    parent.AddChild(child);
                }
            }

            return(this);
        }
        public GraphElementSearcherDatabase AddProperties(Type type, BindingFlags bindingFlags)
        {
            SearcherItem parent = null;

            foreach (PropertyInfo propertyInfo in type.GetProperties(bindingFlags)
                     .OrderBy(p => p.Name)
                     .Where(p => p.GetCustomAttribute <ObsoleteAttribute>() == null &&
                            p.GetCustomAttribute <HiddenAttribute>() == null))
            {
                var children = new List <SearcherItem>();

                if (propertyInfo.GetIndexParameters().Length > 0) // i.e : Vector2.this[int]
                {
                    children.Add(new GraphNodeModelSearcherItem(
                                     new PropertySearcherItemData(propertyInfo),
                                     data => data.CreateFunctionCallNode(propertyInfo.GetMethod),
                                     propertyInfo.Name
                                     ));
                }
                else
                {
                    if (propertyInfo.CanRead)
                    {
                        if (propertyInfo.GetMethod.IsStatic)
                        {
                            if (propertyInfo.CanWrite)
                            {
                                children.Add(new GraphNodeModelSearcherItem(
                                                 new PropertySearcherItemData(propertyInfo),
                                                 data => data.CreateFunctionCallNode(propertyInfo.GetMethod),
                                                 propertyInfo.Name
                                                 ));
                            }
                            else
                            {
                                children.Add(new GraphNodeModelSearcherItem(
                                                 new PropertySearcherItemData(propertyInfo),
                                                 data => data.CreateSystemConstantNode(type, propertyInfo),
                                                 propertyInfo.Name
                                                 ));
                            }
                        }
                        else
                        {
                            children.Add(new GraphNodeModelSearcherItem(
                                             new PropertySearcherItemData(propertyInfo),
                                             data =>
                            {
                                var getPropertyGroupModel = data.CreateGetPropertyGroupNode();
                                Undo.RegisterCompleteObjectUndo(getPropertyGroupModel.SerializableAsset, "Add Member");
                                getPropertyGroupModel.AddMember(propertyInfo.GetUnderlyingType(), propertyInfo.Name);
                                EditorUtility.SetDirty(getPropertyGroupModel.SerializableAsset);

                                return(getPropertyGroupModel);
                            },
                                             propertyInfo.Name
                                             ));
                        }
                    }

                    if (propertyInfo.CanWrite)
                    {
                        children.Add(new StackNodeModelSearcherItem(
                                         new PropertySearcherItemData(propertyInfo),
                                         data => data.CreateFunctionCallNode(propertyInfo.SetMethod),
                                         propertyInfo.Name
                                         ));
                    }
                }

                if (children.Count == 0)
                {
                    continue;
                }

                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                foreach (SearcherItem child in children)
                {
                    parent.AddChild(child);
                }
            }

            return(this);
        }