/// <summary>
        /// Draws a objectpicker button in the given rect. This one is designed to look good on top of DrawDropZone().
        /// </summary>
        public static object ObjectPickerZone(Rect rect, object value, Type type, bool allowSceneObjects, int id)
        {
            // TODO: btnId wasn't used, but the GetControlID call is probably still important.
            //var btnId = GUIUtility.GetControlID(FocusType.Passive);
            GUIUtility.GetControlID(FocusType.Passive);
            var objectPicker = ObjectPicker.GetObjectPicker(type.FullName + "+" + GUIHelper.CurrentWindowInstanceID.ToString() + "+" + id, type);
            var selectRect   = rect.AlignBottom(15).AlignCenter(45);
            var uObj         = value as UnityEngine.Object;

            selectRect.xMin = Mathf.Max(selectRect.xMin, rect.xMin);

            var hide = IsDragging || Event.current.type == EventType.Repaint && !rect.Contains(Event.current.mousePosition);

            if (hide)
            {
                GUIHelper.PushColor(new Color(0, 0, 0, 0));
                GUIHelper.PushGUIEnabled(false);
            }

            bool hideInspectorBtn = !hide && !(uObj);

            if (hideInspectorBtn)
            {
                GUIHelper.PushGUIEnabled(false);
                GUIHelper.PushColor(new Color(0, 0, 0, 0));
            }

            var inspectBtn = rect.AlignRight(14);

            inspectBtn.height = 14;
            SirenixEditorGUI.BeginDrawOpenInspector(inspectBtn, uObj, rect);
            SirenixEditorGUI.EndDrawOpenInspector(inspectBtn, uObj);

            if (hideInspectorBtn)
            {
                GUIHelper.PopColor();
                GUIHelper.PopGUIEnabled();
            }

            if (GUI.Button(selectRect, "select", SirenixGUIStyles.TagButton))
            {
                GUIHelper.RemoveFocusControl();
                objectPicker.ShowObjectPicker(value, allowSceneObjects, rect, false);
                Event.current.Use();
            }

            if (Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.KeyDown && EditorGUIUtility.keyboardControl == id)
            {
                objectPicker.ShowObjectPicker(value, allowSceneObjects, rect, false);
                Event.current.Use();
            }

            if (hide)
            {
                GUIHelper.PopColor();
                GUIHelper.PopGUIEnabled();
            }

            if (objectPicker.IsReadyToClaim)
            {
                GUIHelper.RequestRepaint();
                GUI.changed = true;
                var newValue = objectPicker.ClaimObject();
                Event.current.Use();
                return(newValue);
            }

            if (objectPicker.IsPickerOpen && typeof(UnityEngine.Object).IsAssignableFrom(type))
            {
                return(objectPicker.CurrentSelectedObject);
            }

            if (Event.current.keyCode == KeyCode.Delete && Event.current.type == EventType.KeyDown && EditorGUIUtility.keyboardControl == id)
            {
                Event.current.Use();
                GUI.changed = true;
                return(null);
            }

            if (uObj && Event.current.rawType == EventType.MouseUp && rect.Contains(Event.current.mousePosition) && Event.current.button == 0)
            {
                // For components ping the attached game object instead, because then Unity can figure out to ping prefabs in the project window too.
                UnityEngine.Object pingObj = uObj;
                if (pingObj is Component)
                {
                    pingObj = (pingObj as Component).gameObject;
                }

                EditorGUIUtility.PingObject(pingObj);
            }

            return(value);
        }
Beispiel #2
0
        /// <summary>
        /// Begins the group.
        /// </summary>
        /// <param name="drawToolbar">if set to <c>true</c> a tool-bar for changing pages is drawn.</param>
        /// <param name="style">The style.</param>
        public void BeginGroup(bool drawToolbar = true, GUIStyle style = null)
        {
            LabelWidth = GUIHelper.BetterLabelWidth;

            if (Event.current.type == EventType.Layout)
            {
                this.drawToolbar = drawToolbar;
            }

            style = style ?? SirenixGUIStyles.ToggleGroupBackground;

            this.InnerContainerWidth = this.OuterRect.width - (
                style.padding.left +
                style.padding.right +
                style.margin.left +
                style.margin.right
                );

            if (this.currentPage == null && this.pages.Count > 0)
            {
                this.currentPage = this.pages.Select(x => x.Value).OrderBy(x => x.Order).First();
            }

            if (this.currentPage != null && this.pages.ContainsKey(this.currentPage.Name) == false)
            {
                if (this.pages.Count > 0)
                {
                    this.currentPage = this.OrderedPages.First();
                }
                else
                {
                    this.currentPage = null;
                }
            }

            float maxHeight = 0;

            foreach (var page in this.pages.GFValueIterator())
            {
                page.OnBeginGroup();
                maxHeight = Mathf.Max(page.Rect.height, maxHeight);
                if (Event.current.type == EventType.Layout)
                {
                    if (page.IsVisible != (page.IsVisible = page == this.targetPage || page == this.currentPage))
                    {
                        if (this.targetPage == null)
                        {
                            this.scrollPosition.x = 0f;
                            this.currentHeight    = this.currentPage.Rect.height;
                        }
                        else
                        {
                            this.scrollPosition.x = this.targetPage.Order >= this.currentPage.Order ? 0 : this.scrollPosition.x = this.OuterRect.width;
                            this.currentHeight    = this.currentPage.Rect.height;
                        }
                    }
                }
            }

            GUILayout.Space(1);
            var outerRect = EditorGUILayout.BeginVertical(style, GUILayoutOptions.ExpandWidth(true).ExpandHeight(false));

            if (this.drawToolbar)
            {
                this.DrawToolbar();
            }
            if (this.InnerRect.width > 0)
            {
                if (this.options.Length == 2)
                {
                    if (this.currentPage != null)
                    {
                        this.currentHeight = this.currentPage.Rect.height;
                    }
                    this.options = GUILayoutOptions.ExpandWidth(true).ExpandHeight(false).Height(this.currentHeight);
                }
                if (this.FixedHeight)
                {
                    this.options[2] = GUILayout.Height(maxHeight);
                }
                else
                {
                    this.options[2] = GUILayout.Height(this.currentHeight);
                }
            }

            GUIHelper.PushGUIEnabled(false);
            GUILayout.BeginScrollView(this.scrollPosition, false, false, GUIStyle.none, GUIStyle.none, this.options);
            GUIHelper.PopGUIEnabled();
            var innerRect = EditorGUILayout.BeginHorizontal(GUILayoutOptions.ExpandHeight(false));

            if (Event.current.type == EventType.Repaint)
            {
                this.OuterRect = outerRect;
                this.InnerRect = innerRect;
            }
        }
Beispiel #3
0
        public void DrawPageNavigation(Rect rect)
        {
            var leftBtnRect = rect.AlignLeft(rect.height * 1.3f);

            GUIHelper.PushGUIEnabled(!this.IsOnFirstPage);
            if (GUI.Button(leftBtnRect, GUIContent.none, GUIStyle.none))
            {
                this.NavigateBack();
            }
            EditorIcons.TriangleLeft.Draw(leftBtnRect, 19);
            GUIHelper.PopGUIEnabled();

            rect.xMin += rect.height;

            var totalLength = 0;

            for (int i = this.pages.Count - 1; i >= 0; i--)
            {
                var p = this.pages[i];
                if (!p.TitleWidth.HasValue)
                {
                    p.TitleWidth = (int)SirenixGUIStyles.BoldLabel.CalcSize(new GUIContent(p.Name)).x + 7;
                }
                totalLength += p.TitleWidth.Value;
            }

            rect.width -= 10;

            var cut = rect.xMin;

            if (totalLength > rect.width)
            {
                rect.xMin -= totalLength - rect.width;
            }

            for (int i = 0; i < this.pages.Count; i++)
            {
                var p = this.pages[i];
                if (!p.TitleWidth.HasValue)
                {
                    p.TitleWidth = (int)SirenixGUIStyles.BoldLabel.CalcSize(new GUIContent(p.Name)).x + 7;
                }
                rect.width = p.TitleWidth.Value;

                var btnRect = rect;
                btnRect.width -= 6;
                btnRect.xMin   = Mathf.Max(cut, btnRect.xMin);
                //var hover = btnRect.Contains(Event.current.mousePosition);
                //var active = i == this.pages.Count - 1;

                if (GUI.Button(btnRect, p.Name, SirenixGUIStyles.LabelCentered))
                {
                    this.NavigateBack(i + 1);
                }
                if (i != this.pages.Count - 1)
                {
                    var lblRect = btnRect.AlignRight(10);
                    lblRect.x   += 10;
                    lblRect.xMin = Mathf.Max(cut, lblRect.xMin);
                    GUI.Label(lblRect, "/", SirenixGUIStyles.LabelCentered);
                }
                rect.x += rect.width;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Draws a objectpicker butter, in the given rect. This one is designed to look good on top of DrawDropZone().
        /// </summary>
        public static object ObjectPickerZone(Rect rect, object value, Type type, bool allowSceneObjects, int id)
        {
            var btnId        = GUIUtility.GetControlID(FocusType.Passive);
            var objectPicker = ObjectPicker.GetObjectPicker(type.FullName + "+" + btnId, type);
            var selectRect   = rect.AlignBottom(15).AlignCenter(45);
            var uObj         = value as UnityEngine.Object;

            selectRect.xMin = Mathf.Max(selectRect.xMin, rect.xMin);

            var hide = IsDragging || Event.current.type == EventType.Repaint && !rect.Contains(Event.current.mousePosition);

            if (hide)
            {
                GUIHelper.PushColor(new Color(0, 0, 0, 0));
                GUIHelper.PushGUIEnabled(false);
            }

            bool hideInspectorBtn = !hide && !(uObj);

            if (hideInspectorBtn)
            {
                GUIHelper.PushGUIEnabled(false);
                GUIHelper.PushColor(new Color(0, 0, 0, 0));
            }

            var inspectBtn = rect.AlignRight(14);

            inspectBtn.height = 14;
            SirenixEditorGUI.BeginDrawOpenInspector(inspectBtn, uObj, rect);
            SirenixEditorGUI.EndDrawOpenInspector(inspectBtn, uObj);

            if (hideInspectorBtn)
            {
                GUIHelper.PopColor();
                GUIHelper.PopGUIEnabled();
            }

            if (GUI.Button(selectRect, "select", SirenixGUIStyles.TagButton))
            {
                GUIHelper.RemoveFocusControl();
                objectPicker.ShowObjectPicker(allowSceneObjects, rect, false);
                Event.current.Use();
            }

            if (Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.KeyDown && EditorGUIUtility.keyboardControl == id)
            {
                objectPicker.ShowObjectPicker(allowSceneObjects, rect, false);
                Event.current.Use();
            }

            if (hide)
            {
                GUIHelper.PopColor();
                GUIHelper.PopGUIEnabled();
            }

            if (objectPicker.IsReadyToClaim)
            {
                GUIHelper.RequestRepaint();
                GUI.changed = true;
                var newValue = objectPicker.ClaimObject();
                Event.current.Use();
                return(newValue);
            }

            if (Event.current.keyCode == KeyCode.Delete && Event.current.type == EventType.KeyDown && EditorGUIUtility.keyboardControl == id)
            {
                Event.current.Use();
                GUI.changed = true;
                return(null);
            }

            if (uObj && Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition) && EditorGUIUtility.hotControl == id && Event.current.button == 0)
            {
                EditorGUIUtility.PingObject(uObj);
            }

            return(value);
        }