Beispiel #1
0
        private void DrawPropertyIndex(Guid id, SelectionState selectionState, AnimBool animBool)
        {
            GUILayout.Space(DGUI.Properties.Space(2));
            var propertyIndex    = m_theme.GetColorPropertyIndex(id);
            var propertyNotFound = id == Guid.Empty || propertyIndex == -1;

            GUILayout.BeginHorizontal();
            {
                if (!propertyNotFound && !animBool.target)
                {
                    GUI.color = m_theme.ActiveVariant.Colors[propertyIndex].Color;
                    GUILayout.Label(GUIContent.none, Styles.GetStyle(Styles.StyleName.ColorButtonSelected));
                    GUI.color = InitialGUIColor;
                    GUILayout.Space(2);
                }

                DGUI.Bar.Draw(selectionState.ToString(), Size.L, DGUI.Bar.Caret.CaretType.Caret, ComponentColorName, animBool);
            }
            GUILayout.EndHorizontal();

            if (DGUI.FoldOut.Begin(animBool))
            {
                GUILayout.Space(DGUI.Properties.Space(2));
                if (propertyNotFound)
                {
                    ThemeTargetEditorUtils.DrawLabelNoPropertyFound();
                }
                else
                {
                    DrawColorProperties(m_theme, propertyIndex, selectionState);
                }
            }

            DGUI.FoldOut.End(animBool);
        }
Beispiel #2
0
        private void DrawColorProperties(ThemeData themeData, int propertyIndex, SelectionState selectionState)
        {
            GUIStyle colorButtonStyle         = Styles.GetStyle(Styles.StyleName.ColorButton);
            GUIStyle colorButtonSelectedStyle = Styles.GetStyle(Styles.StyleName.ColorButtonSelected);

            if (themeData.ColorLabels.Count != themeData.ActiveVariant.Colors.Count)
            {
                foreach (LabelId labelId in themeData.ColorLabels.Where(labelId => !themeData.ActiveVariant.ContainsColor(labelId.Id)))
                {
                    themeData.ActiveVariant.AddColorProperty(labelId.Id);
                }
            }

            for (int i = 0; i < themeData.ColorLabels.Count; i++)
            {
                LabelId colorProperty = themeData.ColorLabels[i];
                int     index         = i;
                bool    selected      = i == propertyIndex;
                GUILayout.BeginHorizontal();
                {
                    if (!selected)
                    {
                        GUILayout.Space((colorButtonSelectedStyle.fixedWidth - colorButtonStyle.fixedWidth) / 2);
                    }
                    GUI.color = themeData.ActiveVariant.Colors[i].Color;
                    {
                        if (GUILayout.Button(GUIContent.none, selected ? colorButtonSelectedStyle : colorButtonStyle))
                        {
                            if (serializedObject.isEditingMultipleObjects)
                            {
                                DoozyUtils.UndoRecordObjects(targets, UILabels.UpdateValue);
                                foreach (Object o in targets)
                                {
                                    var themeTarget = (ColorTargetSelectable)o;
                                    if (themeTarget == null)
                                    {
                                        continue;
                                    }
                                    switch (selectionState)
                                    {
                                    case SelectionState.Normal:
                                        themeTarget.NormalColorPropertyId = themeData.ColorLabels[index].Id;
                                        break;

                                    case SelectionState.Highlighted:
                                        themeTarget.HighlightedColorPropertyId = themeData.ColorLabels[index].Id;
                                        break;

                                    case SelectionState.Pressed:
                                        themeTarget.PressedColorPropertyId = themeData.ColorLabels[index].Id;
                                        break;

#if UNITY_2019_1_OR_NEWER
                                    case SelectionState.Selected:
                                        themeTarget.SelectedColorPropertyId = themeData.ColorLabels[index].Id;
                                        break;
#endif
                                    case SelectionState.Disabled:
                                        themeTarget.DisabledColorPropertyId = themeData.ColorLabels[index].Id;
                                        break;
                                    }

                                    themeTarget.UpdateTarget(themeData);
                                }
                            }
                            else
                            {
                                DoozyUtils.UndoRecordObject(target, UILabels.UpdateValue);
                                switch (selectionState)
                                {
                                case SelectionState.Normal:
                                    Target.NormalColorPropertyId = themeData.ColorLabels[index].Id;
                                    break;

                                case SelectionState.Highlighted:
                                    Target.HighlightedColorPropertyId = themeData.ColorLabels[index].Id;
                                    break;

                                case SelectionState.Pressed:
                                    Target.PressedColorPropertyId = themeData.ColorLabels[index].Id;
                                    break;

#if UNITY_2019_1_OR_NEWER
                                case SelectionState.Selected:
                                    Target.SelectedColorPropertyId = themeData.ColorLabels[index].Id;
                                    break;
#endif
                                case SelectionState.Disabled:
                                    Target.DisabledColorPropertyId = themeData.ColorLabels[index].Id;
                                    break;
                                }

                                Target.UpdateTarget(themeData);
                            }
                        }
                    }
                    GUI.color = InitialGUIColor;
                    GUILayout.Space(DGUI.Properties.Space(2));
                    GUI.enabled = selected;
                    DGUI.Label.Draw(colorProperty.Label, selected ? Size.L : Size.M,
                                    selected ? colorButtonSelectedStyle.fixedHeight : colorButtonStyle.fixedHeight);
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(DGUI.Properties.Space());
            }
        }