public static bool Rotate(AnimationItem item)
        {
            AnimationParam param = item.parameter;
            float          time  = 0;

            if (param.playType == AnimationPlayType.Loop)
            {
                float factor = item.time / param.durationTime;
                time = factor - Mathf.Floor(factor);
            }
            else if (param.playType == AnimationPlayType.PingPong)
            {
                float factor = item.time / param.durationTime;
                bool  isOdd  = Mathf.FloorToInt(factor) % 2 == 1;
                factor = factor - Mathf.Floor(factor);
                time   = isOdd ? 1f - factor:factor;
            }
            else if (param.playType == AnimationPlayType.Once)
            {
                time = Mathf.Clamp01(item.time / param.durationTime);
            }
            Vector3 angle       = param.targetAngle - param.startAngle;
            int     interval    = item.parameter.angleInterval;
            Vector3 changeAngle = new Vector3(
                angle.x * param.rotateCurveX.Evaluate(time),
                angle.y * param.rotateCurveY.Evaluate(time),
                angle.z * param.rotateCurveZ.Evaluate(time)
                );

            if (interval != 0)
            {
                changeAngle = new Vector3(
                    ((int)changeAngle.x / interval) * interval,
                    ((int)changeAngle.y / interval) * interval,
                    ((int)changeAngle.z / interval) * interval
                    );
            }

            item.obj.transform.rotation = Quaternion.Euler(
                item.parameter.startAngle + changeAngle
                );

            if (item.time >= item.parameter.durationTime && item.parameter.playType == AnimationPlayType.Once)
            {
                return(true);
            }
            if (item.parameter.playType == AnimationPlayType.Loop ||
                item.parameter.playType == AnimationPlayType.PingPong)
            {
                if (param.loopCount == -1 || param.loopCount == 0)
                {
                    return(false);
                }
                if (item.time >= item.parameter.durationTime * item.parameter.loopCount)
                {
                    return(true);
                }
            }
            return(false);
        }
        public static bool Color(AnimationItem item)
        {
            AnimationParam param = item.parameter;
            float          time  = 0;

            if (param.playType == AnimationPlayType.Loop)
            {
                float factor = item.time / param.durationTime;
                time = factor - Mathf.Floor(factor);
            }
            else if (param.playType == AnimationPlayType.PingPong)
            {
                float factor = item.time / param.durationTime;
                bool  isOdd  = Mathf.FloorToInt(factor) % 2 == 1;
                factor = factor - Mathf.Floor(factor);
                time   = isOdd ? 1f - factor:factor;
            }
            else if (param.playType == AnimationPlayType.Once)
            {
                time = Mathf.Clamp01(item.time / param.durationTime);
            }
            Color diffColor = param.targetColor - param.startColor;

            if (item.parameter.image != null)
            {
                item.parameter.image.color = new Color(
                    param.startColor.r + diffColor.r * param.colorCurveR.Evaluate(time), param.startColor.g + diffColor.g * param.colorCurveG.Evaluate(time),
                    param.startColor.b + diffColor.b * param.colorCurveB.Evaluate(time), param.startColor.a + diffColor.a * param.colorCurveA.Evaluate(time));
            }
            else if (item.parameter.spriteRender != null)
            {
                item.parameter.spriteRender.color = new Color(
                    param.startColor.r + diffColor.r * param.colorCurveR.Evaluate(time), param.startColor.g + diffColor.g * param.colorCurveG.Evaluate(time),
                    param.startColor.b + diffColor.b * param.colorCurveB.Evaluate(time), param.startColor.a + diffColor.a * param.colorCurveA.Evaluate(time));
            }
            else
            {
                return(true);
            }

            if (item.time >= item.parameter.durationTime && item.parameter.playType == AnimationPlayType.Once)
            {
                return(true);
            }
            if (item.parameter.playType == AnimationPlayType.Loop ||
                item.parameter.playType == AnimationPlayType.PingPong)
            {
                if (param.loopCount == -1 || param.loopCount == 0)
                {
                    return(false);
                }
                if (item.time >= item.parameter.durationTime * item.parameter.loopCount)
                {
                    return(true);
                }
            }
            return(false);
        }
        public static bool Resize(AnimationItem item)
        {
            AnimationParam param     = item.parameter;
            RectTransform  transform = item.obj.GetComponent <RectTransform>();

            if (transform == null)
            {
                return(true);
            }
            float time = 0;

            if (param.playType == AnimationPlayType.Loop)
            {
                float factor = item.time / param.durationTime;
                time = factor - Mathf.Floor(factor);
            }
            else if (param.playType == AnimationPlayType.PingPong)
            {
                float factor = item.time / param.durationTime;
                bool  isOdd  = Mathf.FloorToInt(factor) % 2 == 1;
                factor = factor - Mathf.Floor(factor);
                time   = isOdd ? 1f - factor:factor;
            }
            else if (param.playType == AnimationPlayType.Once)
            {
                time = Mathf.Clamp01(item.time / param.durationTime);
            }
            Vector2 size = param.targetSize - param.startSize;

            transform.sizeDelta = new Vector2(param.startSize.x + size.x * param.sizeCurveX.Evaluate(time),
                                              param.startSize.y + size.y * param.sizeCurveY.Evaluate(time));

            if (item.time >= item.parameter.durationTime && item.parameter.playType == AnimationPlayType.Once)
            {
                return(true);
            }
            if (item.parameter.playType == AnimationPlayType.Loop ||
                item.parameter.playType == AnimationPlayType.PingPong)
            {
                if (param.loopCount == -1 || param.loopCount == 0)
                {
                    return(false);
                }
                if (item.time >= item.parameter.durationTime * item.parameter.loopCount)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#4
0
        public static bool Scale(AnimationItem item)
        {
            AnimationParam param = item.parameter;
            float          time  = 0;

            if (param.playType == AnimationPlayType.Loop)
            {
                float factor = item.time / param.durationTime;
                time = factor - Mathf.Floor(factor);
            }
            else if (param.playType == AnimationPlayType.PingPong)
            {
                float factor = item.time / param.durationTime;
                bool  isOdd  = Mathf.FloorToInt(factor) % 2 == 1;
                factor = factor - Mathf.Floor(factor);
                time   = isOdd ? 1f - factor:factor;
            }
            else if (param.playType == AnimationPlayType.Once)
            {
                time = Mathf.Clamp01(item.time / param.durationTime);
            }
            Vector3 scale = param.targetScale - param.startScale;

            item.obj.transform.localScale = new Vector3(param.startScale.x + scale.x * param.scaleCurveX.Evaluate(time),
                                                        param.startScale.y + scale.y * param.scaleCurveY.Evaluate(time), param.startScale.z + scale.z * param.scaleCurveZ.Evaluate(time));

            if (item.time >= item.parameter.durationTime && item.parameter.playType == AnimationPlayType.Once)
            {
                return(true);
            }
            if (item.parameter.playType == AnimationPlayType.Loop ||
                item.parameter.playType == AnimationPlayType.PingPong)
            {
                if (param.loopCount == -1 || param.loopCount == 0)
                {
                    return(false);
                }
                if (item.time >= item.parameter.durationTime * item.parameter.loopCount)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#5
0
        public static bool Move(AnimationItem item)
        {
            AnimationParam param = item.parameter;
            float          time  = 0;

            if (param.playType == AnimationPlayType.Loop)
            {
                float factor = item.time / param.durationTime;
                time = factor - Mathf.Floor(factor);
            }
            else if (param.playType == AnimationPlayType.PingPong)
            {
                float factor = item.time / param.durationTime;
                bool  isOdd  = Mathf.FloorToInt(factor) % 2 == 1;
                factor = factor - Mathf.Floor(factor);
                time   = isOdd ? 1f - factor:factor;
            }
            else if (param.playType == AnimationPlayType.Once)
            {
                time = Mathf.Clamp01(item.time / param.durationTime);
            }
            Vector3 position        = param.targetPosition - param.startPosition;
            Vector3 currentPosition = new Vector3(
                param.targetPosition.x + position.x * param.moveCurveX.Evaluate(time),
                param.targetPosition.y + position.y * param.moveCurveY.Evaluate(time),
                param.targetPosition.z + position.z * param.moveCurveZ.Evaluate(time)
                );

            if (item.parameter.positionSpace == enPositionSpace.Self)
            {
                item.obj.transform.localPosition = currentPosition;
            }
            else if (item.parameter.positionSpace == enPositionSpace.World)
            {
                item.obj.transform.position = currentPosition;
            }
            else
            {
                var rectTransform = item.obj.GetComponent <RectTransform>();
                rectTransform.anchoredPosition = currentPosition;
            }
//            item.obj.transform.Translate(currentPosition, Space.Self);

            if (item.time >= item.parameter.durationTime && item.parameter.playType == AnimationPlayType.Once)
            {
                return(true);
            }
            if (item.parameter.playType == AnimationPlayType.Loop ||
                item.parameter.playType == AnimationPlayType.PingPong)
            {
                if (param.loopCount == -1 || param.loopCount == 0)
                {
                    return(false);
                }
                if (item.time >= item.parameter.durationTime * item.parameter.loopCount)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#6
0
        public static bool Fade(AnimationItem item)
        {
            AnimationParam param = item.parameter;
            float          time  = 0;

            if (param.playType == AnimationPlayType.Loop)
            {
                float factor = item.time / param.durationTime;
                time = factor - Mathf.Floor(factor);
            }
            else if (param.playType == AnimationPlayType.PingPong)
            {
                float factor = item.time / param.durationTime;
                bool  isOdd  = Mathf.FloorToInt(factor) % 2 == 1;
                factor = factor - Mathf.Floor(factor);
                time   = isOdd ? 1f - factor:factor;
            }
            else if (param.playType == AnimationPlayType.Once)
            {
                time = Mathf.Clamp01(item.time / param.durationTime);
            }
            float alpha = param.targetAlpha - param.startAlpha;

            if (item.parameter.spriteRender != null)
            {
                item.parameter.spriteRender.color = new Color(
                    item.parameter.spriteRender.color.r, item.parameter.spriteRender.color.g,
                    item.parameter.spriteRender.color.b, param.startAlpha + alpha * param.fadeCurve.Evaluate(time));
            }
            else if (item.parameter.fadeImage != null)
            {
                item.parameter.fadeImage.color = new Color(
                    item.parameter.fadeImage.color.r, item.parameter.fadeImage.color.g,
                    item.parameter.fadeImage.color.b, param.startAlpha + alpha * param.fadeCurve.Evaluate(time));
            }
            else if (item.parameter.canvasGroup != null)
            {
                item.parameter.canvasGroup.alpha = param.startAlpha + alpha * param.fadeCurve.Evaluate(time);
            }
            else
            {
                return(true);
            }


            if (item.time >= item.parameter.durationTime && item.parameter.playType == AnimationPlayType.Once)
            {
                return(true);
            }
            if (item.parameter.playType == AnimationPlayType.Loop ||
                item.parameter.playType == AnimationPlayType.PingPong)
            {
                if (param.loopCount == -1 || param.loopCount == 0)
                {
                    return(false);
                }
                if (item.time >= item.parameter.durationTime * item.parameter.loopCount)
                {
                    return(true);
                }
            }
            return(false);
        }