Exemple #1
0
        public void CopyFrom(RectStyle other)
        {
            color = other.color;

            enableGradient = other.enableGradient;
            gradientAngle  = other.gradientAngle;

            gradient?.Clear();

            if (other.gradient != null)
            {
                if (gradient == null)
                {
                    gradient = new Gradient();
                }

                foreach (var keyPoint in other.gradient)
                {
                    gradient.Add(keyPoint);
                }
            }

            borderMode  = other.borderMode;
            borderColor = other.borderColor;
            borderWidth = other.borderWidth;

            cornerRadius = other.cornerRadius;

            enableBoxShadow     = other.enableBoxShadow;
            boxShadowColor      = other.boxShadowColor;
            boxShadowBlurRadius = other.boxShadowBlurRadius;
            boxShadowOffset     = other.boxShadowOffset;
            boxShadowInner      = other.boxShadowInner;
        }
        public void CrossFadeStyle(RectStyle newStyle, float duration, EasingType easing = EasingType.Linear)
        {
            if (_oldStyle == null)
            {
                _oldStyle = ScriptableObject.CreateInstance <RectStyle>();
            }

            if (style != null)
            {
                _oldStyle.CopyFrom(style);
            }

            style = newStyle;

            if (duration <= 0f)
            {
                _crossFading = false;
                return;
            }

            _crossFading       = true;
            _crossFadeProgress = 0f;
            _crossFadeSpeed    = 1f / duration;
            _crossFadeEasing   = easing;
        }
        protected override void UpdateMaterial()
        {
            if (_styleForRendering == null)
            {
                _styleForRendering = ScriptableObject.CreateInstance <RectStyle>();
            }

            if (_crossFading && _oldStyle != null && style != null)
            {
                _styleForRendering.CopyFromLerped(_oldStyle, style, Ease(_crossFadeProgress, _crossFadeEasing));
            }
            else if (style != null)
            {
                _styleForRendering.CopyFrom(style);
            }

            var mat = materialForRendering;

            _styleForRendering.UpdateMaterial(mat, transform.rect.size);

            base.UpdateMaterial();
        }
Exemple #4
0
        public void CopyFromLerped(RectStyle a, RectStyle b, float t)
        {
            color = Color.Lerp(a.color, b.color, t);

            if ((a.gradient?.keyPointCount ?? 0) != (b.gradient?.keyPointCount ?? 0))
            {
                // TODO
            }
            else if (a.gradient != null && b.gradient != null && a.gradient.keyPointCount > 0)
            {
                gradientAngle = Mathf.LerpAngle(a.gradientAngle, b.gradientAngle, t);

                if (gradient == null)
                {
                    gradient = new Gradient();
                }
                else
                {
                    gradient.Clear();
                }

                for (var i = 0; i < a.gradient.keyPointCount; ++i)
                {
                    gradient.Add(new GradientKeyPoint
                    {
                        color    = Color.Lerp(a.gradient[i].color, b.gradient[i].color, t),
                        progress = Mathf.Lerp(a.gradient[i].progress, b.gradient[i].progress, t)
                    });
                }
            }

            enableGradient = a.enableGradient || b.enableGradient;
            borderMode     = a.borderMode | b.borderMode;
            borderColor    = a.HasBorder != b.HasBorder
                ? a.HasBorder
                    ? a.borderColor
                    : b.borderColor
                : Color.Lerp(a.borderColor, b.borderColor, t);
            borderWidth = Mathf.Lerp(a.HasBorder ? a.borderWidth : 0f, b.HasBorder ? b.borderWidth : 0f, t);

            cornerRadius = Mathf.Lerp(a.cornerRadius, b.cornerRadius, t);

            var boxShadowColorA = a.enableBoxShadow ? a.boxShadowColor : b.boxShadowColor;
            var boxShadowColorB = b.enableBoxShadow ? b.boxShadowColor : a.boxShadowColor;

            if (!a.enableBoxShadow)
            {
                boxShadowColorA.a = 0f;
            }
            if (!b.enableBoxShadow)
            {
                boxShadowColorB.a = 0f;
            }

            enableBoxShadow     = a.enableBoxShadow || b.enableBoxShadow;
            boxShadowColor      = Color.Lerp(boxShadowColorA, boxShadowColorB, t);
            boxShadowBlurRadius = Mathf.Lerp(
                a.enableBoxShadow ? a.boxShadowBlurRadius : b.boxShadowBlurRadius,
                b.enableBoxShadow ? b.boxShadowBlurRadius : a.boxShadowBlurRadius, t);
            boxShadowOffset = Vector2.Lerp(
                a.enableBoxShadow ? a.boxShadowOffset : b.boxShadowOffset,
                b.enableBoxShadow ? b.boxShadowOffset : a.boxShadowOffset, t);
            boxShadowInner = Mathf.Lerp(
                a.enableBoxShadow ? a.boxShadowInner : b.boxShadowInner,
                b.enableBoxShadow ? b.boxShadowInner : a.boxShadowInner, t);
        }