Beispiel #1
0
        protected override void ConstructFieldTemplates(NodeProvider nodeProvider, Dictionary <Type, NodeFieldTemplate> templates)
        {
            NodeLibrary library = nodeProvider.GetNodeLibrary();

            foreach (var nodeTemplate in library.nodeTemplates)
            {
                Type type = nodeTemplate.RuntimeNodeType;

                var template = new NodeFieldTemplate();
                var fields   = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                foreach (var field in fields)
                {
                    bool isPrivate = field.IsPrivate;

                    if (IsOutput(field))
                    {
                        template.OutputPorts.Add(new Ports.PortDescription(field.Name, field.FieldType, PortDirection.Output, false, false));
                    }
                    else if (IsInput(field))
                    {
                        template.OutputPorts.Add(new Ports.PortDescription(field.Name, field.FieldType, PortDirection.Input, false, false));
                    }
                    else
                    {
                        template.Properties.Add(new PropertyDescription {
                            FieldType = field
                        });
                    }
                }

                templates.Add(type, template);
            }
        }
Beispiel #2
0
        protected override void ConstructFieldTemplates(NodeProvider nodeProvider, Dictionary <Type, NodeFieldTemplate> templates)
        {
            NodeLibrary library = nodeProvider.GetNodeLibrary();

            foreach (var nodeTemplate in library.nodeTemplates)
            {
                Type type     = nodeTemplate.RuntimeNodeType;
                var  fields   = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                var  template = new NodeFieldTemplate();

                var supressInput = type.GetCustomAttribute <SupressInputAttribute>();

                // All tasks (nodes in this case) need to have an input, that isnt in the code of the behaviours
                // so we just add it in the first thing we do.
                if (supressInput == null)
                {
                    template.InputPorts.Add(new PortDescription("Input", typeof(Task), PortDirection.Input, false, false));
                }

                foreach (var field in fields)
                {
                    OutputAttribute output   = field.GetCustomAttribute <OutputAttribute>();
                    InputAttribute  input    = field.GetCustomAttribute <InputAttribute>();
                    SerializeField  property = field.GetCustomAttribute <SerializeField>();

                    bool autoAdd  = false;
                    bool isInput  = input == null ? false : true;
                    bool isOutput = output == null ? false : true;

                    if (output != null)
                    {
                        autoAdd = output.AutoAddPortOnConnect;
                    }
                    if (input != null)
                    {
                        autoAdd = input.AutoAddPortOnConnect;
                    }

                    bool isList = IsListType(field);

                    if (output != null || input != null)
                    {
                        if (IsListType(field))
                        {
                            AddGenericPort(template, field, isInput, isOutput, autoAdd);
                        }
                        else
                        {
                            AddNonGenericPort(template, field.FieldType, field.Name, field.Name, isInput, isOutput, autoAdd);
                        }
                    }
                    else if (property != null)
                    {
                        AddNonGenericProperty(template, field, field.Name, field.Name);
                    }
                }
                templates.Add(type, template);
            }
        }
Beispiel #3
0
 private void AddNonGenericPort(NodeFieldTemplate template, Type type, string memberName, string displayName, bool isInput, bool isOutput, bool autoAddPortOnConnect)
 {
     if (isOutput)
     {
         template.OutputPorts.Add(new PortDescription("Output", type, PortDirection.Output, false, autoAddPortOnConnect));
     }
     else if (isInput)
     {
         template.InputPorts.Add(new PortDescription("Input", type, PortDirection.Input, false, autoAddPortOnConnect));
     }
     else
     {
         Debug.LogError($"Port {memberName} has to be either an input or an ouput!");
     }
 }
Beispiel #4
0
 private void AddNonGenericProperty(NodeFieldTemplate template, FieldInfo field, string memberName, string displayName)
 {
     template.Properties.Add(new PropertyDescription {
         FieldType = field
     });
 }
Beispiel #5
0
        private void AddGenericPort(NodeFieldTemplate template, FieldInfo field, bool isInput, bool isOutput, bool autoAddPortOnConnect)
        {
            var innerFieldType = field.FieldType.GetGenericArguments()[0];

            AddNonGenericPort(template, innerFieldType, innerFieldType.Name, innerFieldType.Name, isInput, isOutput, autoAddPortOnConnect);
        }