Example #1
0
        void Update()
        {
            animDeltaTime = Time.realtimeSinceStartup - animStartTime;

            if (state == 1)
            {
                if (animDeltaTime <= animationDuration)
                {
                    checkRectTransform.localScale = Anim.Overshoot(new Vector3(currentCheckSize, currentCheckSize, 1f), new Vector3(1f, 1f, 1f), animDeltaTime, animationDuration);
                    frameImage.color       = Anim.Quint.SoftOut(currentColor, onColor, animDeltaTime, animationDuration);
                    frameCanvasGroup.alpha = Anim.Cube.SoftOut(currentFrameAlpha, 0f, animDeltaTime, animationDuration);

                    if (changeTextColor)
                    {
                        text.color = Anim.Quint.SoftOut(currentTextColor, onColor, animDeltaTime, animationDuration);
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = frameImage.color;
                    }
                }
                else
                {
                    checkRectTransform.localScale = new Vector3(1f, 1f, 1f);
                    frameImage.color       = onColor;
                    frameCanvasGroup.alpha = 0f;

                    if (changeTextColor)
                    {
                        text.color = onColor;
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = onColor;
                    }

                    frameImage.enabled = false;
                    state = 0;
                }
            }
            else if (state == 2)
            {
                if (animDeltaTime <= animationDuration * 0.75f)
                {
                    checkRectTransform.localScale = Anim.Sept.InOut(new Vector3(currentCheckSize, currentCheckSize, 1f), new Vector3(0f, 0f, 1f), animDeltaTime, animationDuration * 0.75f);
                    frameImage.color       = Anim.Sept.InOut(currentColor, offColor, animDeltaTime, animationDuration * 0.75f);
                    frameCanvasGroup.alpha = Anim.Sept.InOut(currentFrameAlpha, 1f, animDeltaTime, animationDuration * 0.75f);

                    if (changeTextColor)
                    {
                        text.color = Anim.Quint.SoftOut(currentTextColor, textNormalColor, animDeltaTime, animationDuration * 0.75f);
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = frameImage.color;
                    }
                }
                else
                {
                    checkRectTransform.localScale = new Vector3(0f, 0f, 1f);
                    frameImage.color       = offColor;
                    frameCanvasGroup.alpha = 1f;

                    if (changeTextColor)
                    {
                        text.color = textNormalColor;
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = offColor;
                    }

                    checkImage.enabled = false;
                    state = 0;
                }
            }

            if (lastToggleInteractableState != toggle.interactable)
            {
                lastToggleInteractableState = toggle.interactable;

                if (lastToggleInteractableState)
                {
                    EnableCheckbox();
                }
                else
                {
                    DisableCheckbox();
                }
            }

            if (!Application.isPlaying)
            {
                if (lastToggleState != toggle.isOn)
                {
                    lastToggleState = toggle.isOn;

                    if (lastToggleState)
                    {
                        TurnOnSilent();
                    }
                    else
                    {
                        TurnOffSilent();
                    }
                }

                if (changeRippleColor)
                {
                    rippleConfig.rippleColor = frameImage.color;
                }
            }
        }
Example #2
0
        void Update()
        {
            animDeltaTime = Time.realtimeSinceStartup - animStartTime;

            if (state == 1)             // Turning on
            {
                if (animDeltaTime <= animationDuration)
                {
                    dotRectTransform.localScale = Anim.Overshoot(new Vector3(currentDotSize, currentDotSize, 1f), new Vector3(1f, 1f, 1f), animDeltaTime, animationDuration);
                    ringImage.color             = Anim.Quint.SoftOut(currentColor, onColor, animDeltaTime, animationDuration);

                    if (changeTextColor)
                    {
                        text.color = Anim.Quint.SoftOut(currentTextColor, onColor, animDeltaTime, animationDuration);
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = ringImage.color;
                    }
                }
                else
                {
                    dotRectTransform.localScale = new Vector3(1f, 1f, 1f);
                    ringImage.color             = onColor;

                    if (changeTextColor)
                    {
                        text.color = onColor;
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = onColor;
                    }

                    state = 0;
                }
            }
            else if (state == 2)                // Turning off
            {
                if (animDeltaTime <= animationDuration)
                {
                    dotRectTransform.localScale = Anim.Sept.InOut(new Vector3(currentDotSize, currentDotSize, 1f), new Vector3(0f, 0f, 1f), animDeltaTime, animationDuration * 0.75f);
                    ringImage.color             = Anim.Sept.InOut(currentColor, offColor, animDeltaTime, animationDuration * 0.75f);

                    if (changeTextColor)
                    {
                        text.color = Anim.Quint.SoftOut(currentTextColor, textNormalColor, animDeltaTime, animationDuration * 0.75f);
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = ringImage.color;
                    }
                }
                else
                {
                    dotRectTransform.localScale = new Vector3(0f, 0f, 1f);
                    ringImage.color             = offColor;

                    if (changeTextColor)
                    {
                        text.color = textNormalColor;
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = offColor;
                    }

                    dotImage.enabled = false;
                    state            = 0;
                }
            }


            if (lastToggleInteractableState != toggle.interactable)
            {
                lastToggleInteractableState = toggle.interactable;

                if (lastToggleInteractableState)
                {
                    EnableRadioButton();
                }
                else
                {
                    DisableRadioButton();
                }
            }

            if (!Application.isPlaying)
            {
                if (lastToggleState != toggle.isOn)
                {
                    lastToggleState = toggle.isOn;

                    if (lastToggleState)
                    {
                        TurnOnSilent();
                    }
                    else
                    {
                        TurnOffSilent();
                    }
                }

                if (changeRippleColor)
                {
                    rippleConfig.rippleColor = ringImage.color;
                }
            }
        }
Example #3
0
        public void Refresh()
        {
            if (autoSize)
            {
                Rect tempRect = gameObject.GetComponent <RectTransform>().rect;

                if (tempRect.width > tempRect.height)
                {
                    rippleSize = Mathf.RoundToInt(tempRect.width);
                }
                else
                {
                    rippleSize = Mathf.RoundToInt(tempRect.height);
                }

                rippleSize = Mathf.RoundToInt(rippleSize * sizePercentage / 100f);
            }

            normalColor = thisImage.color;

            if (highlightWhen != HighlightActive.Never)
            {
                highlightColor = rippleColor;

                HSBColor highlightColorHSB = HSBColor.FromColor(highlightColor);
                HSBColor normalColorHSB    = HSBColor.FromColor(normalColor);

                if (highlightColorHSB.s <= 0.05f)
                {
                    if (highlightColorHSB.b > 0.5f)
                    {
                        if (normalColorHSB.b > 0.9f)
                        {
                            highlightColorHSB.h = normalColorHSB.h;
                            highlightColorHSB.s = normalColorHSB.s - 0.1f;
                            highlightColorHSB.b = normalColorHSB.b + 0.2f;
                        }
                        else
                        {
                            highlightColorHSB.h = normalColorHSB.h;
                            highlightColorHSB.s = normalColorHSB.s;
                            highlightColorHSB.b = normalColorHSB.b + 0.2f;
                        }
                    }
                    else
                    {
                        highlightColorHSB.h = normalColorHSB.h;
                        highlightColorHSB.s = normalColorHSB.s;
                        highlightColorHSB.b = normalColorHSB.b - 0.15f;
                    }

                    highlightColor   = HSBColor.ToColor(highlightColorHSB);
                    highlightColor.a = normalColor.a;
                }
                else
                {
                    highlightColor.r = Anim.Linear(normalColor.r, highlightColor.r, 0.2f, 1f);
                    highlightColor.g = Anim.Linear(normalColor.g, highlightColor.g, 0.2f, 1f);
                    highlightColor.b = Anim.Linear(normalColor.b, highlightColor.b, 0.2f, 1f);
                    highlightColor.a = Anim.Linear(normalColor.a, highlightColor.a, 0.2f, 1f);
                }
            }

            animationDuration = 4 / rippleSpeed;
        }
Example #4
0
        void Update()
        {
            animDeltaTime = Time.realtimeSinceStartup - animStartTime;

            if (state == 1)             //  Animating on
            {
                if (animDeltaTime <= animationDuration)
                {
                    //  Updates values
                    checkRectTransform.localScale = Anim.Overshoot(new Vector3(currentCheckSize, currentCheckSize, 1f), new Vector3(1f, 1f, 1f), animDeltaTime, animationDuration);
                    frameImage.color       = Anim.Quint.SoftOut(currentColor, onColor, animDeltaTime, animationDuration);
                    frameCanvasGroup.alpha = Anim.Cube.SoftOut(currentFrameAlpha, 0f, animDeltaTime, animationDuration);

                    if (changeTextColor)
                    {
                        text.color = Anim.Quint.SoftOut(currentTextColor, onColor, animDeltaTime, animationDuration);
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = frameImage.color;
                    }
                }
                else
                {
                    //  Animation has finished

                    checkRectTransform.localScale = new Vector3(1f, 1f, 1f);
                    frameImage.color       = onColor;
                    frameCanvasGroup.alpha = 0f;

                    if (changeTextColor)
                    {
                        text.color = onColor;
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = onColor;
                    }

                    frameImage.enabled = false;
                    state = 0;
                }
            }
            else if (state == 2)                                //  Animating off
            {
                if (animDeltaTime <= animationDuration * 0.75f) // * 0.75f to make it shorter than the on animation (looks better)
                {
                    //  Update values
                    checkRectTransform.localScale = Anim.Sept.InOut(new Vector3(currentCheckSize, currentCheckSize, 1f), new Vector3(0f, 0f, 1f), animDeltaTime, animationDuration * 0.75f);
                    frameImage.color       = Anim.Sept.InOut(currentColor, offColor, animDeltaTime, animationDuration * 0.75f);
                    frameCanvasGroup.alpha = Anim.Sept.InOut(currentFrameAlpha, 1f, animDeltaTime, animationDuration * 0.75f);

                    if (changeTextColor)
                    {
                        text.color = Anim.Quint.SoftOut(currentTextColor, textNormalColor, animDeltaTime, animationDuration * 0.75f);
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = frameImage.color;
                    }
                }
                else
                {
                    //  Animation completed
                    checkRectTransform.localScale = new Vector3(0f, 0f, 1f);
                    frameImage.color       = offColor;
                    frameCanvasGroup.alpha = 1f;

                    if (changeTextColor)
                    {
                        text.color = textNormalColor;
                    }

                    if (changeRippleColor)
                    {
                        rippleConfig.rippleColor = offColor;
                    }

                    checkImage.enabled = false;
                    state = 0;
                }
            }

            //  If the 'interactable' toggle on the Toggle has changed, call EnableCheckbox() or DisableCheckbox() accordingly
            if (lastToggleInteractableState != toggle.interactable)
            {
                lastToggleInteractableState = toggle.interactable;

                if (lastToggleInteractableState)
                {
                    EnableCheckbox();
                }
                else
                {
                    DisableCheckbox();
                }
            }

            //  If the Toggle is toggled, update values and appearance accordingly
            if (!Application.isPlaying)
            {
                if (lastToggleState != toggle.isOn)
                {
                    lastToggleState = toggle.isOn;

                    if (lastToggleState)
                    {
                        TurnOnSilent();
                    }
                    else
                    {
                        TurnOffSilent();
                    }
                }

                if (changeRippleColor)
                {
                    rippleConfig.rippleColor = frameImage.color;
                }
            }
        }