public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            Initialize(property);

            EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            const float tagWidth = 77;
            var         txtWidth = position.width - tagWidth - 5;
            var         txtRect  = new Rect(position.x, position.y, txtWidth, position.height);
            var         tagRect  = new Rect(position.x + txtWidth + 5, position.y, tagWidth, position.height);

            GUI.SetNextControlName("FileNameField");
            m_FileName.stringValue = GUI.TextField(txtRect, m_FileName.stringValue);
            var editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);

            if (GUI.GetNameOfFocusedControl().Equals("FileNameField") &&
                Event.current.type == EventType.KeyUp && (Event.current.modifiers == EventModifiers.Control || Event.current.modifiers == EventModifiers.Command))
            {
                if (Event.current.keyCode == KeyCode.C)
                {
                    Event.current.Use();
                    editor.Copy();
                }
                else if (Event.current.keyCode == KeyCode.V)
                {
                    Event.current.Use();
                    editor.Paste();
                    m_FileName.stringValue = editor.text;
                }
            }

            if (EditorGUI.DropdownButton(tagRect, new GUIContent("+ Wildcards"), FocusType.Passive))
            {
                var menu = new GenericMenu();

                foreach (var w in target.wildcards)
                {
                    var pattern = w.pattern;
                    menu.AddItem(new GUIContent(w.label), false, () =>
                    {
                        m_FileName.stringValue = InsertTag(pattern, m_FileName.stringValue, editor);
                        m_FileName.serializedObject.ApplyModifiedProperties();
                        s_Dirty = true;
                    });
                }

                menu.DropDown(tagRect);
            }

            if (s_Dirty)
            {
                s_Dirty     = false;
                GUI.changed = true;
            }

            EditorGUILayout.PropertyField(m_Path);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");

            var path = target.BuildAbsolutePath(null);

            var r = GUILayoutUtility.GetRect(new GUIContent(path), s_PathPreviewStyle, null);

            EditorGUI.SelectableLabel(r, path, s_PathPreviewStyle);

            if (GUILayout.Button(s_OpenPathIcon, s_OpenPathButtonStyle))
            {
                OpenInFileBrowser.Open(path);
            }

            EditorGUILayout.EndHorizontal();

            EditorGUI.EndProperty();
        }
Exemple #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            Initialize(property);

            EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            const float tagWidth = 88;
            var         txtWidth = position.width - tagWidth - 5;
            var         txtRect  = new Rect(position.x, position.y, txtWidth, position.height);
            var         tagRect  = new Rect(position.x + txtWidth + 5, position.y, tagWidth, position.height);

            GUI.SetNextControlName("FileNameField");
            m_FileName.stringValue = RecorderEditor.FromRecorderWindow
                ? EditorGUI.TextField(txtRect, m_FileName.stringValue)
                : EditorGUI.DelayedTextField(txtRect, m_FileName.stringValue);
            var editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);

            if (GUI.GetNameOfFocusedControl().Equals("FileNameField") &&
                Event.current.type == EventType.KeyUp && (Event.current.modifiers == EventModifiers.Control || Event.current.modifiers == EventModifiers.Command))
            {
                if (Event.current.keyCode == KeyCode.C)
                {
                    Event.current.Use();
                    editor.Copy();
                }
                else if (Event.current.keyCode == KeyCode.V)
                {
                    Event.current.Use();
                    editor.Paste();
                    m_FileName.stringValue = editor.text;
                }
            }

            GUI.SetNextControlName("FileNameTagPopup");
            if (EditorGUI.DropdownButton(tagRect, new GUIContent("+ Wildcards", "Insert a placeholder at the cursor position to include auto-generated text data from your current recording context"), FocusType.Passive))
            {
                GUI.FocusControl("FileNameTagPopup");
                var menu = new GenericMenu();

                foreach (var w in target.wildcards)
                {
                    var pattern = w.pattern;
                    menu.AddItem(new GUIContent(w.label), false, () =>
                    {
                        m_FileName.stringValue = InsertTag(pattern, m_FileName.stringValue, editor);
                        m_FileName.serializedObject.ApplyModifiedProperties();
                        s_Dirty = true;
                    });
                }

                menu.DropDown(tagRect);
            }

            if (s_Dirty)
            {
                s_Dirty     = false;
                GUI.changed = true;
            }

            EditorGUI.indentLevel = indent;
            EditorGUILayout.PropertyField(m_Path);
            EditorGUI.indentLevel = 0;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(" ");

            var path = target.BuildAbsolutePath(null);

            GUILayoutOption[] op = new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(true),
                GUILayout.ExpandHeight(true)
            };

            var r = GUILayoutUtility.GetRect(new GUIContent(path), s_PathPreviewStyle, op);

            EditorGUI.SelectableLabel(r, path, s_PathPreviewStyle);

            if (GUILayout.Button(new GUIContent(s_OpenPathIcon, "Open the output location in your file browser"),
                                 s_OpenPathButtonStyle))
            {
                try
                {
                    var fiOutput = new FileInfo(path);
                    var dir      = fiOutput.Directory;
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                }
                catch (ArgumentNullException)
                {
                    // An error occured, most likely because the path was null
                    Debug.LogWarning($"Error opening location {path} in the file browser.");
                }
                OpenInFileBrowser.Open(path);
            }

            EditorGUILayout.EndHorizontal();

            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }