Example #1
0
 protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
 {
     if (this.isHighlightDisabled)
     {
         Color  disabledHighlightedColor   = this._disabledHighlightedColor;
         Sprite disabledHighlightedSprite  = this._disabledHighlightedSprite;
         string disabledHighlightedTrigger = this._disabledHighlightedTrigger;
         if (base.gameObject.activeInHierarchy)
         {
             Selectable.Transition transition = base.transition;
             if (transition != Selectable.Transition.ColorTint)
             {
                 if (transition != Selectable.Transition.SpriteSwap)
                 {
                     if (transition == Selectable.Transition.Animation)
                     {
                         this.TriggerAnimation(disabledHighlightedTrigger);
                     }
                 }
                 else
                 {
                     this.DoSpriteSwap(disabledHighlightedSprite);
                 }
             }
             else
             {
                 this.StartColorTween(disabledHighlightedColor * base.colors.colorMultiplier, instant);
             }
         }
     }
     else
     {
         base.DoStateTransition(state, instant);
     }
 }
Example #2
0
    protected override void GUI()
    {
        base.GUI();

        Selectable.Transition transition = Selectable.Transition.SpriteSwap;
        Sprite      backgroundSprite     = Data.BackgroundSprite;
        Sprite      handleSprite         = Data.DefaultHandleSprite;
        SpriteState spriteState          = Data.DefaultHandleSpriteState;
        ColorBlock  colors = new ColorBlock();

        colors.colorMultiplier = 1;
        colors.fadeDuration    = 0.1f;

        switch (Type)
        {
        case ScrollbarType.Default:
            transition = Selectable.Transition.ColorTint;

            colors.normalColor      = Data.NormalColor;
            colors.highlightedColor = Data.HighlightedColor;
            colors.pressedColor     = Data.PressedColor;
            colors.disabledColor    = Data.DisableColor;

            break;
        }

        // Set Scrollbar
        scrollbar.transition   = transition;
        scrollbar.colors       = colors;
        scrollbar.spriteState  = spriteState;
        backgroundImage.sprite = backgroundSprite;
        handleImage.sprite     = handleSprite;
    }
Example #3
0
 public override void Setup(AbstractView view)
 {
     _button           = GetComponent <Button>();
     _buttonTransition = _button.transition;
     _button.onClick.AddListener(ButtonClicked);
     base.Setup(view);
 }
Example #4
0
        public override void Reset()
        {
            gameObject = null;
            transition = Selectable.Transition.ColorTint;

            resetOnExit = false;
        }
 protected virtual void OnEnable()
 {
     this.m_Script = base.serializedObject.FindProperty("m_Script");
     this.m_InteractableProperty  = base.serializedObject.FindProperty("m_Interactable");
     this.m_TargetGraphicProperty = base.serializedObject.FindProperty("m_TargetGraphic");
     this.m_TransitionProperty    = base.serializedObject.FindProperty("m_Transition");
     this.m_ColorBlockProperty    = base.serializedObject.FindProperty("m_Colors");
     this.m_SpriteStateProperty   = base.serializedObject.FindProperty("m_SpriteState");
     this.m_AnimTriggerProperty   = base.serializedObject.FindProperty("m_AnimationTriggers");
     this.m_NavigationProperty    = base.serializedObject.FindProperty("m_Navigation");
     this.m_PropertyPathToExcludeForChildClasses = new string[]
     {
         this.m_Script.propertyPath,
         this.m_NavigationProperty.propertyPath,
         this.m_TransitionProperty.propertyPath,
         this.m_ColorBlockProperty.propertyPath,
         this.m_SpriteStateProperty.propertyPath,
         this.m_AnimTriggerProperty.propertyPath,
         this.m_InteractableProperty.propertyPath,
         this.m_TargetGraphicProperty.propertyPath
     };
     Selectable.Transition transition = SelectableEditor.GetTransition(this.m_TransitionProperty);
     this.m_ShowColorTint.value       = (transition == Selectable.Transition.ColorTint);
     this.m_ShowSpriteTrasition.value = (transition == Selectable.Transition.SpriteSwap);
     this.m_ShowAnimTransition.value  = (transition == Selectable.Transition.Animation);
     this.m_ShowColorTint.valueChanged.AddListener(new UnityAction(base.Repaint));
     this.m_ShowSpriteTrasition.valueChanged.AddListener(new UnityAction(base.Repaint));
     SelectableEditor.s_Editors.Add(this);
     this.RegisterStaticOnSceneGUI();
     SelectableEditor.s_ShowNavigation = EditorPrefs.GetBool(SelectableEditor.s_ShowNavigationKey);
 }
        protected virtual void InstantClearState()
        {
            string normalTrigger = this.m_AnimationTriggers.normalTrigger;

            this.isPointerInside = false;
            this.isPointerDown   = false;
            this.hasSelection    = false;
            Selectable.Transition transition = this.m_Transition;
            if (transition != Selectable.Transition.ColorTint)
            {
                if (transition != Selectable.Transition.SpriteSwap)
                {
                    if (transition == Selectable.Transition.Animation)
                    {
                        this.TriggerAnimation(normalTrigger);
                    }
                }
                else
                {
                    this.DoSpriteSwap(null);
                }
            }
            else
            {
                this.StartColorTween(Color.white, true);
            }
        }
Example #7
0
    protected override void GUI()
    {
        base.GUI();

        Selectable.Transition transition = Selectable.Transition.SpriteSwap;
        Sprite      sprite          = Data.DefaultSprite;
        Sprite      checkmarkSprite = Data.CheckmarkSprite;
        SpriteState spriteState     = Data.DefaultSpriteState;
        ColorBlock  colors          = new ColorBlock();

        colors.colorMultiplier = 1;
        colors.fadeDuration    = 0.1f;


        switch (Type)
        {
        case ToggleType.Default:
            transition = Selectable.Transition.ColorTint;

            colors.normalColor      = Data.NormalColor;
            colors.highlightedColor = Data.HighlightedColor;
            colors.pressedColor     = Data.PressedColor;
            colors.disabledColor    = Data.DisableColor;
            break;
        }

        // Set Toggle
        toggle.transition      = transition;
        toggle.colors          = colors;
        toggle.spriteState     = spriteState;
        backgroundImage.sprite = sprite;
        checkmarkImage.sprite  = checkmarkSprite;
    }
Example #8
0
        private void Init()
        {
            LevelCategoryButton levelCategoryButton = GameStateMachine.Instance.LevelSelectionObject.GetComponentInChildren <LevelCategoryButton>();

            normalFont      = levelCategoryButton.normalFont;
            highlightedFont = levelCategoryButton.highlightedFont;
            transition      = levelCategoryButton.transition;
            color           = levelCategoryButton.colors;
        }
Example #9
0
 private void InitVar()
 {
     m_button             = GetComponent <Button>();
     m_transition         = m_button.transition;
     m_originalColorBlock = m_button.colors;
     m_image         = GetComponent <Image>();
     m_originalColor = m_image.color;
     m_UIObject      = GetComponent <KaiTool_BasicUIObject>();
 }
Example #10
0
 static Selectable.Transition?ParseTransition(string str)
 {
     if (String.IsNullOrEmpty(str))
     {
         return(null);
     }
     Selectable.Transition transition = Selectable.Transition.ColorTint;
     transition = KodeUI_Utils.ToEnum <Selectable.Transition> (str, transition);
     return(transition);
 }
 public SelectableObjectProperties(Selectable selectable)
 {
     animationTriggers = selectable.animationTriggers;
     colors            = selectable.colors;
     image             = selectable.image;
     interactable      = selectable.interactable;
     navigation        = selectable.navigation;
     spriteState       = selectable.spriteState;
     targetGraphic     = selectable.targetGraphic;
     transition        = selectable.transition;
 }
Example #12
0
        /// <summary>
        /// Draws the option background layout properties.
        /// </summary>
        public void DrawOptionBackgroundLayoutProperties()
        {
            EditorGUILayout.LabelField("Option Background Layout", EditorStyles.boldLabel);
            EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
            EditorGUILayout.PropertyField(this.m_OptionBackgroundSpriteProperty, new GUIContent("Sprite"));

            if (this.m_OptionBackgroundSpriteProperty.objectReferenceValue != null)
            {
                EditorGUILayout.PropertyField(this.m_OptionBackgroundSpriteTypeProperty, new GUIContent("Sprite Type"));
                EditorGUILayout.PropertyField(this.m_OptionBackgroundSpriteColorProperty, new GUIContent("Sprite Color"));
                EditorGUILayout.PropertyField(this.m_OptionBackgroundTransitionTypeProperty, new GUIContent("Transition"));

                Selectable.Transition optionBgTransition = (Selectable.Transition) this.m_OptionBackgroundTransitionTypeProperty.enumValueIndex;

                if (optionBgTransition != Selectable.Transition.None)
                {
                    EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
                    if (optionBgTransition == Selectable.Transition.ColorTint)
                    {
                        EditorGUILayout.PropertyField(this.m_OptionBackgroundTransColorsProperty, true);
                    }
                    else if (optionBgTransition == Selectable.Transition.SpriteSwap)
                    {
                        EditorGUILayout.PropertyField(this.m_OptionBackgroundSpriteStatesProperty, true);
                    }
                    else if (optionBgTransition == Selectable.Transition.Animation)
                    {
                        EditorGUILayout.PropertyField(this.m_OptionBackgroundAnimatorControllerProperty, new GUIContent("Animator Controller"));
                        EditorGUILayout.PropertyField(this.m_OptionBackgroundAnimationTriggersProperty, true);

                        if (this.m_OptionBackgroundAnimatorControllerProperty.objectReferenceValue == null)
                        {
                            Rect controlRect = EditorGUILayout.GetControlRect();
                            controlRect.xMin = (controlRect.xMin + EditorGUIUtility.labelWidth);

                            if (GUI.Button(controlRect, "Auto Generate Animation", EditorStyles.miniButton))
                            {
                                // Generate the animator controller
                                UnityEditor.Animations.AnimatorController animatorController = UIAnimatorControllerGenerator.GenerateAnimatorContoller(this.m_OptionBackgroundAnimationTriggersProperty, target.name + " - Option Background");

                                // Apply the controller to the property
                                if (animatorController != null)
                                {
                                    this.m_OptionBackgroundAnimatorControllerProperty.objectReferenceValue = animatorController;
                                }
                            }
                        }
                    }
                    EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
                }
            }
            EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
        }
Example #13
0
        protected override void ReadFromImpl(object obj)
        {
            base.ReadFromImpl(obj);
            Selectable uo = (Selectable)obj;

            navigation        = uo.navigation;
            transition        = uo.transition;
            colors            = uo.colors;
            spriteState       = uo.spriteState;
            animationTriggers = uo.animationTriggers;
            targetGraphic     = ToID(uo.targetGraphic);
            interactable      = uo.interactable;
            image             = ToID(uo.image);
        }
            public virtual void Apply(Selectable item)
            {
                Selectable.Transition transition = _transition;
                bool transitionChanged           = item.transition != transition;

                item.transition = transition;

                ICustomSelectable customSel = item as ICustomSelectable;

                if (transition == Selectable.Transition.ColorTint)
                {
                    // Two-step color change to get around delay bug due to fade duration
                    CustomColorBlock cb = _colors;
                    cb.fadeDuration = 0.0f;
                    item.colors     = cb;
                    cb.fadeDuration = _colors.fadeDuration;
                    item.colors     = cb;
                    if (customSel != null)
                    {
                        customSel.disabledHighlightedColor = cb.disabledHighlightedColor;
                    }
                }
                else if (transition == Selectable.Transition.SpriteSwap)
                {
                    item.spriteState = _spriteState;
                    if (customSel != null)
                    {
                        customSel.disabledHighlightedSprite = _spriteState.disabledHighlightedSprite;
                    }
                }
                else if (transition == Selectable.Transition.Animation)
                {
                    item.animationTriggers.disabledTrigger    = _animationTriggers.disabledTrigger;
                    item.animationTriggers.highlightedTrigger = _animationTriggers.highlightedTrigger;
                    item.animationTriggers.normalTrigger      = _animationTriggers.normalTrigger;
                    item.animationTriggers.pressedTrigger     = _animationTriggers.pressedTrigger;
                    if (customSel != null)
                    {
                        customSel.disabledHighlightedTrigger = _animationTriggers.disabledHighlightedTrigger;
                    }
                }

                if (transitionChanged)
                {
                    item.targetGraphic.CrossFadeColor(item.targetGraphic.color, 0.0f, true, true);                   // force color to revert to default or it will be left with color tint
                }
            }
            public virtual void Apply(Selectable item)
            {
                Selectable.Transition transition = this._transition;
                bool flag = item.get_transition() != transition;

                item.set_transition(transition);
                ICustomSelectable customSelectable = item as ICustomSelectable;

                if (transition == 1)
                {
                    ThemeSettings.CustomColorBlock colors = this._colors;
                    colors.fadeDuration = 0.0f;
                    item.set_colors((ColorBlock)colors);
                    colors.fadeDuration = this._colors.fadeDuration;
                    item.set_colors((ColorBlock)colors);
                    if (customSelectable != null)
                    {
                        customSelectable.disabledHighlightedColor = colors.disabledHighlightedColor;
                    }
                }
                else if (transition == 2)
                {
                    item.set_spriteState((SpriteState)this._spriteState);
                    if (customSelectable != null)
                    {
                        customSelectable.disabledHighlightedSprite = this._spriteState.disabledHighlightedSprite;
                    }
                }
                else if (transition == 3)
                {
                    item.get_animationTriggers().set_disabledTrigger(this._animationTriggers.disabledTrigger);
                    item.get_animationTriggers().set_highlightedTrigger(this._animationTriggers.highlightedTrigger);
                    item.get_animationTriggers().set_normalTrigger(this._animationTriggers.normalTrigger);
                    item.get_animationTriggers().set_pressedTrigger(this._animationTriggers.pressedTrigger);
                    if (customSelectable != null)
                    {
                        customSelectable.disabledHighlightedTrigger = this._animationTriggers.disabledHighlightedTrigger;
                    }
                }
                if (!flag)
                {
                    return;
                }
                item.get_targetGraphic().CrossFadeColor(item.get_targetGraphic().get_color(), 0.0f, true, true);
            }
Example #16
0
        public override void OnEnter()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (UpdateCache(go))
            {
                selectable = cachedComponent;
            }

            if (selectable != null && resetOnExit.Value)
            {
                originalTransition = selectable.transition;
            }

            DoSetValue();

            Finish();
        }
Example #17
0
            public virtual void Apply(Selectable item)
            {
                Selectable.Transition transition = this._transition;
                bool flag = item.transition != transition;

                item.transition = transition;
                ICustomSelectable customSelectable = item as ICustomSelectable;

                if (transition == Selectable.Transition.ColorTint)
                {
                    ThemeSettings.CustomColorBlock colors = this._colors;
                    colors.fadeDuration = 0f;
                    item.colors         = colors;
                    colors.fadeDuration = this._colors.fadeDuration;
                    item.colors         = colors;
                    if (customSelectable != null)
                    {
                        customSelectable.disabledHighlightedColor = colors.disabledHighlightedColor;
                    }
                }
                else if (transition == Selectable.Transition.SpriteSwap)
                {
                    item.spriteState = this._spriteState;
                    if (customSelectable != null)
                    {
                        customSelectable.disabledHighlightedSprite = this._spriteState.disabledHighlightedSprite;
                    }
                }
                else if (transition == Selectable.Transition.Animation)
                {
                    item.animationTriggers.disabledTrigger    = this._animationTriggers.disabledTrigger;
                    item.animationTriggers.highlightedTrigger = this._animationTriggers.highlightedTrigger;
                    item.animationTriggers.normalTrigger      = this._animationTriggers.normalTrigger;
                    item.animationTriggers.pressedTrigger     = this._animationTriggers.pressedTrigger;
                    if (customSelectable != null)
                    {
                        customSelectable.disabledHighlightedTrigger = this._animationTriggers.disabledHighlightedTrigger;
                    }
                }
                if (flag)
                {
                    item.targetGraphic.CrossFadeColor(item.targetGraphic.color, 0f, true, true);
                }
            }
    protected override void GUI()
    {
        base.GUI();

        Selectable.Transition transition = Selectable.Transition.SpriteSwap;
        Sprite      sprite      = Data.DefaultSprite;
        SpriteState spriteState = Data.DefaultSpriteState;
        ColorBlock  colors      = new ColorBlock();

        colors.colorMultiplier = 1;
        colors.fadeDuration    = 0.1f;

        int   fontSize             = Data.FontSize;
        Font  font                 = Data.Font;
        Color fontColor            = Data.FontColor;
        Font  placeHolderFont      = Data.PlaceHolderFont;
        Color placeHolderFontColor = Data.PlaceHolderFontColor;

        switch (Type)
        {
        case InputFieldType.Default:
            transition = Selectable.Transition.ColorTint;

            colors.normalColor      = Data.NormalColor;
            colors.highlightedColor = Data.HighlightedColor;
            colors.pressedColor     = Data.PressedColor;
            colors.disabledColor    = Data.DisableColor;
            break;
        }

        inputField.transition  = transition;
        inputField.colors      = colors;
        inputField.spriteState = spriteState;
        image.sprite           = sprite;

        text.fontSize = fontSize;
        text.font     = font;
        text.color    = fontColor;

        placeHolderText.fontSize  = fontSize;
        placeHolderText.font      = placeHolderFont;
        placeHolderText.color     = placeHolderFontColor;
        placeHolderText.fontStyle = FontStyle.Italic;
    }
    private static int get_transition(IntPtr L)
    {
        object obj = null;
        int    result;

        try
        {
            obj = ToLua.ToObject(L, 1);
            Selectable            selectable = (Selectable)obj;
            Selectable.Transition transition = selectable.transition;
            ToLua.Push(L, transition);
            result = 1;
        }
        catch (Exception ex)
        {
            result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index transition on a nil value");
        }
        return(result);
    }
Example #20
0
        public static Toggle CreateToggle(Node parent, Selectable.Transition transition = Selectable.Transition.SpriteSwap)
        {
            var node = new Node {
                name = "Toggle", parent = parent, size = new Vector2(100, 16)
            };
            var toggle = node.AddLeaf <Toggle>();

            toggle.transition = transition;
            toggle.colorState = new Selectable.ColorState()
            {
                normalColor   = Color.white,
                focusedColor  = Color.white,
                pressedColor  = DefaultPressedTintColor,
                disabledColor = DefaultDisabledTintColor,
            };
            var normalSprite  = AssetDatabase.LoadAssetAtPath <Sprite>(DefaultResource.DefaultToggleSprite);
            var pressedSprite = AssetDatabase.LoadAssetAtPath <Sprite>(DefaultResource.DefaultToggleActiveSprite);
            var bg            = CreateImage(node);

            bg.node.name             = "Background";
            bg.node.anchoredPosition = new Vector2(0, 2);
            bg.sprite = normalSprite;
            bg.SetNativeSize();
            toggle.targetGraphic = bg;
            toggle.spriteState   = new Selectable.SpriteState()
            {
                pressedSprite = pressedSprite
            };
            var mark = CreateImage(bg.node);

            mark.node.name = "Checkmark";
            mark.sprite    = AssetDatabase.LoadAssetAtPath <Sprite>(DefaultResource.DefaultToggleCheckmarkSprite);
            mark.SetNativeSize();
            toggle.toggleGraphic = mark;
            var text = CreateText(node);

            text.text           = "Toggle";
            text.alignment      = TextAnchor.UpperLeft;
            text.node.anchorMin = Vector2.zero;
            text.node.anchorMax = Vector2.one;
            text.node.offsetMin = new Vector2(bg.node.size.x, 0);
            return(toggle);
        }
    private static int set_transition(IntPtr L)
    {
        object obj = null;
        int    result;

        try
        {
            obj = ToLua.ToObject(L, 1);
            Selectable            selectable = (Selectable)obj;
            Selectable.Transition transition = (Selectable.Transition)((int)ToLua.CheckObject(L, 2, typeof(Selectable.Transition)));
            selectable.transition = transition;
            result = 0;
        }
        catch (Exception ex)
        {
            result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index transition on a nil value");
        }
        return(result);
    }
Example #22
0
    protected override void GUI()
    {
        base.GUI();

        Selectable.Transition transition = Selectable.Transition.SpriteSwap;
        Sprite      sprite      = Data.DefaultSprite;
        Sprite      iconSprite  = Data.DefaultIconSprite;
        SpriteState spriteState = Data.DefaultSpriteState;
        ColorBlock  colors      = new ColorBlock();

        colors.colorMultiplier = 1;
        colors.fadeDuration    = 0.1f;

        int   fontSize  = Data.FontSize;
        Font  font      = Data.Font;
        Color fontColor = Data.FontColor;;

        switch (Type)
        {
        case ButtonType.Default:

            transition = Selectable.Transition.ColorTint;

            colors.normalColor      = Data.NormalColor;
            colors.highlightedColor = Data.HighlightedColor;
            colors.pressedColor     = Data.PressedColor;
            colors.disabledColor    = Data.DisableColor;
            break;
        }

        // Set Button
        button.transition  = transition;
        button.colors      = colors;
        button.spriteState = spriteState;
        image.sprite       = sprite;
        iconImage.sprite   = iconSprite;

        text.fontSize = fontSize;
        text.font     = font;
        text.color    = fontColor;
    }
Example #23
0
 protected virtual void DoStateTransition(Selectable.SelectionState state, bool instant)
 {
     if (this.isHighlightDisabled)
     {
         Color  highlightedColor   = this._disabledHighlightedColor;
         Sprite highlightedSprite  = this._disabledHighlightedSprite;
         string highlightedTrigger = this._disabledHighlightedTrigger;
         if (!((Component)this).get_gameObject().get_activeInHierarchy())
         {
             return;
         }
         Selectable.Transition transition = ((Selectable)this).get_transition();
         if (transition != 1)
         {
             if (transition != 2)
             {
                 if (transition != 3)
                 {
                     return;
                 }
                 this.TriggerAnimation(highlightedTrigger);
             }
             else
             {
                 this.DoSpriteSwap(highlightedSprite);
             }
         }
         else
         {
             Color      color           = highlightedColor;
             ColorBlock colors          = ((Selectable)this).get_colors();
             double     colorMultiplier = (double)((ColorBlock) ref colors).get_colorMultiplier();
             this.StartColorTween(Color.op_Multiply(color, (float)colorMultiplier), instant);
         }
     }
     else
     {
         ((Selectable)this).DoStateTransition(state, instant);
     }
 }
Example #24
0
        private void DrawTargetImageProperties()
        {
            EditorGUILayout.LabelField("Image Target Properties", EditorStyles.boldLabel);
            EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);

            EditorGUILayout.PropertyField(this.m_ImageTargetProperty);

            // Check if image is set
            if (this.m_ImageTargetProperty.objectReferenceValue != null)
            {
                Image image = (this.m_ImageTargetProperty.objectReferenceValue as Image);

                EditorGUILayout.PropertyField(this.m_ImageTransitionProperty);

                // Get the selected transition
                Selectable.Transition transition = (Selectable.Transition) this.m_ImageTransitionProperty.enumValueIndex;

                if (transition != Selectable.Transition.None)
                {
                    EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
                    if (transition == Selectable.Transition.ColorTint)
                    {
                        EditorGUILayout.PropertyField(this.m_ImageColorsProperty);
                    }
                    else if (transition == Selectable.Transition.SpriteSwap)
                    {
                        EditorGUILayout.PropertyField(this.m_ImageSpriteStateProperty);
                    }
                    else if (transition == Selectable.Transition.Animation)
                    {
                        //
                    }
                    EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
                }
            }

            EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
        }
Example #25
0
        public static Button CreateButton(Node parent, Selectable.Transition transition = Selectable.Transition.SpriteSwap)
        {
            var image = CreateImage(parent);
            var node  = image.node;

            node.name = "Button";
            node.size = new Vector2(60, 25);
            var button = node.AddLeaf <Button>();

            button.targetGraphic = image;
            button.transition    = transition;
            button.colorState    = new Selectable.ColorState()
            {
                normalColor   = Color.white,
                focusedColor  = Color.white,
                pressedColor  = DefaultPressedTintColor,
                disabledColor = DefaultDisabledTintColor,
            };
            var normalSprite  = AssetDatabase.LoadAssetAtPath <Sprite>(DefaultResource.DefaultButtonSprite);
            var pressedSprite = AssetDatabase.LoadAssetAtPath <Sprite>(DefaultResource.DefaultButtonActiveSprite);

            button.spriteState = new Selectable.SpriteState()
            {
                pressedSprite = pressedSprite
            };
            image.sprite = normalSprite;
            var text = CreateText(button.node);

            text.text           = "Button";
            text.alignment      = TextAnchor.MiddleCenter;
            text.node.anchorMin = Vector2.zero;
            text.node.anchorMax = Vector2.one;
            text.node.offsetMin = Vector2.zero;
            text.node.offsetMax = new Vector2(0, 3);
            return(button);
        }
        private void DrawTargetImageProperties()
        {
            bool newState = EditorGUILayout.Foldout(this.showImageProperties, "Image Target Properties", this.m_FoldoutStyle);

            if (newState != this.showImageProperties)
            {
                EditorPrefs.SetBool(PREFS_KEY + "1", newState);
                this.showImageProperties = newState;
            }

            if (this.showImageProperties)
            {
                EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);

                EditorGUILayout.PropertyField(this.m_ImageTargetProperty);

                // Check if image is set
                if (this.m_ImageTargetProperty.objectReferenceValue != null)
                {
                    Image image = (this.m_ImageTargetProperty.objectReferenceValue as Image);

                    EditorGUILayout.PropertyField(this.m_ImageTransitionProperty);

                    // Get the selected transition
                    Selectable.Transition transition = (Selectable.Transition) this.m_ImageTransitionProperty.enumValueIndex;

                    if (transition != Selectable.Transition.None)
                    {
                        EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
                        if (transition == Selectable.Transition.ColorTint)
                        {
                            EditorGUILayout.PropertyField(this.m_ImageColorsProperty);
                        }
                        else if (transition == Selectable.Transition.SpriteSwap)
                        {
                            EditorGUILayout.PropertyField(this.m_ImageSpriteStateProperty);
                        }
                        else if (transition == Selectable.Transition.Animation)
                        {
                            EditorGUILayout.PropertyField(this.m_ImageAnimationTriggersProperty);

                            Animator animator = image.gameObject.GetComponent <Animator>();

                            if (animator == null || animator.runtimeAnimatorController == null)
                            {
                                Rect controlRect = EditorGUILayout.GetControlRect();
                                controlRect.xMin = (controlRect.xMin + EditorGUIUtility.labelWidth);

                                if (GUI.Button(controlRect, "Auto Generate Animation", EditorStyles.miniButton))
                                {
                                    // Generate the animator controller
                                    UnityEditor.Animations.AnimatorController animatorController = UIAnimatorControllerGenerator.GenerateAnimatorContoller(this.m_ImageAnimationTriggersProperty, this.target.name);

                                    if (animatorController != null)
                                    {
                                        if (animator == null)
                                        {
                                            animator = image.gameObject.AddComponent <Animator>();
                                        }
                                        UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, animatorController);
                                    }
                                }
                            }
                        }
                        EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
                    }
                }

                EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
            }
        }
Example #27
0
        protected virtual void DoStateTransition(Selectable.SelectionState state, bool instant)
        {
            Color  a;
            Sprite newSprite;
            string triggername;

            switch (state)
            {
            case Selectable.SelectionState.Normal:
                a           = this.m_Colors.normalColor;
                newSprite   = null;
                triggername = this.m_AnimationTriggers.normalTrigger;
                break;

            case Selectable.SelectionState.Highlighted:
                a           = this.m_Colors.highlightedColor;
                newSprite   = this.m_SpriteState.highlightedSprite;
                triggername = this.m_AnimationTriggers.highlightedTrigger;
                break;

            case Selectable.SelectionState.Pressed:
                a           = this.m_Colors.pressedColor;
                newSprite   = this.m_SpriteState.pressedSprite;
                triggername = this.m_AnimationTriggers.pressedTrigger;
                break;

            case Selectable.SelectionState.Disabled:
                a           = this.m_Colors.disabledColor;
                newSprite   = this.m_SpriteState.disabledSprite;
                triggername = this.m_AnimationTriggers.disabledTrigger;
                break;

            default:
                a           = Color.black;
                newSprite   = null;
                triggername = string.Empty;
                break;
            }
            if (base.gameObject.activeInHierarchy)
            {
                Selectable.Transition transition = this.m_Transition;
                if (transition != Selectable.Transition.ColorTint)
                {
                    if (transition != Selectable.Transition.SpriteSwap)
                    {
                        if (transition == Selectable.Transition.Animation)
                        {
                            this.TriggerAnimation(triggername);
                        }
                    }
                    else
                    {
                        this.DoSpriteSwap(newSprite);
                    }
                }
                else
                {
                    this.StartColorTween(a * this.m_Colors.colorMultiplier, instant);
                }
            }
        }
        public override void OnInspectorGUI()
        {
            base.serializedObject.Update();
            EditorGUILayout.PropertyField(this.m_InteractableProperty, new GUILayoutOption[0]);
            Selectable.Transition transition = SelectableEditor.GetTransition(this.m_TransitionProperty);
            Graphic graphic = this.m_TargetGraphicProperty.objectReferenceValue as Graphic;

            if (graphic == null)
            {
                graphic = (base.target as Selectable).GetComponent <Graphic>();
            }
            Animator animator = (base.target as Selectable).GetComponent <Animator>();

            this.m_ShowColorTint.target       = (!this.m_TransitionProperty.hasMultipleDifferentValues && transition == Selectable.Transition.ColorTint);
            this.m_ShowSpriteTrasition.target = (!this.m_TransitionProperty.hasMultipleDifferentValues && transition == Selectable.Transition.SpriteSwap);
            this.m_ShowAnimTransition.target  = (!this.m_TransitionProperty.hasMultipleDifferentValues && transition == Selectable.Transition.Animation);
            EditorGUILayout.PropertyField(this.m_TransitionProperty, new GUILayoutOption[0]);
            EditorGUI.indentLevel++;
            if (transition == Selectable.Transition.ColorTint || transition == Selectable.Transition.SpriteSwap)
            {
                EditorGUILayout.PropertyField(this.m_TargetGraphicProperty, new GUILayoutOption[0]);
            }
            if (transition != Selectable.Transition.ColorTint)
            {
                if (transition == Selectable.Transition.SpriteSwap)
                {
                    if (graphic as Image == null)
                    {
                        EditorGUILayout.HelpBox("You must have a Image target in order to use a sprite swap transition.", MessageType.Warning);
                    }
                }
            }
            else if (graphic == null)
            {
                EditorGUILayout.HelpBox("You must have a Graphic target in order to use a color transition.", MessageType.Warning);
            }
            if (EditorGUILayout.BeginFadeGroup(this.m_ShowColorTint.faded))
            {
                EditorGUILayout.PropertyField(this.m_ColorBlockProperty, new GUILayoutOption[0]);
            }
            EditorGUILayout.EndFadeGroup();
            if (EditorGUILayout.BeginFadeGroup(this.m_ShowSpriteTrasition.faded))
            {
                EditorGUILayout.PropertyField(this.m_SpriteStateProperty, new GUILayoutOption[0]);
            }
            EditorGUILayout.EndFadeGroup();
            if (EditorGUILayout.BeginFadeGroup(this.m_ShowAnimTransition.faded))
            {
                EditorGUILayout.PropertyField(this.m_AnimTriggerProperty, new GUILayoutOption[0]);
                if (animator == null || animator.runtimeAnimatorController == null)
                {
                    Rect controlRect = EditorGUILayout.GetControlRect(new GUILayoutOption[0]);
                    controlRect.xMin += EditorGUIUtility.labelWidth;
                    if (GUI.Button(controlRect, "Auto Generate Animation", EditorStyles.miniButton))
                    {
                        AnimatorController animatorController = SelectableEditor.GenerateSelectableAnimatorContoller((base.target as Selectable).animationTriggers, base.target as Selectable);
                        if (animatorController != null)
                        {
                            if (animator == null)
                            {
                                animator = (base.target as Selectable).gameObject.AddComponent <Animator>();
                            }
                            AnimatorController.SetAnimatorController(animator, animatorController);
                        }
                    }
                }
            }
            EditorGUILayout.EndFadeGroup();
            EditorGUI.indentLevel--;
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(this.m_NavigationProperty, new GUILayoutOption[0]);
            EditorGUI.BeginChangeCheck();
            Rect controlRect2 = EditorGUILayout.GetControlRect(new GUILayoutOption[0]);

            controlRect2.xMin += EditorGUIUtility.labelWidth;
            SelectableEditor.s_ShowNavigation = GUI.Toggle(controlRect2, SelectableEditor.s_ShowNavigation, this.m_VisualizeNavigation, EditorStyles.miniButton);
            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetBool(SelectableEditor.s_ShowNavigationKey, SelectableEditor.s_ShowNavigation);
                SceneView.RepaintAll();
            }
            this.ChildClassPropertiesGUI();
            base.serializedObject.ApplyModifiedProperties();
        }
        public override void OnInspectorGUI()
        {
            this.serializedObject.Update();

            Selectable.Transition transition = (Selectable.Transition) this.m_TransitionProperty.enumValueIndex;
            Graphic    graphic          = this.m_TargetGraphicProperty.objectReferenceValue as Graphic;
            GameObject targetGameObject = this.m_TargetGameObjectProperty.objectReferenceValue as GameObject;

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(this.m_TransitionProperty, new GUIContent("Transition"));
            EditorGUI.indentLevel++;

            // Check if the transition requires a graphic
            if (transition == Selectable.Transition.ColorTint || transition == Selectable.Transition.SpriteSwap)
            {
                EditorGUILayout.PropertyField(this.m_TargetGraphicProperty, new GUIContent("Target Graphic"));

                if (transition == Selectable.Transition.ColorTint)
                {
                    if (graphic == null)
                    {
                        EditorGUILayout.HelpBox("You must have a Graphic target in order to use a color transition.", MessageType.Info);
                    }
                    else
                    {
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.PropertyField(this.m_NormalColorProperty, true);
                        if (EditorGUI.EndChangeCheck())
                        {
                            graphic.canvasRenderer.SetColor(this.m_NormalColorProperty.colorValue);
                        }

                        EditorGUILayout.PropertyField(this.m_HighlightedColorProperty, true);
                        EditorGUILayout.PropertyField(this.m_SelectedColorProperty, true);
                        EditorGUILayout.PropertyField(this.m_ColorMultiplierProperty, true);
                        EditorGUILayout.PropertyField(this.m_DurationProperty, true);
                    }
                }
                else if (transition == Selectable.Transition.SpriteSwap)
                {
                    if (graphic as Image == null)
                    {
                        EditorGUILayout.HelpBox("You must have a Image target in order to use a sprite swap transition.", MessageType.Info);
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(this.m_HighlightedSpriteProperty, true);
                        EditorGUILayout.PropertyField(this.m_SelectedSpriteProperty, true);
                    }
                }
            }
            else if (transition == Selectable.Transition.Animation)
            {
                EditorGUILayout.PropertyField(this.m_TargetGameObjectProperty, new GUIContent("Target GameObject"));

                if (targetGameObject == null)
                {
                    EditorGUILayout.HelpBox("You must have a Game Object target in order to use a animation transition.", MessageType.Info);
                }
                else
                {
                    EditorGUILayout.PropertyField(this.m_NormalTriggerProperty, true);
                    EditorGUILayout.PropertyField(this.m_HighlightedTriggerProperty, true);
                    EditorGUILayout.PropertyField(this.m_SelectedTriggerProperty, true);

                    Animator animator = targetGameObject.GetComponent <Animator>();

                    if (animator == null || animator.runtimeAnimatorController == null)
                    {
                        Rect controlRect = EditorGUILayout.GetControlRect();
                        controlRect.xMin = (controlRect.xMin + EditorGUIUtility.labelWidth);

                        if (GUI.Button(controlRect, "Auto Generate Animation", EditorStyles.miniButton))
                        {
                            // Generate the animator controller
                            UnityEditor.Animations.AnimatorController animatorController = this.GenerateAnimatorController();

                            if (animatorController != null)
                            {
                                if (animator == null)
                                {
                                    animator = targetGameObject.AddComponent <Animator>();
                                }
                                UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, animatorController);
                            }
                        }
                    }
                }
            }

            this.serializedObject.ApplyModifiedProperties();
        }
Example #30
0
        /// <summary>
        /// Draws the select field layot properties.
        /// </summary>
        public void DrawSelectFieldLayotProperties()
        {
            EditorGUILayout.LabelField("Select Field Layout", EditorStyles.boldLabel);
            EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);

            EditorGUILayout.PropertyField(this.m_TransitionProperty, new GUIContent("Transition"));

            Graphic graphic = this.m_TargetGraphicProperty.objectReferenceValue as Graphic;

            Selectable.Transition transition = (Selectable.Transition) this.m_TransitionProperty.enumValueIndex;

            // Check if the transition requires a graphic
            if (transition == Selectable.Transition.ColorTint || transition == Selectable.Transition.SpriteSwap)
            {
                EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
                EditorGUILayout.PropertyField(this.m_TargetGraphicProperty);
                EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
            }

            // Check if we have a transition set
            if (transition != Selectable.Transition.None)
            {
                EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);

                if (transition == Selectable.Transition.ColorTint)
                {
                    if (graphic == null)
                    {
                        EditorGUILayout.HelpBox("You must have a Graphic target in order to use a color transition.", MessageType.Info);
                    }
                    else
                    {
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.PropertyField(this.m_ColorBlockProperty, true);
                        if (EditorGUI.EndChangeCheck())
                        {
                            graphic.canvasRenderer.SetColor(this.m_ColorBlockProperty.FindPropertyRelative("m_NormalColor").colorValue);
                        }
                    }
                }
                else if (transition == Selectable.Transition.SpriteSwap)
                {
                    if (graphic as Image == null)
                    {
                        EditorGUILayout.HelpBox("You must have a Image target in order to use a sprite swap transition.", MessageType.Info);
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(this.m_SpriteStateProperty, true);
                    }
                }
                else if (transition == Selectable.Transition.Animation)
                {
                    EditorGUILayout.PropertyField(this.m_AnimTriggerProperty, true);

                    Animator animator = (target as UISelectField).animator;

                    if (animator == null || animator.runtimeAnimatorController == null)
                    {
                        Rect controlRect = EditorGUILayout.GetControlRect();
                        controlRect.xMin = (controlRect.xMin + EditorGUIUtility.labelWidth);

                        if (GUI.Button(controlRect, "Auto Generate Animation", EditorStyles.miniButton))
                        {
                            // Generate the animator controller
                            UnityEditor.Animations.AnimatorController animatorController = UIAnimatorControllerGenerator.GenerateAnimatorContoller(this.m_AnimTriggerProperty, target.name);

                            if (animatorController != null)
                            {
                                if (animator == null)
                                {
                                    animator = (target as UISelectField).gameObject.AddComponent <Animator>();
                                }
                                UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, animatorController);
                            }
                        }
                    }
                }

                EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
            }

            EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
        }