Exemplo n.º 1
0
    private Vector3 EvalateVector(ref JTweenFactor factor)
    {
        float offset = factor.curTime / factor.endTime;

        float x = factor.start.x + (factor.end.x - factor.start.x) * _animationCurve [(int)factor.easeType].Evaluate(offset);
        float y = factor.start.y + (factor.end.y - factor.start.y) * _animationCurve [(int)factor.easeType].Evaluate(offset);
        float z = factor.start.z + (factor.end.z - factor.start.z) * _animationCurve [(int)factor.easeType].Evaluate(offset);

        return(new Vector3(x, y, z));
    }
Exemplo n.º 2
0
    //this function use vector3's first element
    public static void ValueTo(GameObject target, float startVal, float endVal, float time, float delay, TweenAction updateAction, TweenAction completeAction = null, EaseType easeType = EaseType.Linear)
    {
        if (updateAction == null)
        {
            JDebugger.Log("JTween ValueTo updateAction must be registered");
            return;
        }

        JTweenFactor factor = new JTweenFactor(TweenType.Value, easeType, target, new Vector3(startVal, 0, 0), new Vector3(endVal, 0, 0), time, delay, updateAction, completeAction);

        _factorList.Add(factor);
    }
Exemplo n.º 3
0
    private void UpdateValue(ref JTweenFactor factor)
    {
        Vector3 value = EvalateVector(ref factor);

        if (factor.onUpdateAction != null)
        {
            factor.onUpdateAction(value.x);
        }
        if (factor.onCompleteAction != null && factor.end == value)
        {
            factor.onCompleteAction(value.x);
        }
    }
Exemplo n.º 4
0
    //Delay > 0 ? return true, or return false
    private bool UpdateDelay(ref JTweenFactor factor)
    {
        if (factor.delay > 0)
        {
            factor.delay -= Time.deltaTime;

            if (factor.delay < 0)
            {
                factor.delay = 0;
            }

            return(true);
        }

        return(false);
    }
Exemplo n.º 5
0
    private void Update()
    {
        if (_factorList.Count == 0)
        {
            return;
        }

        for (int i = 0; i < _factorList.Count; i++)
        {
            JTweenFactor factor = _factorList [i];

            if (UpdateDelay(ref factor))
            {
                continue;
            }

            //Update JTween.
            factor.CurTime += Time.deltaTime;
            switch (factor.tweenType)
            {
            case TweenType.Move:
                UpdatePosition(ref factor);
                break;

            case TweenType.Scale:
                UpdateScale(ref factor);
                break;

            case TweenType.Value:
                UpdateValue(ref factor);
                break;
            }

            _factorList [i] = factor;
        }


        //Remove factor
        _factorList.RemoveAll((JTweenFactor factor) => {
            return(factor.CurTime == factor.endTime);
        });
    }
Exemplo n.º 6
0
    public static void ScaleTo(GameObject target, Vector3 scale, float time, float delay = 0, EaseType easeType = EaseType.Linear)
    {
        JTweenFactor factor = new JTweenFactor(TweenType.Scale, easeType, target, target.transform.localScale, scale, time, delay);

        _factorList.Add(factor);
    }
Exemplo n.º 7
0
 private void UpdateScale(ref JTweenFactor factor)
 {
     factor.target.transform.localScale = EvalateVector(ref factor);
 }
Exemplo n.º 8
0
 private void UpdatePosition(ref JTweenFactor factor)
 {
     factor.target.transform.localPosition = EvalateVector(ref factor);
 }
Exemplo n.º 9
0
    public static void MoveTo(GameObject target, Vector3 pos, float time, float delay = 0, EaseType easeType = EaseType.Linear)
    {
        JTweenFactor factor = new JTweenFactor(TweenType.Move, easeType, target, target.transform.localPosition, pos, time, delay);

        _factorList.Add(factor);
    }