Exemple #1
0
 public NodeFieldInformation(FieldInfo info, string name, bool input, bool isMultiple, CustomPortBehaviorDelegate behavior)
 {
     this.input      = input;
     this.isMultiple = isMultiple;
     this.info       = info;
     this.name       = name;
     this.fieldName  = info.Name;
     this.behavior   = behavior;
 }
Exemple #2
0
        void InitializeInOutDatas()
        {
            var fields  = GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var methods = GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            foreach (var field in fields)
            {
                var    inputAttribute  = field.GetCustomAttribute <InputAttribute>();
                var    outputAttribute = field.GetCustomAttribute <OutputAttribute>();
                bool   isMultiple      = false;
                bool   input           = false;
                string name            = field.Name;

                if (inputAttribute == null && outputAttribute == null)
                {
                    continue;
                }

                //check if field is a collection type
                isMultiple = (inputAttribute != null) ? inputAttribute.allowMultiple : false;
                input      = inputAttribute != null;

                if (!String.IsNullOrEmpty(inputAttribute?.name))
                {
                    name = inputAttribute.name;
                }
                if (!String.IsNullOrEmpty(outputAttribute?.name))
                {
                    name = outputAttribute.name;
                }

                // By default we set the behavior to null, if the field have a custom behavior, it will be set in the loop just below
                nodeFields[field.Name] = new NodeFieldInformation(field, name, input, isMultiple, null);
            }

            foreach (var method in methods)
            {
                var customPortBehaviorAttribute     = method.GetCustomAttribute <CustomPortBehaviorAttribute>();
                CustomPortBehaviorDelegate behavior = null;

                if (customPortBehaviorAttribute == null)
                {
                    continue;
                }

                // Check if custom port behavior function is valid
                try {
                    var referenceType = typeof(CustomPortBehaviorDelegate);
                    behavior = (CustomPortBehaviorDelegate)Delegate.CreateDelegate(referenceType, this, method, true);
                } catch {
                    Debug.LogError("The function " + method + " can be converted to the required delegate format: " + typeof(CustomPortBehaviorDelegate));
                }

                if (nodeFields.ContainsKey(customPortBehaviorAttribute.fieldName))
                {
                    nodeFields[customPortBehaviorAttribute.fieldName].behavior = behavior;
                }
                else
                {
                    Debug.LogError("Invalid field name for custom port behavior: " + method + ", " + customPortBehaviorAttribute.fieldName);
                }
            }
        }