Exemplo n.º 1
0
        private void DrawElement
            (Rect rect, int index, bool isActive, bool isFocused)
        {
            var item = (Variable)list.list[index];

            var width  = rect.width;
            var height = rect.height;

            rect.y     += EditorGUIUtility.standardVerticalSpacing;
            rect.height = EditorGUIUtility.singleLineHeight;
            XGUI.ResetToStyle(GUI.skin.label);
            XGUI.RichText = true;
            var str = item.Value == null ? null : item.Value.TypeString;

            XGUI.Label(rect, string.Format("<b>{0}</b> <i>{1}</i>", item.Name, str));

            rect.y     += rect.height + EditorGUIUtility.standardVerticalSpacing;
            rect.height = height - EditorGUIUtility.singleLineHeight
                          - EditorGUIUtility.standardVerticalSpacing * 4;

            EditorGUI.BeginChangeCheck();

            var type = item.Value == null
                                ? null : Type.GetType(item.Value.TypeString);

            if (type != null)
            {
                if (typeof(UnityEngine.Object).IsAssignableFrom(type))
                {
                    item.Value.Value = EditorGUI.ObjectField(rect, (UnityEngine.Object)item.Value.Value, type, true);
                }
                else
                {
                    var oldValue = item.Value.Value;
                    var newValue = GUIExtension.DrawField(rect, oldValue, type, XGUI.None, true);
                    item.Value.Value = newValue;
                }
            }
            else
            {
                XGUI.ResetToStyle(GUI.skin.label);
                XGUI.Enabled = false;
                XGUI.TextField(rect, "Unknown Type");
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(editor.Graph);
            }
        }
Exemplo n.º 2
0
        private static void DrawMember
            (bool isInput, GraphEditor editor, Node node, ref Rect rect,
            SerializedObject serializedObject, Socket socket)
        {
            string name     = node.GetSocketDisplayName(socket);
            bool   editable = node.GetSocketFlags(socket).IsEditable();
            bool   linked   = editor.Graph.Links.IsSocketLinkedTo(socket);

            rect.height = EditorGUIUtility.singleLineHeight;

            XGUI.ResetToStyle(null);
            XGUI.Normal.textColor = GraphEditor.Skin.nodeTextColor;

            if (editor.search.IsOpen)
            {
                XGUI.Normal.textColor = GraphEditor.Skin.TintColor(
                    XGUI.Normal.textColor, GraphEditor.Skin.disabledNodeTextTint);
            }

            var clipboardHasValue = false;
            var hovering          = rect.Contains(Event.current.mousePosition) &&
                                    !editor.search.IsOpen;

            if (editable && !linked)
            {
                var type  = node.GetSocketType(socket);
                var value = node.GetSocketValue(socket);
                clipboardHasValue = editor.Clipboard.ContainsKey(type);

                // Check for clipboard operations
                if (hovering)
                {
                    switch (Event.current.type)
                    {
                    case EventType.MouseDown:
                        if (Event.current.shift)
                        {
                            if (Event.current.button == 0)
                            {
                                usedClipboard = true;
                                if (clipboardHasValue)
                                {
                                    value = editor.Clipboard[type];
                                    node.SetSocketValue(socket, value);
                                }
                            }
                            else if (Event.current.button == 1)
                            {
                                usedClipboard          = true;
                                editor.Clipboard[type] = value;
                            }

                            Event.current.Use();
                        }
                        break;

                    case EventType.MouseUp:
                        if (usedClipboard)
                        {
                            usedClipboard = false;
                            Event.current.Use();
                        }
                        break;
                    }
                }

                XGUI.Enabled = !editor.search.IsOpen;
                var prop = serializedObject.FindProperty(socket.FieldName);
                if (type == typeof(bool))
                {
                    value = XGUI.ToggleLeft(rect, name, (bool)value);
                    node.SetSocketValue(socket, value);
                }
                else if (prop != null)
                {
                    EditorGUI.PropertyField(rect, prop, GUIContent.none, true);
                }
                else if (type == null)
                {
                    XGUI.Enabled = false;
                    XGUI.TextField(rect, "Unknown Type");
                }
                else
                {
                    value = GUIExtension.DrawField
                                (rect, value, type, GUIContent.none, true);
                    node.SetSocketValue(socket, value);
                }
            }
            else
            {
                XGUI.Label(rect, name);
            }

            // Prepare a tooltip
            if (hovering && editor.Tooltip == null)
            {
                var text = string.Format(
                    "<color=#4aa><i>{0}</i></color> <b>{1}</b>\n{2}{3}{4}",
                    node.GetSocketType(socket).Name,
                    node.GetSocketDisplayName(socket),
                    string.IsNullOrEmpty(node.GetSocketDescription(socket))
                                                ? "<color=#aaa><i>No documentation</i></color>"
                                                : node.GetSocketDescription(socket),
                    (editable && !linked ? "\n<color=#777><i>Shift + Right click to copy</i></color>" : ""),
                    (clipboardHasValue ? "\n<color=#777><i>Shift + Left click to paste</i></color>" : "")
                    );
                editor.Tooltip = new Tooltip(text);
            }
        }
Exemplo n.º 3
0
        void OnGUI()
        {
            if (list == null || list.Equals(null))
            {
                Close();
                return;
            }

            XGUI.ResetToStyle(null);
            XGUI.BeginVertical();

            XGUI.ResetToStyle(GUI.skin.textField);

            XGUI.LabelWidth = 40;
            varName         = XGUI.TextField("Name", varName);
            typeStr         = XGUI.TextField("Type", typeStr);

            XGUI.ResetToStyle(null);
            XGUI.BeginHorizontal();

            XGUI.ResetToStyle(GUI.skin.button);
            if (XGUI.Button("Cancel"))
            {
                Close();
                return;
            }

            XGUI.Enabled = IsValid();
            if (XGUI.Button("Create"))
            {
                var value = new DynamicValue();
                value.TypeString = typeStr;
                list.list.Add(new Variable(varName, value));
                editor.SaveList();
                Close();
                return;
            }

            XGUI.EndHorizontal();

            if (!IsNameValid())
            {
                EditorGUILayout.HelpBox(
                    "Variable name is empty!",
                    MessageType.Warning);
            }
            else if (!IsNameUnique())
            {
                EditorGUILayout.HelpBox(
                    "Variable name is the same as an existing variable!",
                    MessageType.Warning);
            }
            else if (!IsTypeValid())
            {
                EditorGUILayout.HelpBox(
                    "Variable type does not exist!",
                    MessageType.Warning);
            }

            XGUI.EndVertical();
        }
Exemplo n.º 4
0
        public void OnGUI(GraphEditor editor)
        {
            if (editor.Target != this)
            {
                Close();
                return;
            }
            if (!isOpen)
            {
                return;
            }

            GUI.enabled = true;

            var rect = new Rect();

            rect.size   = size;
            rect.center = position + new Vector2(0, rect.size.y / 2);
            XGUI.ResetToStyle(GUI.skin.box);
            XGUI.Normal.background = GraphEditor.boxTexture;
            XGUI.Box(rect);

            rect.position += Vector2.one * SEARCH_PADDING;
            rect.size     -= Vector2.one * SEARCH_PADDING * 2;
            XGUI.ResetToStyle(null);
            XGUI.BeginArea(rect);
            XGUI.BeginVertical();

            if (XEvent.IsKeyDown(KeyCode.Escape))
            {
                Close();
                XEvent.Use();
            }

            // Search bar
            XGUI.BeginHorizontal();
            XGUI.ResetToStyle(GUI.skin.button);
            var buttonString = searchNodes ? "Nodes" : "Variables";

            if (XGUI.Button(buttonString, XGUI.Width(70)))
            {
                searchNodes = !searchNodes;
            }

            bool keysUsed     = false;
            var  newSearchStr = searchStr;

            if (searchNodes)
            {
                // Detect key events before the text field
                switch (Event.current.type)
                {
                case EventType.KeyDown:
                    switch (Event.current.keyCode)
                    {
                    case KeyCode.UpArrow:
                        selected--;
                        Event.current.Use();
                        break;

                    case KeyCode.DownArrow:
                        selected++;
                        Event.current.Use();
                        break;

                    case KeyCode.Home:
                        selected = 0;
                        Event.current.Use();
                        break;

                    case KeyCode.End:
                        selected = int.MaxValue;
                        Event.current.Use();
                        break;

                    case KeyCode.PageUp:
                        selected -= 11;
                        Event.current.Use();
                        break;

                    case KeyCode.PageDown:
                        selected += 11;
                        Event.current.Use();
                        break;
                    }

                    keysUsed = Event.current.type == EventType.Used;
                    break;
                }

                XGUI.ResetToStyle(GUI.skin.textField);
                GUI.SetNextControlName("search_field");
                newSearchStr = XGUI.TextField(searchStr);
                GUI.FocusControl("search_field");

                var countStr = "" + resultCount;
                if (searchJob != null && searchJob.IsRunning)
                {
                    countStr += "...";
                }
                GUILayout.Label(countStr, GUILayout.ExpandWidth(false));
            }
            GUILayout.EndHorizontal();

            var hoveringOnResult = false;

            if (searchNodes)
            {
                hoveringOnResult = DrawNodeResults(editor, newSearchStr, keysUsed);
            }
            else
            {
                DrawVariableResults(editor);
            }

            GUILayout.EndVertical();
            GUILayout.EndArea();

            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (hoveringOnResult)
                {
                    SelectResult(editor, selected);
                    Close();
                }
                else if (rect.Contains(Event.current.mousePosition))
                {
                    editor.Target = this;
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (rect.Contains(Event.current.mousePosition))
                {
                    editor.Target = this;
                    Event.current.Use();
                }
                break;
            }
        }