コード例 #1
0
        public static void IntRange(Rect rect, GUIContent label, SerializedProperty property)
        {
            EditorGUI.BeginProperty(rect, label, property);

            rect = EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), label);

            int indentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Horizontal,
                                                                    new AdvancedRect.ExpandedItem("Start"),
                                                                    new AdvancedRect.FixedSpace(5),
                                                                    new AdvancedRect.ExpandedItem("End")
                                                                    );

            EditorGUIUtility.labelWidth = 35;
            EditorGUI.PropertyField(rects["Start"], property.FindPropertyRelative("start"));
            EditorGUIUtility.labelWidth = 30;
            EditorGUI.PropertyField(rects["End"], property.FindPropertyRelative("end"));
            EditorGUIUtility.labelWidth = 0;

            EditorGUI.indentLevel = indentLevel;

            EditorGUI.EndProperty();
        }
コード例 #2
0
        private void DrawEase(Rect rect, int easeType)
        {
            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Vertical,
                                                                    new AdvancedRect.FixedItem("Header", 20),
                                                                    new AdvancedRect.FixedSpace(1),
                                                                    new AdvancedRect.ExpandedItem("Ease")
                                                                    );

            Rect originalEaseRect = rects["Ease"];
            Rect easeRect         = originalEaseRect;

            // GUI.Label (rects["Header"], ease.ToString ().ToTitleCase (), EasingCurvesStyles.Header);
            Styles.Ease.Draw(easeRect);

            GUI.BeginGroup(easeRect);
            easeRect.position = Vector2.zero;
            easeRect          = new RectOffset(-2, -2, 0, 0).Add(easeRect);

            float   verticalOffset = easeRect.height / 4f;
            Vector2 offset         = new Vector2(easeRect.xMin, easeRect.height - verticalOffset);

            Vector2 bottomLeft  = offset;
            Vector2 bottomRight = offset + Vector2.right * easeRect.width;

            Vector2 topLeft  = new Vector2(easeRect.xMin, verticalOffset);
            Vector2 topRight = new Vector2(easeRect.xMax, verticalOffset);

            Handles.color = Color.red;
            Handles.DrawLine(bottomLeft, bottomRight);
            Handles.DrawLine(topLeft, topRight);
            Handles.color = Color.white;

            GUI.EndGroup();
        }
コード例 #3
0
        private void Draw()
        {
            Dictionary <string, Rect> rects = AdvancedRect.GetRects(WindowRect, AdvancedRect.Orientation.Vertical,
                                                                    new AdvancedRect.FixedItem("Header", 24),
                                                                    new AdvancedRect.FixedSpace(2),
                                                                    new AdvancedRect.FixedGroup("Settings", AdvancedRect.Orientation.Horizontal, 18, new RectPadding(-2, RectPaddingType.All),
                                                                                                new AdvancedRect.FixedItem("PreviewTime", 150),
                                                                                                new AdvancedRect.FixedSpace(6),
                                                                                                new AdvancedRect.FixedItem("FilteredEasingsModes", 200),
                                                                                                new AdvancedRect.FixedSpace(3),
                                                                                                new AdvancedRect.ExpandedItem("FilteredEasingsType")
                                                                                                ),
                                                                    new AdvancedRect.FixedSpace(5),
                                                                    new AdvancedRect.ExpandedItem("Easings")
                                                                    );

            GUI.Label(rects["Header"], "Easings Viewer", Styles.Header);

            Styles.Background.Draw(rects["Settings"]);

            EditorGUIUtility.labelWidth = 80;
            PreviewTime = EditorGUI.FloatField(rects["PreviewTime"], "Preview Time", PreviewTime);

            EditorGUIUtility.labelWidth = 90;
            EditorGUI.BeginChangeCheck();
            EditorGUI.BeginChangeCheck();
            int filteredMode = (int)(Easings.Mode)EditorGUI.EnumFlagsField(rects["FilteredEasingsModes"], "Easings Modes", (Easings.Mode)FilteredEasings);

            if (filteredMode == -1)
            {
                filteredMode = (int)Easings.Mode.Everything;
            }

            if (EditorGUI.EndChangeCheck())
            {
            }

            EditorGUI.BeginChangeCheck();
            int filteredTypes = (int)(Easings.Type)EditorGUI.EnumFlagsField(rects["FilteredEasingsType"], "Easings Types", (Easings.Type)FilteredEasings);

            if (filteredTypes == -1)
            {
                filteredTypes = (int)Easings.Type.Everything;
            }

            if (EditorGUI.EndChangeCheck())
            {
            }

            if (EditorGUI.EndChangeCheck())
            {
            }

            if (searchField == null)
            {
                searchField = new SearchField();
            }

            DrawEasings(rects["Easings"]);
        }
コード例 #4
0
        public static string DateField(Rect rect, GUIContent label, string date)
        {
            Rect contentRect = EditorGUI.PrefixLabel(rect, label);

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(contentRect, AdvancedRect.Orientation.Horizontal,
                                                                    new AdvancedRect.FixedItem("Day", 30),
                                                                    new AdvancedRect.FixedSpace(2),
                                                                    new AdvancedRect.ExpandedItem("Month"),
                                                                    new AdvancedRect.FixedSpace(2),
                                                                    new AdvancedRect.FixedItem("Year", 40)
                                                                    );

            DateTime dateTime = DateTime.ParseExact(date, DateTimeFormat, null);

            EditorGUI.BeginChangeCheck();
            int year  = EditorGUI.IntField(rects["Year"], GUIContent.none, dateTime.Year);
            int month = EditorGUI.Popup(rects["Month"], dateTime.Month - 1, Months) + 1;
            int day   = EditorGUI.IntField(rects["Day"], GUIContent.none, dateTime.Day);

            if (EditorGUI.EndChangeCheck())
            {
                dateTime = ApplyToDate(day, month, year);
            }

            return(dateTime.ToString(DateTimeFormat));
        }
コード例 #5
0
        private void OnGUI()
        {
            Dictionary <string, Rect> rects = AdvancedRect.GetRects(Rect, AdvancedRect.Orientation.Vertical,
                                                                    new AdvancedRect.FixedItem("Header", 18),
                                                                    new AdvancedRect.FixedSpace(2),
                                                                    new AdvancedRect.ExpandedGroup(AdvancedRect.Orientation.Horizontal,
                                                                                                   new AdvancedRect.FixedGroup(AdvancedRect.Orientation.Vertical, 150,
                                                                                                                               new AdvancedRect.FixedItem("ListHeader", 18),
                                                                                                                               new AdvancedRect.FixedSpace(2),
                                                                                                                               new AdvancedRect.ExpandedItem("List"),
                                                                                                                               new AdvancedRect.FixedSpace(2),
                                                                                                                               new AdvancedRect.FixedItem("AddButton", 16)
                                                                                                                               ),
                                                                                                   new AdvancedRect.FixedSpace(2),
                                                                                                   new AdvancedRect.ExpandedGroup(AdvancedRect.Orientation.Vertical,
                                                                                                                                  new AdvancedRect.ExpandedItem("PropertiesA"),
                                                                                                                                  new AdvancedRect.FixedSpace(2),
                                                                                                                                  new AdvancedRect.ExpandedItem("PropertiesB")
                                                                                                                                  )
                                                                                                   )
                                                                    );

            foreach (KeyValuePair <string, Rect> rect in rects)
            {
                EditorGUI.DrawRect(rect.Value, Color.black);
                AdvancedLabel.Draw(rect.Value, new AdvancedLabel.Config(rect.Key));
            }
        }
コード例 #6
0
        public static IntRange IntRange(Rect rect, GUIContent label, IntRange value)
        {
            rect = EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), label);

            int indentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Horizontal,
                                                                    new AdvancedRect.ExpandedItem("Start"),
                                                                    new AdvancedRect.FixedSpace(5),
                                                                    new AdvancedRect.ExpandedItem("End")
                                                                    );

            float lastLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 35;
            value.start = EditorGUI.IntField(rects["Start"], "Start", value.start);
            EditorGUIUtility.labelWidth = 30;
            value.end = EditorGUI.IntField(rects["End"], "End", value.end);
            EditorGUIUtility.labelWidth = lastLabelWidth;

            EditorGUI.indentLevel = indentLevel;

            return(value);
        }
コード例 #7
0
        private void DrawEasings(Rect rect)
        {
            Styles.Background.Draw(rect);
            Rect paddedRect = new RectOffset(Styles.Padding, Styles.Padding, Styles.Padding, Styles.Padding).Add(rect);

            int easeCount = Easings.Functions.Count;

            List <Rect> easingsRects = ComputeEasingsRects(paddedRect.size, easeCount, out Vector2 totalSize);

            float viewHeight = paddedRect.height + Styles.Padding;
            float viewOffset = totalSize.y - viewHeight;
            float handleSize = (viewHeight / totalSize.y) * totalSize.y;

            bool needsScrollBar = viewOffset > 0;

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Horizontal,
                                                                    new AdvancedRect.ExpandedItem("Easings", new RectPadding(Styles.Padding, RectPaddingType.Vertical)),
                                                                    new AdvancedRect.FixedItem("Scrollbar", 16, needsScrollBar)
                                                                    );

            Rect easingsRect = rects["Easings"];

            if (needsScrollBar)
            {
                ScrollPosition = GUI.VerticalScrollbar(rects["Scrollbar"], ScrollPosition, handleSize, 0, viewOffset + handleSize);

                if (easingsRect.Contains(Event.current.mousePosition) && Event.current.type == EventType.ScrollWheel)
                {
                    ScrollPosition += Event.current.delta.y * 20f;
                    Event.current.Use();
                }
            }
            else
            {
                ScrollPosition = 0;
            }

            Vector2 easingsOffset = new Vector2((easingsRect.width - totalSize.x) / 2f, 0);

            easingsOffset.y -= ScrollPosition;

            GUI.BeginGroup(easingsRect);
            for (int i = 0; i < easingsRects.Count; i++)
            {
                if (!easingsRect.Overlaps(rect))
                {
                    continue;
                }

                Rect easeRect = new Rect(easingsRects[i].position + easingsOffset, easingsRects[i].size);
                DrawEase(easeRect, 0);
            }

            GUI.EndGroup();
        }
コード例 #8
0
        public override void OnGUI(Rect rect)
        {
            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Vertical,
                                                                    new AdvancedRect.FixedSpace(4),
                                                                    new AdvancedRect.FixedItem("SearchBar", 18, new RectPadding(-2, RectPaddingType.Horizontal)),
                                                                    new AdvancedRect.ExpandedItem("List")
                                                                    );

            treeView.searchString = searchField.OnToolbarGUI(rects["SearchBar"], treeView.searchString);
            treeView.OnGUI(rects["List"]);
        }
コード例 #9
0
        private void OnGUI()
        {
            windowRect = WindowOffset.Add(new Rect(Vector2.zero, position.size));

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(windowRect, AdvancedRect.Orientation.Vertical,
                                                                    new AdvancedRect.FixedItem("Header", 24),
                                                                    new AdvancedRect.FixedSpace(5),
                                                                    new AdvancedRect.ExpandedItem("Easings")
                                                                    );

            DrawHeader(rects["Header"]);
            DrawEasings(rects["Easings"]);
        }
コード例 #10
0
        internal void DrawElementBase(Rect rect, int index)
        {
            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Horizontal,
                                                                    new AdvancedRect.FixedItem("ReorderIcon", Styles.DragIconWidth, CanReorder()),
                                                                    new AdvancedRect.ExpandedItem("Element")
                                                                    );

            if (CanReorder())
            {
                Styles.DragIcon.Draw(ExtendedRect.Align(new Vector2(rects["ReorderIcon"].width, 16), rects["ReorderIcon"], RectAlignment.Center));
            }

            DrawElement(rects["Element"], index);
        }
コード例 #11
0
        public static TimeObject TimeObject(Rect rect, GUIContent label, TimeObject value)
        {
            rect = EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label));

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Horizontal,
                                                                    new AdvancedRect.ExpandedItem("Value"),
                                                                    new AdvancedRect.FixedSpace(2),
                                                                    new AdvancedRect.FixedItem("Type", 75)
                                                                    );

            value.value = EditorGUI.DoubleField(rects["Value"], value.value);
            value.type  = (TimeObjectType)EditorGUI.EnumPopup(rects["Type"], value.type);

            return(value);
        }
コード例 #12
0
        protected internal void DrawSearchBar(Rect rect)
        {
            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Horizontal,
                                                                    new AdvancedRect.ExpandedItem("Bar"),
                                                                    new AdvancedRect.FixedItem("CancelButton", Styles.HeaderHeight, new RectPadding(Styles.SearchBarCancelButtonPadding, RectPaddingType.All))
                                                                    );

            SearchString = searchBar.OnGUI(rects["Bar"], SearchString, Styles.SearchBar, GUIStyle.none, GUIStyle.none);

            if (!string.IsNullOrEmpty(SearchString))
            {
                if (GUI.Button(rects["CancelButton"], string.Empty, Styles.SearchBarCancelButton))
                {
                    SearchString = string.Empty;
                    GUI.FocusControl(null);
                }
            }
        }
コード例 #13
0
        protected internal virtual void DoDraw(Rect rect)
        {
            if (treeView.ItemCount != ElementCount)
            {
                ReloadTree();
                RepaintTree();
                return;
            }

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Vertical,
                                                                    new AdvancedRect.FixedSpace(Styles.DefaultSpacing),
                                                                    new AdvancedRect.FixedItem("Header", Styles.HeaderHeight, new RectPadding(Styles.DefaultPadding, RectPaddingType.Horizontal)),
                                                                    new AdvancedRect.FixedSpace(Styles.DefaultSpacing),
                                                                    new AdvancedRect.ExpandedItem("TreeView")
                                                                    );

            DrawHeader(rects["Header"]);

            if (CanDrawBackground())
            {
                Styles.Background.Draw(rects["TreeView"]);
                rects["TreeView"] = rects["TreeView"].Expand(new RectPadding(Styles.DefaultPadding, RectPaddingType.All));
            }

            if (ElementCount > 0)
            {
                if (showContextMenuInNextDraw)
                {
                    showContextMenuInNextDraw = false;
                    ShowContextElementMenu();
                }

                treeView.OnGUI(rects["TreeView"]);
            }
            else
            {
                AdvancedLabel.Draw(rects["TreeView"], new AdvancedLabel.Config(GetEmptyListMessage(), FontStyle.Bold));
            }
        }
コード例 #14
0
        public static void TimeObject(Rect rect, GUIContent label, SerializedProperty property)
        {
            EditorGUI.BeginProperty(rect, label, property);

            rect = EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), label);

            int indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Horizontal,
                                                                    new AdvancedRect.ExpandedItem("Value"),
                                                                    new AdvancedRect.FixedSpace(2),
                                                                    new AdvancedRect.FixedItem("Type", 75)
                                                                    );

            EditorGUI.PropertyField(rects["Value"], property.FindPropertyRelative("value"), GUIContent.none);
            EditorGUI.PropertyField(rects["Type"], property.FindPropertyRelative("type"), GUIContent.none);

            EditorGUI.indentLevel = indent;

            EditorGUI.EndProperty();
        }
コード例 #15
0
        protected internal virtual void DrawHeader(Rect rect)
        {
            bool canSearch     = CanSearch();
            bool canAddElement = CanAddElement();

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Horizontal,
                                                                    new AdvancedRect.ExpandedGroup("SearchBar", AdvancedRect.Orientation.Horizontal,
                                                                                                   new AdvancedRect.FixedSpace(12, canSearch),
                                                                                                   new AdvancedRect.ExpandedItem("Title")
                                                                                                   ),
                                                                    new AdvancedRect.FixedItem("AddButton", Styles.AddButtonWidth, canAddElement)
                                                                    );

            Styles.HeaderBackground.Draw(rect);

            if (canSearch)
            {
                if (ElementCount > 0)
                {
                    DrawSearchBar(rects["SearchBar"]);
                }
            }

            if (!canSearch || (!searchBar.HasFocus() && string.IsNullOrEmpty(SearchString)))
            {
                GUI.Label(rects["Title"], Title, Styles.Header);
            }

            if (canAddElement)
            {
                if (GUI.Button(rects["AddButton"], string.Empty, Styles.AddButton))
                {
                    AddElement();
                }
            }
        }
コード例 #16
0
        private static void DoPopup(Rect rect, SerializedProperty serializedProperty, string label, GUIStyle style)
        {
            bool   labelEmpty   = label == string.Empty;
            string selectedEnum = serializedProperty.enumNames[serializedProperty.enumValueIndex];
            float  styleHeight  = style.CalcHeight(new GUIContent(selectedEnum), 100);

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Horizontal,
                                                                    new AdvancedRect.ExpandedItem("Field"),
                                                                    new AdvancedRect.FixedItem("Label", EditorGUIUtility.labelWidth, !labelEmpty)
                                                                    );

            if (!labelEmpty)
            {
                GUI.Label(rects["Label"], label);
            }

            if (GUI.Button(rects["Field"], selectedEnum.ToTitleCase(), style))
            {
                EnumPopupWindow popupWindow = new EnumPopupWindow(serializedProperty);

                Rect windowRect = new Rect(rects["Field"].position, new Vector2(1, styleHeight));
                PopupWindow.Show(windowRect, popupWindow);
            }
        }
コード例 #17
0
        private void DrawEase(Rect rect, EasingCurves.List ease)
        {
            if (!windowRect.Overlaps(rect))
            {
                return;
            }

            Dictionary <string, Rect> rects = AdvancedRect.GetRects(rect, AdvancedRect.Orientation.Vertical,
                                                                    new AdvancedRect.FixedItem("Header", 20),
                                                                    new AdvancedRect.FixedSpace(1),
                                                                    new AdvancedRect.ExpandedItem("Ease")
                                                                    );

            Rect originalEaseRect = rects["Ease"];
            Rect easeRect         = originalEaseRect;

            GUI.Label(rects["Header"], ease.ToString().ToTitleCase(), EasingCurvesStyles.Header);
            EasingCurvesStyles.Ease.Draw(easeRect);

            GUI.BeginGroup(easeRect);
            easeRect.position = Vector2.zero;
            easeRect          = new RectOffset(-2, -2, 0, 0).Add(easeRect);

            float   verticalOffset = easeRect.height / 4f;
            Vector2 offset         = new Vector2(easeRect.xMin, easeRect.height - verticalOffset);

            Vector2 bottomLeft  = offset;
            Vector2 bottomRight = offset + Vector2.right * easeRect.width;

            Vector2 topLeft  = new Vector2(easeRect.xMin, verticalOffset);
            Vector2 topRight = new Vector2(easeRect.xMax, verticalOffset);

            Handles.color = Color.red;
            Handles.DrawLine(bottomLeft, bottomRight);
            Handles.DrawLine(topLeft, topRight);
            Handles.color = Color.white;

            for (int i = 0; i <= Resolution; i++)
            {
                float previousPercent = (i > 0 ? i - 1 : i) / Resolution;
                float percent         = i / Resolution;

                Vector2 prevPosition = new Vector2(offset.x + previousPercent * easeRect.width, offset.y + -EasingCurves.GetEaseValue(ease, previousPercent) * (easeRect.height - verticalOffset * 2));
                Vector2 position     = new Vector2(offset.x + percent * easeRect.width, offset.y + -EasingCurves.GetEaseValue(ease, percent) * (easeRect.height - verticalOffset * 2));
                Handles.DrawLine(prevPosition, position);
            }

            GUI.EndGroup();

            if (originalEaseRect.Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown)
            {
                previewEase        = ease;
                currentPreviewTime = Time.realtimeSinceStartup;
            }

            if (ease == previewEase)
            {
                float previewTime = Mathf.Clamp(Time.realtimeSinceStartup - currentPreviewTime, 0, 1 + PreviewDelay);

                if (previewTime <= PreviewDelay)
                {
                    previewTime = 0;
                }
                else
                {
                    previewTime -= PreviewDelay;
                }

                Vector2 position = new Vector2(offset.x + previewTime * easeRect.width, offset.y + -EasingCurves.GetEaseValue(ease, previewTime) * (easeRect.height - verticalOffset * 2));

                Rect circleRect = new Rect(originalEaseRect.position + position - Vector2.one * 4f, Vector2.one * 8);
                EasingCurvesStyles.Circle.Draw(circleRect);

                Rect arrowRect = new Rect(originalEaseRect.xMax + 5, originalEaseRect.y + position.y - 6, 20, 12);
                EasingCurvesStyles.Arrow.Draw(arrowRect);
            }
        }