Пример #1
0
    public void RegisterTweenValueType()
    {
        var runner = new TweenRunner();

        // Register a test type
        TweenDataRegistry.RegisterTweenDataType <TestType>(GetValueTestType);

        // Make sure a tween of that type can be started and updated
        var startValue  = (TestType)1f;
        var tweenParams = new TweenParams
        {
            TweenSecs = 10f,
            Ease      = EaseType.Linear,
            Loop      = LoopType.PingPong
        };
        var tweenRef = runner.StartTween <TestType>(
            startValue,
            10f,
            tweenParams,
            null
            );

        // Make sure the starting value is correct
        var value = runner.GetTweenValue <TestType>(tweenRef);

        Assert.IsTrue(value == startValue, $"TestType pre update, got value {value} should be {startValue}");

        runner.Update(1f / 60f);

        // Make sure the value has changed after updating
        value = runner.GetTweenValue <TestType>(tweenRef);
        Assert.IsTrue(value != startValue, $"TestType post update, got value {value} should be different from start value {startValue}");

        runner.StopTween(tweenRef);
    }
Пример #2
0
        public override void CrossFadeColor(Color targetColor, float duration, bool ignoreTimeScale, bool useAlpha, bool useRGB)
        {
            //if (EditorApplication.isPlayingOrWillChangePlaymode) return;

            if (_sc == null || (!useRGB && !useAlpha))
            {
                return;
            }

            Color currentColor = _sc.TintColor;

            if (currentColor.Equals(targetColor))
            {
                m_ColorTweenRunner.StopTween();
                return;
            }

            ColorTween.ColorTweenMode mode = (useRGB && useAlpha ?
                                              ColorTween.ColorTweenMode.All :
                                              (useRGB ? ColorTween.ColorTweenMode.RGB : ColorTween.ColorTweenMode.Alpha));

            var colorTween = new ColorTween {
                duration = duration, startColor = _sc.TintColor, targetColor = targetColor
            };

            colorTween.AddOnChangedCallback((c) => _sc.TintColor = c);
            colorTween.ignoreTimeScale = ignoreTimeScale;
            colorTween.tweenMode       = mode;
            m_ColorTweenRunner.StartTween(colorTween);
        }
Пример #3
0
    public void StartAndStopTween()
    {
        const int numTweens = 50;

        var runner    = new TweenRunner();
        var tweenRefs = new List <TweenRef>(numTweens);

        // Start a bunch of tweens running
        var tweenParams = new TweenParams
        {
            TweenSecs = 10f,
            Ease      = EaseType.Linear,
            Loop      = LoopType.PingPong
        };

        for (var i = 0; i < numTweens; ++i)
        {
            var tweenRef = runner.StartTween(
                0f,
                10f,
                tweenParams,
                null
                );
            tweenRefs.Add(tweenRef);
        }

        // Make sure the correct amount started
        var numRunningTweens = runner.GetNumberOfRunningTweens();

        Assert.IsTrue(numRunningTweens == numTweens, $"Only {numRunningTweens} tweens running. We should have started {numTweens}");

        // Stop all tweens
        for (var i = 0; i < tweenRefs.Count; ++i)
        {
            runner.StopTween(tweenRefs[i]);
        }

        // Make sure they all stopped
        numRunningTweens = runner.GetNumberOfRunningTweens();
        Assert.IsTrue(numRunningTweens == 0, $"There are still {numRunningTweens} tweens running. All should have been stopped");
    }