コード例 #1
0
        public static void PortPair(INodePort input, INodePort output,
                                    NodeGuiLayoutStyle intputStyle, NodeGuiLayoutStyle outputStyle)
        {
            GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));

            PortField(input, intputStyle);
            PortField(output, outputStyle);

            GUILayout.EndHorizontal();
        }
コード例 #2
0
        public static NodeGuiLayoutStyle GetDefaultPortStyle(INodePort port)
        {
            var name  = port == null ? string.Empty : port.ItemName;
            var label = port == null ? new GUIContent(string.Empty) : new GUIContent(port.ItemName);

            var style = new NodeGuiLayoutStyle()
            {
                Color      = GetMainPortColor(port),
                Background = GetBackgroundPortColor(port),
                Options    = new GUILayoutOption[] { GUILayout.MinWidth(30) },
                Label      = label,
                Name       = name,
            };

            return(style);
        }
コード例 #3
0
        public static void PortField(INodePort port, NodeGuiLayoutStyle portStyle)
        {
            if (port == null)
            {
                return;
            }

            if (portStyle.Options == null)
            {
                portStyle.Options = new GUILayoutOption[] { GUILayout.MinWidth(30) }
            }
            ;

            Vector2 position = Vector3.zero;

            portStyle.Label = portStyle.Label != null ? portStyle.Label
                : string.IsNullOrEmpty(portStyle.Name) ? new GUIContent(ObjectNames.NicifyVariableName(port.ItemName))
                : new GUIContent(portStyle.Name);

            // If property is an input, display a regular property field and put a port handle on the left side
            if (port.Direction == PortIO.Input)
            {
                // Display a label
                EditorGUILayout.LabelField(portStyle.Label, portStyle.Options);

                var rect = GUILayoutUtility.GetLastRect();
                position = rect.position - new Vector2(16, 0);
            }
            // If property is an output, display a text label and put a port handle on the right side
            else if (port.Direction == PortIO.Output)
            {
                // Display a label
                EditorGUILayout.LabelField(portStyle.Label, NodeEditorResources.OutputPort, portStyle.Options);
                var rect = GUILayoutUtility.GetLastRect();
                position = rect.position + new Vector2(rect.width, 0);
            }

            PortField(position, port, portStyle.Color, portStyle.Background);
        }