Beispiel #1
0
        public static string    OpenFolderField(string label, string path, FieldButtons buttons = FieldButtons.All)
        {
            EditorGUILayout.BeginHorizontal();
            {
                path = EditorGUILayout.TextField(label, path);

                if ((buttons & FieldButtons.Browse) != 0)
                {
                    Utility.content.text = "Browse";
                    Rect r = GUILayoutUtility.GetRect(Utility.content, buttons == FieldButtons.All ? "ButtonLeft" : GUI.skin.button, GUILayoutOptionPool.ExpandWidthFalse);
                    r.y -= 2F;
                    if (GUI.Button(r, Utility.content, buttons == FieldButtons.All ? "ButtonLeft" : GUI.skin.button) == true)
                    {
                        path = string.IsNullOrEmpty(path) == false ? path : EditorPrefs.GetString(NGEditorGUILayout.LastOpenFolderPathKeyPref);
                        string projectPath = EditorUtility.OpenFolderPanel(label, path, string.Empty);

                        if (string.IsNullOrEmpty(projectPath) == false)
                        {
                            EditorPrefs.SetString(NGEditorGUILayout.LastOpenFolderPathKeyPref, Path.GetDirectoryName(projectPath));
                            path = projectPath;
                            GUI.FocusControl(null);
                        }
                    }
                }

                if ((buttons & FieldButtons.Open) != 0)
                {
                    EditorGUI.BeginDisabledGroup(false);
                    {
                        GUI.enabled          = true;
                        Utility.content.text = "Open";
                        Rect r = GUILayoutUtility.GetRect(Utility.content, buttons == FieldButtons.All ? "ButtonRight" : GUI.skin.button, GUILayoutOptionPool.ExpandWidthFalse);
                        r.y -= 2F;
                        if (GUI.Button(r, Utility.content, buttons == FieldButtons.All ? "ButtonRight" : GUI.skin.button) == true)
                        {
                            EditorUtility.RevealInFinder(path);
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
            }
            EditorGUILayout.EndHorizontal();

            return(path);
        }
Beispiel #2
0
 public static string    OpenFolderField(Rect r, string label, string path, FieldButtons buttons = FieldButtons.All)
 {
     return(NGEditorGUILayout.OpenFolderField(r, label, path, string.Empty, buttons));
 }
Beispiel #3
0
        public static string    SaveFileField(Rect r2, string label, string path, string defaultName = "", string extension = "", FieldButtons buttons = FieldButtons.All)
        {
            Rect rBrowse = new Rect(r2.x, r2.y, r2.width, r2.height);
            Rect rOpen   = new Rect(r2.x, r2.y, r2.width, r2.height);

            if ((buttons & FieldButtons.Browse) != 0)
            {
                Utility.content.text = "Browse";
                rBrowse.width        = (buttons == FieldButtons.All ? "ButtonLeft" : GUI.skin.button).CalcSize(Utility.content).x;
                r2.width            -= rBrowse.width;
            }

            if ((buttons & FieldButtons.Open) != 0)
            {
                Utility.content.text = "Open";
                rOpen.width          = (buttons == FieldButtons.All ? "ButtonRight" : GUI.skin.button).CalcSize(Utility.content).x;
                r2.width            -= rOpen.width;
            }

            path = EditorGUI.TextField(r2, label, path);

            if ((buttons & FieldButtons.Browse) != 0)
            {
                rBrowse.x            = r2.xMax;
                r2.xMax              = rBrowse.xMax;
                Utility.content.text = "Browse";
                //Rect	r = GUILayoutUtility.GetRect(Utility.content, buttons == FieldButtons.All ? "ButtonLeft" : GUI.skin.button, GUILayoutOptionPool.ExpandWidthFalse);
                //r.y -= 2F;
                if (GUI.Button(rBrowse, Utility.content, buttons == FieldButtons.All ? "ButtonLeft" : GUI.skin.button) == true)
                {
                    string directory = string.IsNullOrEmpty(path) == false?Path.GetDirectoryName(path) : EditorPrefs.GetString(NGEditorGUILayout.LastSaveFilePathKeyPref);

                    string projectPath = EditorUtility.SaveFilePanel(label, directory, defaultName, extension);

                    if (string.IsNullOrEmpty(projectPath) == false)
                    {
                        EditorPrefs.SetString(NGEditorGUILayout.LastSaveFilePathKeyPref, Path.GetDirectoryName(projectPath));
                        path = projectPath;
                        GUI.FocusControl(null);
                    }
                }
            }

            if ((buttons & FieldButtons.Open) != 0)
            {
                rOpen.x = r2.xMax;
                EditorGUI.BeginDisabledGroup(false);
                {
                    GUI.enabled          = true;
                    Utility.content.text = "Open";
                    //Rect	r = GUILayoutUtility.GetRect(Utility.content, buttons == FieldButtons.All ? "ButtonRight" : GUI.skin.button, GUILayoutOptionPool.ExpandWidthFalse);
                    //r.y -= 2F;
                    if (GUI.Button(rOpen, Utility.content, buttons == FieldButtons.All ? "ButtonRight" : GUI.skin.button) == true)
                    {
                        EditorUtility.RevealInFinder(path);
                    }
                }
                EditorGUI.EndDisabledGroup();
            }

            return(path);
        }
Beispiel #4
0
        public static string    OpenFolderField(Rect r, string label, string path, string prefixPath, FieldButtons buttons = FieldButtons.All)
        {
            float browseWidth = 0F;
            float openWidth   = 0F;

            if ((buttons & FieldButtons.Browse) != 0)
            {
                Utility.content.text = "Browse";
                browseWidth          = 55F;
            }

            if ((buttons & FieldButtons.Open) != 0)
            {
                Utility.content.text = "Open";
                openWidth            = 45F;
            }

            r.width  -= browseWidth + openWidth;
            path      = EditorGUI.TextField(r, label, path);
            r.x      += r.width;
            r.y      -= 1F;
            r.height += 1F;

            if ((buttons & FieldButtons.Browse) != 0)
            {
                r.width = browseWidth;
                if (GUI.Button(r, "Browse", buttons == FieldButtons.All ? "ButtonLeft" : GUI.skin.button) == true)
                {
                    path = string.IsNullOrEmpty(path) == false ? path : EditorPrefs.GetString(NGEditorGUILayout.LastOpenFolderPathKeyPref);
                    string projectPath = EditorUtility.OpenFolderPanel(label, Path.Combine(prefixPath, path), string.Empty);

                    if (string.IsNullOrEmpty(projectPath) == false)
                    {
                        EditorPrefs.SetString(NGEditorGUILayout.LastOpenFolderPathKeyPref, Path.GetDirectoryName(projectPath));
                        path = projectPath;
                        GUI.FocusControl(null);
                    }
                }
                r.x += r.width;
            }

            if ((buttons & FieldButtons.Open) != 0)
            {
                EditorGUI.BeginDisabledGroup(false);
                {
                    GUI.enabled = true;
                    r.width     = openWidth;
                    if (GUI.Button(r, "Open", buttons == FieldButtons.All ? "ButtonRight" : GUI.skin.button) == true)
                    {
                        EditorUtility.RevealInFinder(Path.Combine(prefixPath, path));
                    }
                }
                EditorGUI.EndDisabledGroup();
            }

            return(path);
        }