/// <summary> /// Sets the color of the AppBar and hides the shadow if the new alpha is less than 1. Does not animate in edit mode. /// </summary> /// <param name="color">The new color to set the AppBar's graphic. The shadow will be shown if the color is fully opaque.</param> /// <param name="animate">Animate the transition? Always false if in edit mode.</param> public void SetPanelColor(Color color, bool animate = true) { bool transparent = color.a < 1f; m_Shadow.SetShadow(!transparent, !transparent ? Tween.TweenType.SoftEaseOutQuint : Tween.TweenType.EaseOutQuint, !animate); if (m_PanelGraphic.color.a < 0.015f) { m_PanelGraphic.color = color.WithAlpha(m_PanelGraphic.color.a); } if (animate && Application.isPlaying) { // The action that is called each 'frame' of the tween Action <Color> tweenAction = c => { m_PanelGraphic.color = c; shadowGraphic.color = m_PanelGraphic.color.WithAlpha(shadowGraphic.color.a); }; TweenManager.TweenValue(tweenAction, m_PanelGraphic.color, color, m_AnimationDuration); } else { m_PanelGraphic.color = color; shadowGraphic.color = m_PanelGraphic.color.WithAlpha(shadowGraphic.color.a); } }
/// <summary> /// Tweens the color of a Graphic. /// </summary> /// <param name="graphic">The Graphic to modify.</param> /// <param name="color">The target color to tween the Graphic.</param> /// <param name="animate">Animate the transition? Always false if in edit mode.</param> /// <param name="onTweenEndAction">The action to call upon tween completion.</param> private void TweenGraphicColor(Graphic graphic, Color color, bool animate, Action onTweenEndAction = null) { if (animate && Application.isPlaying) { TweenManager.TweenValue(c => graphic.color = c, graphic.color, color, m_AnimationDuration, 0f, onTweenEndAction); } else { graphic.color = color; onTweenEndAction.InvokeIfNotNull(); } }