Ejemplo n.º 1
0
        public static Color GetPortColor(Port port)
        {
            Color c;

            if (colors.TryGetValue(port.id, out c))
            {
                return(c);
            }
            else
            {
                if (port is ValuePort)
                {
                    return(colors[port.id] = GUIReferrer.GetTypeColor((port as ValuePort).valueType));
                }
                else
                {
                    return(colors[port.id] = GUIReferrer.GetTypeColor(port.type));
                }
            }
        }
Ejemplo n.º 2
0
        public void SetMethod(MethodInfo method_info, params Type[] type_args)
        {
            if (method_info == null)
            {
#if UNITY_EDITOR
                node_color = Color.red;
                DisplayMessage("Missing Method", UnityEditor.MessageType.Error);
#endif
                Debug.LogError("type method_info is null!");
                return;
            }

            this.cached_method = method_info;

            if (type_args.IsNullOrEmpty())
            {
                this.serialized_method = this.serialized_method ?? new SerializedMethod(method_info);
            }
            else
            {
                this.serialized_method = this.serialized_method ?? new SerializedMethod(method_info, type_args);
            }

            string method_name = cached_method.Name;
            this.name = method_name;

            RegisterEntryPort("In", Execute);
            this.output = RegisterExitPort("Out");

            if (method_info.ReturnType != typeof(void))
            {
                RegisterOutputValue(method_info.ReturnType, "Get", Invoke);
            }
#if UNITY_EDITOR
            node_color = GUIReferrer.GetTypeColor(method_info.ReturnType);

            ObsoleteAttribute obsolete_flag = method_info.GetAttribute <ObsoleteAttribute>(false);
            if (obsolete_flag != null)
            {
                DisplayMessage(obsolete_flag.Message, UnityEditor.MessageType.Warning);
            }
#endif

            if (method_info.IsStatic)
            {
                this.target = null;
                string title = method_name;
                if (title.Contains("get_"))
                {
                    title = title.Replace("get_", string.Empty);
                }
                else if (title.Contains("set_"))
                {
                    title = title.Replace("set_", string.Empty);
                }
                this.title = title;
            }
            else
            {
                this.target = (IInputValue)RegisterInputValue(method_info.ReflectedType, "Target");
                string title = method_name;
                if (title.Contains("get_"))
                {
                    title = /*"[Get] " + */ title.Replace("get_", string.Empty).AddSpacesToSentence();
                }
                else if (title.Contains("set_"))
                {
                    title = /*"[Set] " + */ title.Replace("set_", string.Empty).AddSpacesToSentence();
                }
                this.title = title;
            }

            parameters = new List <IInputValue>();
            foreach (ParameterInfo parameter in method_info.GetParameters())
            {
                parameters.Add((IInputValue)RegisterInputValue(parameter.ParameterType, parameter.Name.AddSpacesToSentence()));
            }
        }
Ejemplo n.º 3
0
        public void CreatePortPoints()
        {
            int     input         = 0;
            int     output        = 0;
            Vector2 port_position = Vector2.zero;

            // IInputPort
            for (int id = 0; id < this.inputs.Count; id++)
            {
                Port port = this.inputValues[id];
                if (!port.display_port)
                {
                    continue;
                }
                if (slim)
                {
                    port_position = new Vector2(5.0f, 10.0f);
                }
                else
                {
                    port_position = new Vector2(5.0f, head_height + 10.0f + (20.0f * input));
                }
                points[port.id] = new Rect(port_position, PORT_SIZE);
                if (port is ValuePort)
                {
                    colors[port.id] = GUIReferrer.GetTypeColor((port as ValuePort).valueType);
                }
                else
                {
                    colors[port.id] = GUIReferrer.GetTypeColor(port.type);
                }
                input++;
            }

            // IOutputPort
            for (int id = 0; id < this.outputs.Count; id++)
            {
                Port port = this.outputValues[id];
                if (!port.display_port)
                {
                    continue;
                }
                if (slim)
                {
                    port_position = new Vector2(size.x - 23.0f, 10.0f);
                }
                else
                {
                    port_position = new Vector2(size.x - 23.0f, head_height + 10.0f + (20.0f * output));
                }
                points[port.id] = new Rect(port_position, PORT_SIZE);
                if (port is ValuePort)
                {
                    colors[port.id] = GUIReferrer.GetTypeColor((port as ValuePort).valueType);
                }
                else
                {
                    colors[port.id] = GUIReferrer.GetTypeColor(port.type);
                }
                output++;
            }
        }
Ejemplo n.º 4
0
        public void GenerateContent()
        {
            if (this is IValueNode)
            {
                node_color = GUIReferrer.GetTypeColor(((IValueNode)this).valueType);
            }
            else if (!((this is ReflectedNode)))
            {
                node_color = GUIReferrer.GetTypeColor(type);
            }
            if (this is IVariable)
            {
                this.title = (this as IVariable).GetVariableName();
            }

            TitleAttribute flag_title = type.GetAttribute <TitleAttribute>(false);

            if (flag_title != null)
            {
                this.title = flag_title.title;
            }
            SubtitleAttribute flag_subtitle = type.GetAttribute <SubtitleAttribute>(true);

            if (flag_subtitle != null)
            {
                this.subtitle = flag_subtitle.subtitle;
            }
            IconAttribute flag_icon = type.GetAttribute <IconAttribute>(false);

            if (flag_icon != null)
            {
                this.icon = flag_icon.GetIcon();
            }
            SlimAttribute flag_slim = type.GetAttribute <SlimAttribute>(false);

            this.slim = flag_slim != null && flag_slim.is_slim;

            if (this is EventNode)
            {
                if (this.subtitle.IsNullOrEmpty())
                {
                    this.subtitle = "Event";
                }
            }
            else if (this is ReflectedNode)
            {
                invert_title = true;
                MethodInfo method = ((ReflectedNode)this).cached_method;
                if (method != null)
                {
                    Type reflected_type = ((ReflectedNode)this).cached_method.ReflectedType;
                    if (this.subtitle.IsNullOrEmpty())
                    {
                        this.subtitle = reflected_type.GetTypeName();
                    }
                    this.icon = this.icon ?? GUIReferrer.GetTypeIcon(reflected_type);
                }
                else
                {
                    this.title = "Missing Method";
                    this.icon  = styles.error_icon;
                }
            }
            if (this is IValueNode)
            {
                this.icon = this.icon ?? GUIReferrer.GetTypeIcon(((IValueNode)this).valueType);
            }
            if (this.title.IsNullOrEmpty())
            {
                if (this is IValueNode)
                {
                    this.title = (this as IValueNode).valueType.GetTypeName(false, true);
                }
                else
                {
                    this.title = this.name;
                }
            }
            this.icon    = this.icon ?? GUIReferrer.GetTypeIcon(type);
            has_subtitle = !subtitle.IsNullOrEmpty();
        }