Beispiel #1
0
        public static string Draw(Rect position, GUIContent label, string text, ref bool expanded)
        {
            var rect     = EditorGUI.PrefixLabel(position, label);
            var iconRect = RectHelper.AdjustHeight(RectHelper.TakeLeadingIcon(ref rect), EditorGUIUtility.singleLineHeight, RectVerticalAlignment.Top);

            using (ColorScope.Color(new Color(0.3f, 0.3f, 0.3f)))
            {
                var button = expanded ? _collapseButton : _expandButton;

                if (GUI.Button(iconRect, button.Content, GUIStyle.none))
                {
                    expanded = !expanded;
                }
            }

            if (expanded)
            {
                text = EditorGUI.TextArea(rect, text);
            }
            else
            {
                var textRect = RectHelper.TakeLine(ref rect);
                text = EditorGUI.TextField(textRect, text);
            }

            return(text);
        }
Beispiel #2
0
        private void DrawElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            if (Visible && index < List.count)
            {
                var elementRect  = RectHelper.AdjustHeight(rect, rect.height - ItemPadding, RectVerticalAlignment.Middle);
                var buttonsWidth = GetItemButtonsWidth();
                var buttonsRect  = RectHelper.TakeTrailingWidth(ref elementRect, buttonsWidth);

                for (var i = 0; i < _itemButtons.Count; i++)
                {
                    var button     = _itemButtons[i];
                    var buttonRect = RectHelper.AdjustHeight(RectHelper.TakeLeadingIcon(ref buttonsRect), ItemDefaultHeight, RectVerticalAlignment.Top);

                    using (ColorScope.ContentColor(button.Color))
                    {
                        if (GUI.Button(buttonRect, button.Icon.Content, GUIStyle.none))
                        {
                            SetClickedButton(index, i, buttonRect);
                        }
                    }
                }

                Draw(elementRect, index);
            }
        }
Beispiel #3
0
        public static void Draw(Rect position, SceneReference scene, GUIContent label, string newSceneName, Action newSceneSetup)
        {
            position = EditorGUI.PrefixLabel(position, label);

            var loadRect    = RectHelper.TakeTrailingIcon(ref position);
            var refreshRect = RectHelper.TakeTrailingIcon(ref position);

            if (GUI.Button(refreshRect, _refreshScenesButton.Content, GUIStyle.none))
            {
                SceneHelper.RefreshLists();
            }

            var list     = SceneHelper.GetSceneList(true, newSceneSetup != null);
            var index    = list.GetIndex(scene.Path);
            var selected = EditorGUI.Popup(position, index, list.Names);

            if (selected != index && selected == list.CreateIndex)
            {
                var newScene = SceneHelper.CreateScene(newSceneName, newSceneSetup);
                scene.Path = newScene.path;
            }
            else
            {
                scene.Path = list.GetPath(selected);
            }

            if (!string.IsNullOrEmpty(scene.Path))
            {
                var s = SceneManager.GetSceneByPath(scene.Path);

                using (ColorScope.ContentColor(Color.black))
                {
                    if (s.IsValid() && s.isLoaded)
                    {
                        if (GUI.Button(loadRect, _unloadSceneButton.Content, GUIStyle.none))
                        {
                            if (EditorSceneManager.SaveModifiedScenesIfUserWantsTo(new Scene[] { s }))
                            {
                                EditorSceneManager.CloseScene(s, true);
                            }
                        }
                    }
                    else
                    {
                        if (GUI.Button(loadRect, _loadSceneButton.Content, GUIStyle.none))
                        {
                            s = EditorSceneManager.OpenScene(scene.Path, OpenSceneMode.Additive);
                            SceneManager.SetActiveScene(s);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public void DoDefaultDraw(Rect rect, int index)
        {
            var property = List.serializedProperty.GetArrayElementAtIndex(index);

            switch (_itemDisplay)
            {
            case ListItemDisplayType.Normal:
            {
                EditorGUI.PropertyField(rect, property, GUIContent.none);
                break;
            }

            case ListItemDisplayType.Inline:
            {
                InlineDisplayDrawer.Draw(rect, property, null);
                break;
            }

            case ListItemDisplayType.Foldout:
            {
                var expanded    = IsExpanded(index);
                var labelRect   = expanded ? RectHelper.TakeLine(ref rect) : rect;
                var foldoutRect = RectHelper.TakeLeadingIcon(ref labelRect);

                using (ColorScope.Color(new Color(0.3f, 0.3f, 0.3f)))
                {
                    if (GUI.Button(foldoutRect, expanded ? _collapseButton.Content : _expandButton.Content, GUIStyle.none))
                    {
                        SetExpanded(index, !expanded);
                    }
                }

                EditorGUI.LabelField(labelRect, "Item " + index, EditorStyles.boldLabel);

                if (expanded)
                {
                    using (new EditorGUI.IndentLevelScope(1))
                        InlineDisplayDrawer.Draw(rect, property, null);
                }

                break;
            }

            case ListItemDisplayType.AssetPopup:
            {
                AssetPopupDrawer.Draw(rect, GUIContent.none, property, _assetPopupType, true, false, true);
                break;
            }
            }
        }
Beispiel #5
0
        private void DrawHeader(Rect rect)
        {
            var buttonsWidth = GetHeaderButtonsWidth();
            var buttonsRect  = RectHelper.TakeTrailingWidth(ref rect, buttonsWidth);
            var labelRect    = new Rect(rect);

            if (_canCollapse)
            {
                var arrowRect = RectHelper.TakeLeadingIcon(ref labelRect);

                EditorGUI.LabelField(arrowRect, Visible ? _collapseButton.Content : _expandButton.Content);

                if (GUI.Button(rect, GUIContent.none, GUIStyle.none))
                {
                    Visible = !Visible;
                    _onCollapse?.Invoke(Visible);
                }
            }

            EditorGUI.LabelField(labelRect, _label);

            if (Visible)
            {
                for (var i = 0; i < _headerButtons.Count; i++)
                {
                    var button     = _headerButtons[i];
                    var buttonRect = RectHelper.TakeLeadingIcon(ref buttonsRect);

                    using (ColorScope.ContentColor(button.Color))
                    {
                        if (GUI.Button(buttonRect, button.Label.Content, GUIStyle.none))
                        {
                            SetClickedButton(-1, i, buttonRect);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public static void Draw(Rect position, SceneReference scene, GUIContent label, AssetLocation location, string newSceneName, Action creator)
        {
            var rect        = EditorGUI.PrefixLabel(position, label);
            var refreshRect = RectHelper.TakeTrailingIcon(ref rect);

            if (GUI.Button(refreshRect, _refreshScenesButton.Content, GUIStyle.none))
            {
                SceneHelper.RefreshLists();
            }

            var list  = SceneHelper.GetSceneList(true, location != AssetLocation.None);
            var index = list.GetIndex(scene.Path);

            if (index != 0 && scene.IsAssigned)
            {
                var loadRect = RectHelper.TakeTrailingIcon(ref rect);
                var s        = scene.Scene;

                using (ColorScope.ContentColor(Color.black))
                {
                    if (s.IsValid() && s.isLoaded)
                    {
                        if (GUI.Button(loadRect, _unloadSceneButton.Content, GUIStyle.none))
                        {
                            if (EditorSceneManager.SaveModifiedScenesIfUserWantsTo(new Scene[] { s }))
                            {
                                EditorSceneManager.CloseScene(s, true);
                            }
                        }
                    }
                    else
                    {
                        if (GUI.Button(loadRect, _loadSceneButton.Content, GUIStyle.none))
                        {
                            s = EditorSceneManager.OpenScene(scene.Path, OpenSceneMode.Additive);
                            SceneManager.SetActiveScene(s);
                        }
                    }
                }
            }

            var thumbnail  = AssetPreview.GetMiniTypeThumbnail(typeof(SceneAsset));
            var start      = scene.Path.LastIndexOf('/') + 1;
            var popupLabel = index != 0 && scene.IsAssigned ? new GUIContent(scene.Path.Substring(start, scene.Path.Length - start - 6), thumbnail) : new GUIContent("None");

            var selection = SelectionPopup.Draw(rect, popupLabel, new SelectionState {
                Tab = 0, Index = index
            }, list.Tree);

            if (selection.Tab == 0 && selection.Index != index)
            {
                scene.Path = list.GetPath(selection.Index);
            }
            else if (selection.Tab == 1)
            {
                var newScene = SceneHelper.CreateScene(location, newSceneName, creator);
                scene.Path = newScene.path;
            }

            if (DragAndDrop.objectReferences.Length > 0 && rect.Contains(Event.current.mousePosition))
            {
                var obj = DragAndDrop.objectReferences[0];

                if (obj is SceneAsset asset)
                {
                    if (Event.current.type == EventType.DragUpdated)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        Event.current.Use();
                    }

                    if (Event.current.type == EventType.DragPerform)
                    {
                        scene.Path = AssetDatabase.GetAssetPath(asset);
                        DragAndDrop.AcceptDrag();
                    }
                }
            }
        }