예제 #1
0
        private static void ApplyLayoutElement <T>(ElementStyleData style, UIReference <T> reference)
            where T : MonoBehaviour
        {
            var minWidth        = style.minWidth;
            var minHeight       = style.minHeight;
            var preferredWidth  = style.preferredWidth;
            var preferredHeight = style.preferredHeight;
            var flexibleWidth   = style.flexibleWidth;
            var flexibleHeight  = style.flexibleHeight;

            // LayoutElement uses -1 values as disabled
            var useLayout = minWidth >= 0 || minHeight >= 0 ||
                            preferredWidth >= 0 || preferredHeight >= 0 ||
                            flexibleWidth >= 0 || flexibleHeight >= 0;

            if (UpdateComponent(reference.value, ref reference.layoutElement, useLayout))
            {
                reference.layoutElement.minWidth        = minWidth;
                reference.layoutElement.minHeight       = minHeight;
                reference.layoutElement.preferredWidth  = preferredWidth;
                reference.layoutElement.preferredHeight = preferredHeight;
                reference.layoutElement.flexibleWidth   = flexibleWidth;
                reference.layoutElement.flexibleHeight  = flexibleHeight;
            }
        }
예제 #2
0
        private static void ApplyDropdownStyle <T>(DropdownStyleData style, UIReference <T> reference)
            where T : Dropdown
        {
            reference.value.alphaFadeSpeed = style.alphaFadeSpeed;

            ApplySelectableStyle(style, reference);
        }
예제 #3
0
        private static void ApplyToggleStyle <T>(ToggleStyleData style, UIReference <T> reference)
            where T : Toggle
        {
            reference.value.toggleTransition = style.toggleTransition;

            ApplySelectableStyle(style, reference);
        }
예제 #4
0
        private static void ApplyGraphicStyle <T>(GraphicStyleData style, UIReference <T> reference)
            where T : Graphic
        {
            reference.value.color    = style.color;
            reference.value.material = style.material;

            ApplyShadow(style, reference);
        }
예제 #5
0
 private static void ApplyScrollRectStyle <T>(ScrollRectStyleData style, UIReference <T> reference)
     where T : ScrollRect
 {
     reference.value.movementType      = style.movementType;
     reference.value.elasticity        = style.elasticity;
     reference.value.inertia           = style.inertia;
     reference.value.decelerationRate  = style.decelerationRate;
     reference.value.scrollSensitivity = style.scrollSensitivity;
 }
예제 #6
0
 private static void ApplyLayout <T>(ElementStyleData style, UIReference <T> behaviour)
     where T : MonoBehaviour
 {
     if (behaviour.value && visitedObjectsSet.Add(behaviour.value.gameObject))
     {
         ApplyLayoutElement(style, behaviour);
         ApplyContentSizeFitter(style, behaviour);
     }
 }
예제 #7
0
        private static void ApplyShadow <T>(GraphicStyleData style, UIReference <T> reference)
            where T : Graphic
        {
            var gameObject = reference.value.gameObject;

            switch (style.shadowType.resolvedValue)
            {
            case GraphicStyleData.ShadowType.None:
                if (reference.shadow)
                {
                    Destroy(reference.shadow);
                    reference.shadow = null;
                }

                break;

            case GraphicStyleData.ShadowType.Shadow:
                if (!reference.shadow || reference.shadow.GetType() != typeof(Shadow))
                {
                    Destroy(reference.shadow);
                    reference.shadow = gameObject.AddComponent <Shadow>();
                }

                break;

            case GraphicStyleData.ShadowType.Outline:
                if (!reference.shadow || reference.shadow.GetType() != typeof(Outline))
                {
                    Destroy(reference.shadow);
                    reference.shadow = gameObject.AddComponent <Outline>();
                }

                break;
            }

            if (!reference.shadow)
            {
                return;
            }

            // shadow marks layout as dirty on value update, don't update without changes
            if (reference.shadow.effectColor != style.shadowColor)
            {
                reference.shadow.effectColor = style.shadowColor;
            }

            if (reference.shadow.effectDistance != style.shadowDistance)
            {
                reference.shadow.effectDistance = style.shadowDistance;
            }

            if (reference.shadow.useGraphicAlpha != style.shadowUseGraphicAlpha)
            {
                reference.shadow.useGraphicAlpha = style.shadowUseGraphicAlpha;
            }
        }
예제 #8
0
        private static void ApplyImageStyle <T>(ImageStyleData style, UIReference <T> reference)
            where T : Image
        {
            reference.value.sprite                  = style.sprite;
            reference.value.preserveAspect          = style.preserveAspect;
            reference.value.fillCenter              = style.fillCenter;
            reference.value.useSpriteMesh           = style.useSpriteMesh;
            reference.value.pixelsPerUnitMultiplier = style.pixelsPerUnitMultiplier;

            ApplyGraphicStyle(style, reference);
        }
예제 #9
0
        private static void ApplyInputFieldStyle <T>(InputFieldStyleData style, UIReference <T> reference)
            where T : InputField
        {
            reference.value.caretBlinkRate = style.caretBlinkRate;
            reference.value.caretWidth     = style.caretWidth;
            reference.value.selectionColor = style.selectionColor;

            // use custom caret color if property set
            reference.value.customCaretColor = style.caretColor.IsResolved;

            ApplySelectableStyle(style, reference);
        }
예제 #10
0
        private static void ApplyContentSizeFitter <T>(ElementStyleData style, UIReference <T> reference)
            where T : MonoBehaviour
        {
            var horizontalFit = style.horizontalFit;
            var verticalFit   = style.verticalFit;

            var useFitter = horizontalFit != ContentSizeFitter.FitMode.Unconstrained ||
                            verticalFit != ContentSizeFitter.FitMode.Unconstrained;

            if (UpdateComponent(reference.value, ref reference.sizeFitter, useFitter))
            {
                reference.sizeFitter.horizontalFit = horizontalFit;
                reference.sizeFitter.verticalFit   = verticalFit;
            }
        }
예제 #11
0
        private static void ApplyStyle <S, T>(S style, UIReference <T> data, StyleApplyFunc <S, T> apply)
            where S : ElementStyleData, new()
            where T : MonoBehaviour
        {
            if (!data.value)
            {
                return;
            }

            if (!Application.isPlaying)
            {
                data.UpdateReferences();
            }

            apply(style, data);
            ApplyLayout(style, data);
        }
예제 #12
0
        private static void ApplySelectableStyle <T>(SelectableStyleData style, UIReference <T> reference)
            where T : Selectable
        {
            reference.value.transition = style.transition;

            switch (reference.value.transition)
            {
            case Selectable.Transition.ColorTint:
            {
                var colorBlock    = reference.value.colors;
                var originalBlock = colorBlock;
                colorBlock.normalColor      = style.colorNormal;
                colorBlock.highlightedColor = style.colorHighlighted;
                colorBlock.pressedColor     = style.colorPressed;
                colorBlock.selectedColor    = style.colorSelected;
                colorBlock.disabledColor    = style.colorDisabled;
                colorBlock.colorMultiplier  = style.colorMultiplier;
                colorBlock.fadeDuration     = style.colorFadeDuration;

                if (!colorBlock.Equals(originalBlock))
                {
                    reference.value.colors = colorBlock;
                }

                break;
            }

            case Selectable.Transition.SpriteSwap:
            {
                var spriteBlock   = reference.value.spriteState;
                var originalBlock = spriteBlock;
                spriteBlock.selectedSprite    = style.spriteSelected;
                spriteBlock.highlightedSprite = style.spriteHighlighted;
                spriteBlock.pressedSprite     = style.spritePressed;
                spriteBlock.disabledSprite    = style.spriteDisabled;

                if (!spriteBlock.Equals(originalBlock))
                {
                    reference.value.spriteState = spriteBlock;
                }

                break;
            }
            }
        }
예제 #13
0
        private static void ApplyTextStyle <T>(TextStyleData style, UIReference <T> reference)
            where T : Text
        {
            var fontValue = style.font.resolvedValue;

            if (fontValue)
            {
                reference.value.font = fontValue;
            }

            reference.value.fontStyle            = style.fontStyle;
            reference.value.fontSize             = style.fontSize;
            reference.value.lineSpacing          = style.lineSpacing;
            reference.value.supportRichText      = style.richText;
            reference.value.alignment            = style.alignment;
            reference.value.alignByGeometry      = style.alignByGeometry;
            reference.value.horizontalOverflow   = style.horizontalOverflow;
            reference.value.verticalOverflow     = style.verticalOverflow;
            reference.value.resizeTextForBestFit = style.bestFit;
            reference.value.resizeTextMinSize    = style.bestFitMinSize;
            reference.value.resizeTextMaxSize    = style.bestFitMaxSize;

            ApplyGraphicStyle(style, reference);
        }
예제 #14
0
 public static void Apply(DropdownStyleData style, UIReference <Dropdown> field) =>
 ApplyStyle(style, field, applyDropdown);
예제 #15
0
 public static void Apply(SliderStyleData style, UIReference <Slider> field) =>
 ApplyStyle(style, field, applySlider);
예제 #16
0
 public static void Apply(InputFieldStyleData style, UIReference <InputField> field) =>
 ApplyStyle(style, field, applyInputField);
예제 #17
0
 public static void Apply(ScrollbarStyleData style, UIReference <Scrollbar> scroll) =>
 ApplyStyle(style, scroll, applyScrollBar);
예제 #18
0
 public static void Apply(ScrollRectStyleData style, UIReference <ScrollRect> scroll) =>
 ApplyStyle(style, scroll, applyScrollRect);
예제 #19
0
 public static void Apply(ToggleStyleData style, UIReference <Toggle> toggle) =>
 ApplyStyle(style, toggle, applyToggle);
예제 #20
0
 public static void Apply(GraphicStyleData style, UIReference <Graphic> graphic) =>
 ApplyStyle(style, graphic, applyGraphic);
예제 #21
0
 public static void Apply(TextStyleData style, UIReference <Text> text) =>
 ApplyStyle(style, text, applyText);
예제 #22
0
 private static void ApplySliderStyle <T>(SliderStyleData style, UIReference <T> reference)
     where T : Slider
 {
     ApplySelectableStyle(style, reference);
 }
예제 #23
0
 private static void ApplyScrollbarStyle <T>(ScrollbarStyleData style, UIReference <T> reference)
     where T : Scrollbar
 {
     ApplySelectableStyle(style, reference);
 }
예제 #24
0
 public static void Apply(ButtonStyleData style, UIReference <Button> button) =>
 ApplyStyle(style, button, applyButton);
예제 #25
0
 public static void Apply(ImageStyleData style, UIReference <Image> image) =>
 ApplyStyle(style, image, applyImage);
예제 #26
0
 private static void ApplyButtonStyle <T>(ButtonStyleData style, UIReference <T> reference)
     where T : Button
 {
     ApplySelectableStyle(style, reference);
 }