/// <summary>
        /// Sets the color of the target graphic. This is the recommended way to change the graphic's color (if any sort of highlighting is used) to reliably set the color without messing up the highlighting values.
        /// </summary>
        /// <param name="color">The color to set.</param>
        /// <param name="animate">Should the graphic fade to the new color? Otherwise the new color is applied instantly.</param>
        public void SetGraphicColor(Color color, bool animate = true)
        {
            if (animate)
            {
                m_NormalColor = color;

                if (m_AutoHighlightColor)
                {
                    m_HighlightColor = MaterialColor.HighlightColor(m_NormalColor, rippleData.Color, m_AutoHighlightBlendAmount);
                }

                m_CurrentColor  = highlightGraphic.color;
                m_AnimStartTime = Time.realtimeSinceStartup;

                if (m_AnimState == 0)
                {
                    m_AnimState = 2;
                }
            }
            else
            {
                m_NormalColor = color;

                if (m_AutoHighlightColor)
                {
                    m_HighlightColor = MaterialColor.HighlightColor(m_NormalColor, rippleData.Color, m_AutoHighlightBlendAmount);
                }

                highlightGraphic.color = m_AnimState == 1 ? m_HighlightColor : m_NormalColor;
                m_AnimState            = 0;
            }
        }
Example #2
0
        public void RefreshSettings()
        {
            m_AnimDuration = 4f / rippleData.Speed;

            if (highlightGraphic)
            {
                m_ImageIsTransparent = (highlightGraphic.color.a == 0f && toggleMask);

                if (m_ToggleMask)
                {
                    if (highlightGraphic.GetComponent <Mask>())
                    {
                        Destroy(highlightGraphic.GetComponent <Mask>());
                    }
                }
            }

            if (!highlightGraphic)
            {
                return;
            }

            m_NormalColor = highlightGraphic.color;

            if (autoHighlightColor)
            {
                if (highlightWhen != HighlightActive.Never)
                {
                    highlightColor = MaterialColor.GetHighlightColor(m_NormalColor, rippleData.Color, m_AutoHighlightBlendAmount);

                    if (m_ImageIsTransparent)
                    {
                        m_NormalColor          = new Color(highlightColor.r, highlightColor.g, highlightColor.b, 0f);
                        highlightGraphic.color = m_NormalColor;
                    }
                }
            }
        }
        /// <summary>
        /// Calculates the (absolute) highlight color based on the graphic color and ripple color.
        /// </summary>
        public void RefreshAutoHighlightColor()
        {
            if (!highlightGraphic)
            {
                return;
            }

            m_NormalColor = highlightGraphic.color;

            if (autoHighlightColor)
            {
                if (highlightWhen != HighlightActive.Never)
                {
                    highlightColor = MaterialColor.HighlightColor(m_NormalColor, rippleData.Color, m_AutoHighlightBlendAmount);

                    if (m_ImageIsTransparent)
                    {
                        m_NormalColor          = new Color(highlightColor.r, highlightColor.g, highlightColor.b, 0f);
                        highlightGraphic.color = m_NormalColor;
                    }
                }
            }
        }