Beispiel #1
0
        // ListItemClick for ReorderableList
        protected void ListItemClick(ReorderableList <UnityEngine.Object> list, UnityEngine.Object item)
        {
            if (item is ShelfSceneReference)
            {
                var reference = (item as ShelfSceneReference).Resolve();
                Selection.activeObject = reference;
            }
            else
            {
                var path        = AssetDatabase.GetAssetPath(item);
                var isDirectory = false;
                if (!string.IsNullOrEmpty(path))
                {
                    path        = Application.dataPath + "/../" + path;
                    isDirectory = Directory.Exists(path);
                }

                if (isDirectory)
                {
                    // Try to show the folder's contents in Unity 4's two-column
                    // project view instead of the parent folder's contents.
                    bool success           = false;
                    var  objectBrowserType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ProjectBrowser");
                    if (objectBrowserType != null)
                    {
                        //var objectBrowser = EditorWindow.GetWindow(objectBrowserType);
                        var browsers = Resources.FindObjectsOfTypeAll(objectBrowserType);
                        if (browsers.Length == 0)
                        {
                            Debug.LogError("Shelf: Project browser not open, please open it to jump to folders.");
                        }
                        else
                        {
                            var field = objectBrowserType.GetField("m_ViewMode", bindingFlags);
                            if (field != null)
                            {
                                var viewMode = (int)field.GetValue(browsers[0]);
                                if (viewMode == 1)
                                {
                                    var method = objectBrowserType.GetMethod("ShowFolderContents", bindingFlags);
                                    if (method != null)
                                    {
                                        (browsers[0] as EditorWindow).Focus();
                                        method.Invoke(browsers[0], new object[] { item.GetInstanceID(), true });
                                        success = true;
                                    }
                                }
                            }
                        }
                    }

                    // Fall back to just pinging the folder
                    if (!success)
                    {
                        EditorGUIUtility.PingObject(item);
                    }
                }
                else if (path.EndsWith(".unity"))
                {
                    var goahead = true;
                    goahead = EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
                    if (goahead)
                    {
                        OpenSceneDelayed(AssetDatabase.GetAssetPath(item));
                    }
                }
                else
                {
                    Selection.activeObject = item;
                }
            }
        }
Beispiel #2
0
 // ListItemName for ReorderableList
 protected string ListItemName(ReorderableList <UnityEngine.Object> list, UnityEngine.Object item)
 {
     return(ListItemContent(list, item).text);
 }
Beispiel #3
0
        // Preferences DrawListItem for ReorderableList
        protected static void PreferencesDrawListItem(ReorderableList <ShelfLayer> list, ShelfLayer item)
        {
            EditorGUILayout.BeginHorizontal(GUI.skin.box);
            {
                // Stop editing an items name if enter or return is pressed
                if (editItemName == item &&
                    Event.current.type == EventType.KeyDown &&
                    (Event.current.keyCode == KeyCode.Return ||
                     Event.current.keyCode == KeyCode.KeypadEnter))
                {
                    editItemName = null;
                    Event.current.Use();
                }

                // Layer name
                if (editItemName != item)
                {
                    GUILayout.Label(item.name, GUILayout.ExpandWidth(true));
                }
                else
                {
                    var newName = GUILayout.TextField(item.name, GUILayout.ExpandWidth(true));
                    if (newName != item.name)
                    {
                        Undo.RecordObject(Data, "Rename Shelf Layer Name");
                        item.name = newName;
                        EditorUtility.SetDirty(Data);
                    }
                }

                // Rename button
                var content = new GUIContent("...", "Rename Layer");
                if (GUILayout.Button(content, "label", GUILayout.Width(15)))
                {
                    if (editItemName == item)
                    {
                        editItemName = null;
                    }
                    else
                    {
                        editItemName = item;
                    }
                }

                // Delete button
                content = new GUIContent("x", "Delete Layer");
                var delete = GUILayout.Button(content, "label", GUILayout.Width(10));

                if (delete && item.objects != null && item.objects.Count > 0)
                {
                    delete = EditorUtility.DisplayDialog(
                        "Shelf",
                        "Are you shure you want to delete '" + item.name + "'?",
                        "Delete", "Cancel"
                        );
                }

                if (delete)
                {
                    list.RemoveItem(item);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
Beispiel #4
0
 // Preferences ListItemName for ReorderableList
 protected static string PreferencesListItemName(ReorderableList <ShelfLayer> list, ShelfLayer item)
 {
     return(item.name);
 }
Beispiel #5
0
 // Preferences ReorderableList.objectReferenceCallback
 protected static UnityEngine.Object[] PreferencesLayersReferences(ReorderableList <ShelfLayer> list, ShelfLayer[] layers)
 {
     // Use the editor itself as stand-in for proper drag events
     return(new UnityEngine.Object[] { Data });
 }
Beispiel #6
0
        protected static void ShelfPreferences()
        {
#if ENABLE_HACKS && PREFERENCES_WINDOW_REDRAW_HACK
            // HACK: Get private PreferencesWindow to type to get a
            // reference of the preferences window to trigger its redraw
            if (!inlinePrefs && preferencesWindow == null)
            {
                var prefWindowType = typeof(EditorApplication).Assembly.GetType("UnityEditor.PreferencesWindow");
                if (prefWindowType != null)
                {
                    preferencesWindow = EditorWindow.GetWindow(prefWindowType);
                }
            }
#endif

            if (Data == null)
            {
                return;
            }

            // Initialize reorderable list used to edit shelf layers
            if (preferencesList == null)
            {
                preferencesList = new ReorderableList <ShelfLayer>();
                preferencesList.allowMultiSelection      = false;
                preferencesList.undoTarget               = Data;
                preferencesList.objectReferencesCallback = PreferencesLayersReferences;
                preferencesList.listItemNameCallback     = PreferencesListItemName;
                preferencesList.listItemDrawCallback     = PreferencesDrawListItem;
                preferencesList.List = Data.layers;
            }

            EditorGUILayout.LabelField("Drag layers to reorder:");

            if (preferencesList.OnGUI())
            {
#if ENABLE_HACKS && PREFERENCES_WINDOW_REDRAW_HACK
                if (!inlinePrefs && preferencesWindow != null)
                {
                    preferencesWindow.Repaint();
                }
#endif
                if (editorInstance != null)
                {
                    editorInstance.Repaint();
                }
            }

            // Make sure the selected shelf index stays valid
            if (Data.currentLayer >= Data.layers.Count)
            {
                Data.currentLayer = Data.layers.Count - 1;
            }

            EditorGUILayout.Space();

            // Add new layer
            if (GUILayout.Button("Add Layer"))
            {
                Data.layers.Add(new ShelfLayer()
                {
                    name    = "New Layer",
                    objects = new List <UnityEngine.Object>()
                });
                EditorUtility.SetDirty(Data);
                if (editorInstance != null)
                {
                    editorInstance.Repaint();
                }
            }

            EditorGUILayout.Space();

            var enablePopup = EditorPrefs.GetBool(POPUP_PREFS_KEY, true);
            enablePopup = EditorGUILayout.Toggle("Enable Popup Shelf", enablePopup);
            EditorPrefs.SetBool(POPUP_PREFS_KEY, enablePopup);
        }