コード例 #1
0
        public static NodeManifest Construct(Type[] types)
        {
            var manifest = new NodeManifest();

            var information = new List <NodeInformation> ();

            foreach (var type in types)
            {
                information.Add(NodeInformation.Construct(type));
            }
            manifest.Nodes = information.ToArray();
            return(manifest);
        }
コード例 #2
0
        public static NodeManifest Construct(Type[] types)
        {
            var manifest = new NodeManifest();

            var information = new Dictionary <string, NodeInformation> ();

            foreach (var type in types)
            {
                information.Add(type.FullName, NodeInformation.Construct(type));
            }
            manifest.Nodes = information;
            return(manifest);
        }
コード例 #3
0
        public static BehaviourManifest CreateFromAppDomain(AppDomain appDomain)
        {
            var manifest = new BehaviourManifest();

            var objectTypes = new Dictionary <string, TypeInformation>();

            foreach (var type in frameworkTypes)
            {
                objectTypes.Add(type.Name, TypeInformation.Construct(type));
            }

            var nodeTypes = new Dictionary <string, NodeInformation>();

            foreach (var assembly in GetDependentAssemblies(appDomain, typeof(NodeTemplate).Assembly))
            {
                Type[] types;
                try
                {
                    types = assembly.GetTypes();
                }
                catch
                {
                    continue;
                }

                foreach (var type in types)
                {
                    ConstructType(type, objectTypes);

                    if (type.IsAbstract)
                    {
                        continue;
                    }

                    if (typeof(NodeTemplate).IsAssignableFrom(type))
                    {
                        nodeTypes.Add(type.FullName, NodeInformation.Construct(type));
                    }
                }
            }

            manifest.Types = new TypeManifest()
            {
                ObjectTypes = objectTypes,
                NodeTypes   = nodeTypes,
            };

            return(manifest);
        }
コード例 #4
0
        public static NodeManifest Construct()
        {
            var manifest = new NodeManifest();

            var information = new Dictionary <string, NodeInformation> ();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (type.IsAbstract)
                    {
                        continue;
                    }

                    if (typeof(Node).IsAssignableFrom(type))
                    {
                        information.Add(type.FullName, NodeInformation.Construct(type));
                    }
                }
            }
            manifest.Nodes = information;
            return(manifest);
        }
コード例 #5
0
        public static NodeInformation Construct(Type nodeType)
        {
            var nodeInformation = new NodeInformation
            {
                Name = nodeType.Name
            };

            var typeDefinition  = new Type[] { typeof(IGraphInstance), nodeType.BaseType.GenericTypeArguments[0] };
            var inputsProperty  = nodeType.GetMethod("Inputs", typeDefinition);
            var outputsProperty = nodeType.GetMethod("Outputs", typeDefinition);

            var    nodeTemplate     = (Node)Activator.CreateInstance(nodeType);
            object metadataInstance = Activator.CreateInstance(typeDefinition[1]);
            var    singleNodeGraph  = new ManifestCaptureGraphInstance(nodeTemplate);

            int inputId            = 0;
            int outputId           = 0;
            var inputSocketFields  = new List <FieldInfo> ();
            var outputSocketFields = new List <FieldInfo> ();
            var fieldInfos         = new List <FieldInformation> ();

            foreach (var field in nodeType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (field.FieldType == typeof(InputSocket))
                {
                    field.SetValue(nodeTemplate, new InputSocket(inputId));
                    inputId++;
                    inputSocketFields.Add(field);
                }
                else if (field.FieldType == typeof(OutputSocket))
                {
                    field.SetValue(nodeTemplate, new OutputSocket(outputId));
                    outputId++;
                    outputSocketFields.Add(field);
                }
                else
                {
                    fieldInfos.Add(FieldInformation.Construct(field));
                }
            }
            nodeInformation.Fields = fieldInfos.ToArray();

            object[] connectParameters = { singleNodeGraph, metadataInstance };
            var      inputsArray       = (InputMap[])inputsProperty.Invoke(nodeTemplate, connectParameters);
            var      outputsArray      = (OutputMap[])outputsProperty.Invoke(nodeTemplate, connectParameters);

            if (inputsArray != null)
            {
                nodeInformation.Inputs = new SocketInformation[inputsArray.Length];

                for (int i = 0; i < inputsArray.Length; i++)
                {
                    var map   = inputsArray[i];
                    var field = inputSocketFields[map.Source.TargetId];
                    nodeInformation.Inputs[i] = SocketInformation.Construct(field, map);
                }
            }
            else
            {
                nodeInformation.Inputs = null;
            }

            if (outputsArray != null)
            {
                nodeInformation.Outputs = new SocketInformation[outputsArray.Length];

                for (int i = 0; i < outputsArray.Length; i++)
                {
                    var map   = outputsArray[i];
                    var field = outputSocketFields[map.Source.Id];
                    nodeInformation.Outputs[i] = SocketInformation.Construct(field, map);
                }
            }
            else
            {
                nodeInformation.Outputs = null;
            }

            return(nodeInformation);
        }
コード例 #6
0
        public static NodeInformation Construct(Type nodeType)
        {
            var nodeInformation = new NodeInformation();

            var nodeTemplate     = (NodeTemplate)Activator.CreateInstance(nodeType);
            var metadataInstance = (NodeInstanceBase)nodeTemplate.CreateInstance();

            var instanceType = metadataInstance.GetType();

            var singleNodeGraph = new ManifestCaptureGraphInstance(nodeTemplate);

            int inputId            = 0;
            int outputId           = 0;
            var inputSocketFields  = new List <FieldInfo>();
            var outputSocketFields = new List <FieldInfo>();
            var fieldInfos         = new Dictionary <string, FieldInformation>();

            foreach (var field in nodeType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (field.FieldType == typeof(OutputSocket))
                {
                    field.SetValue(nodeTemplate, new OutputSocket(outputId));
                    outputId++;
                    outputSocketFields.Add(field);
                }
                else
                {
                    if (field.FieldType == typeof(InputSocket))
                    {
                        field.SetValue(nodeTemplate, new InputSocket(inputId));
                        inputId++;
                        inputSocketFields.Add(field);
                    }
                    fieldInfos.Add(field.Name, FieldInformation.ConstructFieldInformation(field, nodeTemplate));
                }
            }
            nodeInformation.Fields = fieldInfos;

            var nodeProperty = instanceType.GetProperty("Template");

            nodeProperty.SetValue(metadataInstance, nodeTemplate);

            var connectionMapper = new ConnectionMapper(metadataInstance, singleNodeGraph);

            var inputsArray  = metadataInstance.Inputs(connectionMapper);
            var outputsArray = metadataInstance.Outputs(connectionMapper);

            if (inputsArray != null)
            {
                nodeInformation.Inputs = new Dictionary <string, SocketInformation>(inputsArray.Length);

                for (int i = 0; i < inputsArray.Length; i++)
                {
                    var map   = inputsArray[i];
                    var field = inputSocketFields[map.ConnectionId];
                    nodeInformation.Inputs.Add(field.Name, SocketInformation.Construct(field, map));
                }
            }
            else
            {
                nodeInformation.Inputs = null;
            }

            if (outputsArray != null)
            {
                nodeInformation.Outputs = new Dictionary <string, SocketInformation>(outputsArray.Length);

                for (int i = 0; i < outputsArray.Length; i++)
                {
                    var map   = outputsArray[i];
                    var field = outputSocketFields[map.ConnectionId];
                    nodeInformation.Outputs.Add(field.Name, SocketInformation.Construct(field, map));
                }
            }
            else
            {
                nodeInformation.Outputs = null;
            }

            return(nodeInformation);
        }
コード例 #7
0
ファイル: NodeInformation.cs プロジェクト: leelnfei/RPGCore
        public static NodeInformation ConstructNodeInformation(Type nodeType)
        {
            var nodeInformation = new NodeInformation();

            var    typeDefinition   = new Type[] { typeof(IGraphConnections) };
            var    nodeTemplate     = (Node)Activator.CreateInstance(nodeType);
            object metadataInstance = nodeTemplate.CreateInstance();

            var instanceType = metadataInstance.GetType();

            var inputsProperty  = instanceType.GetMethod("Inputs", typeDefinition);
            var outputsProperty = instanceType.GetMethod("Outputs", typeDefinition);

            var singleNodeGraph = new ManifestCaptureGraphInstance(nodeTemplate);

            int inputId            = 0;
            int outputId           = 0;
            var inputSocketFields  = new List <FieldInfo> ();
            var outputSocketFields = new List <FieldInfo> ();
            var fieldInfos         = new Dictionary <string, FieldInformation> ();

            foreach (var field in nodeType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (field.FieldType == typeof(OutputSocket))
                {
                    field.SetValue(nodeTemplate, new OutputSocket(outputId));
                    outputId++;
                    outputSocketFields.Add(field);
                }
                else
                {
                    if (field.FieldType == typeof(InputSocket))
                    {
                        field.SetValue(nodeTemplate, new InputSocket(inputId));
                        inputId++;
                        inputSocketFields.Add(field);
                    }
                    fieldInfos.Add(field.Name, FieldInformation.ConstructFieldInformation(field, nodeTemplate));
                }
            }
            nodeInformation.Fields = fieldInfos;

            var nodeProperty = instanceType.GetProperty("Node");

            nodeProperty.SetValue(metadataInstance, nodeTemplate);

            object[] connectParameters = { singleNodeGraph };
            var      inputsArray       = (InputMap[])inputsProperty.Invoke(metadataInstance, connectParameters);
            var      outputsArray      = (OutputMap[])outputsProperty.Invoke(metadataInstance, connectParameters);

            if (inputsArray != null)
            {
                nodeInformation.Inputs = new Dictionary <string, SocketInformation> (inputsArray.Length);

                for (int i = 0; i < inputsArray.Length; i++)
                {
                    var map   = inputsArray[i];
                    var field = inputSocketFields[map.ConnectionId];
                    nodeInformation.Inputs.Add(field.Name, SocketInformation.Construct(field, map));
                }
            }
            else
            {
                nodeInformation.Inputs = null;
            }

            if (outputsArray != null)
            {
                nodeInformation.Outputs = new Dictionary <string, SocketInformation> (outputsArray.Length);

                for (int i = 0; i < outputsArray.Length; i++)
                {
                    var map   = outputsArray[i];
                    var field = outputSocketFields[map.ConnectionId];
                    nodeInformation.Outputs.Add(field.Name, SocketInformation.Construct(field, map));
                }
            }
            else
            {
                nodeInformation.Outputs = null;
            }

            return(nodeInformation);
        }