Ejemplo n.º 1
0
    public static Coroutine TweenCanvasGroupAlpha(CanvasGroup canvasGroup, EzEaseType easeType, float to, float time, System.Action completeAction = null)
    {
        float from = canvasGroup.alpha;

        return(TweenAct(canvasGroup, easeType, from, to, time, (v) => {
            canvasGroup.alpha = v;
        }, completeAction));
    }
Ejemplo n.º 2
0
    // material
    public static Coroutine TweenMaterial(Material material, string floatParamName, EzEaseType easeType, float to, float time, System.Action completeAction = null)
    {
        float from = material.GetFloat(floatParamName);

        return(TweenAct(material, easeType, from, to, time, (v) => {
            material.SetFloat(floatParamName, v);
        }, completeAction));
    }
Ejemplo n.º 3
0
    // ui
    public static Coroutine TweenUiColor(MaskableGraphic uiElement, EzEaseType easeType, Color to, float time, System.Action completeAction = null)
    {
        Color from = uiElement.color;

        return(TweenAct(uiElement, easeType, from, to, time, (v) => {
            uiElement.color = v;
        }, completeAction));
    }
Ejemplo n.º 4
0
    // renderer
    public static Coroutine TweenRendererColor(Renderer renderer, EzEaseType easeType, Color to, float time, System.Action completeAction = null)
    {
        Color from = renderer.material.color;

        return(TweenAct(renderer, easeType, from, to, time, (v) => {
            renderer.material.color = v;
        }, completeAction));
    }
Ejemplo n.º 5
0
    public static Coroutine TweenScale(Transform transform, EzEaseType easeType, Vector3 to, float time, System.Action completeAction = null)
    {
        Vector3 from = transform.localScale;

        return(TweenAct(transform, easeType, from, to, time, (v) => {
            transform.localScale = v;
        }, completeAction));
    }
Ejemplo n.º 6
0
    public static Coroutine TweenLocalRotation(Transform transform, EzEaseType easeType, Quaternion to, float time, System.Action completeAction = null)
    {
        Quaternion from = transform.localRotation;

        return(TweenAct(transform, easeType, from, to, time, (v) => {
            transform.localRotation = v;
        }, completeAction));
    }
Ejemplo n.º 7
0
    public static Coroutine TweenAct(Object keyObject, EzEaseType easeType, Quaternion from, Quaternion to, float time, System.Action <Quaternion> updateAction, System.Action completeAction = null)
    {
        Coroutine co = TweenBaseAct(keyObject, 0, 1, time, (v) => {
            Quaternion p = Quaternion.LerpUnclamped(from, to, v);
            updateAction(p);
        }, completeAction, easeType, null);

        return(co);
    }
Ejemplo n.º 8
0
    public static Coroutine TweenAct(Object keyObject, EzEaseType easeType, Color32 from, Color32 to, float time, System.Action <Color32> updateAction, System.Action completeAction = null)
    {
        Coroutine co = TweenBaseAct(keyObject, 0, 1, time, (v) => {
            Color32 p = Color32.LerpUnclamped(from, to, v);
            updateAction(p);
        }, completeAction, easeType, null);

        return(co);
    }
Ejemplo n.º 9
0
    public static Coroutine TweenAct(Object keyObject, EzEaseType easeType, Vector3 from, Vector3 to, float time, System.Action <Vector3> updateAction, System.Action completeAction = null)
    {
        //System.Action<float> act = (v) => {
        //    Vector3 p = Vector3.LerpUnclamped(from, to, v);
        //    updateAction(p);
        //};
        //if (from.Equals(to)) {
        //    completeAction?.Invoke();
        //    return null;
        //}
        Coroutine co = TweenBaseAct(keyObject, 0, 1, time, (v) => {
            Vector3 p = Vector3.LerpUnclamped(from, to, v);
            updateAction(p);
        }, completeAction, easeType, null);

        return(co);
    }
Ejemplo n.º 10
0
 // TODO: generic を使ってもっとシンプルにできないか?
 // extend
 // EaseType
 public static Coroutine TweenAct(Object keyObject, EzEaseType easeType, float from, float to, float time, System.Action <float> updateAction, System.Action completeAction = null)
 {
     return(TweenBaseAct(keyObject, from, to, time, updateAction, completeAction, easeType));
 }
Ejemplo n.º 11
0
    IEnumerator Tween(float from, float to, float time, System.Action <float> updateAction, System.Action completeAction = null, EzEaseType easeType = EzEaseType.Linear, AnimationCurve curve = null)
    {
        float t = 0;
        float d = to - from;

        if (d != 0)
        {
            System.Func <float, float> easeAct = GetEaseAction(easeType);
            while (t < time)
            {
                t += Time.deltaTime;
                float per = t / time;
                per = Mathf.Clamp01(per);
                if (curve != null)
                {
                    per = curve.Evaluate(per);
                }
                else
                {
                    per = easeAct(per);
                }

                updateAction(from + d * per);
                yield return(null);
            }
            updateAction(to);
        }
        else
        {
            yield return(null);
        }
        completeAction?.Invoke();
    }
Ejemplo n.º 12
0
 Coroutine _StartTween(float from, float to, float time, System.Action <float> updateAction, System.Action completeAction = null, EzEaseType easeType = EzEaseType.Linear, AnimationCurve curve = null)
 {
     return(StartCoroutine(Tween(from, to, time, updateAction, completeAction, easeType, curve)));
 }
Ejemplo n.º 13
0
 public System.Func <float, float> GetEaseAction(EzEaseType type)
 {
     if (type == EzEaseType.SineIn)
     {
         return((v) => Easing.SineIn(v));
     }
     else if (type == EzEaseType.SineOut)
     {
         return((v) => Easing.SineOut(v));
     }
     else if (type == EzEaseType.SineInOut)
     {
         return((v) => Easing.SineInOut(v));
     }
     else if (type == EzEaseType.QuadIn)
     {
         return((v) => Easing.QuadIn(v));
     }
     else if (type == EzEaseType.QuadOut)
     {
         return((v) => Easing.QuadOut(v));
     }
     else if (type == EzEaseType.QuadInOut)
     {
         return((v) => Easing.QuadInOut(v));
     }
     else if (type == EzEaseType.CubicIn)
     {
         return((v) => Easing.CubicIn(v));
     }
     else if (type == EzEaseType.CubicOut)
     {
         return((v) => Easing.CubicOut(v));
     }
     else if (type == EzEaseType.CubicInOut)
     {
         return((v) => Easing.CubicInOut(v));
     }
     else if (type == EzEaseType.QuartIn)
     {
         return((v) => Easing.QuartIn(v));
     }
     else if (type == EzEaseType.QuartOut)
     {
         return((v) => Easing.QuartOut(v));
     }
     else if (type == EzEaseType.QuartInOut)
     {
         return((v) => Easing.QuartInOut(v));
     }
     else if (type == EzEaseType.ExpIn)
     {
         return((v) => Easing.ExpIn(v));
     }
     else if (type == EzEaseType.ExpOut)
     {
         return((v) => Easing.ExpOut(v));
     }
     else if (type == EzEaseType.ExpInOut)
     {
         return((v) => Easing.ExpInOut(v));
     }
     else if (type == EzEaseType.CircIn)
     {
         return((v) => Easing.CircIn(v));
     }
     else if (type == EzEaseType.CircOut)
     {
         return((v) => Easing.CircOut(v));
     }
     else if (type == EzEaseType.CircInOut)
     {
         return((v) => Easing.CircInOut(v));
     }
     else if (type == EzEaseType.ElasticIn)
     {
         return((v) => Easing.ElasticIn(v));
     }
     else if (type == EzEaseType.ElasticOut)
     {
         return((v) => Easing.ElasticOut(v));
     }
     else if (type == EzEaseType.ElasticInOut)
     {
         return((v) => Easing.ElasticInOut(v));
     }
     else if (type == EzEaseType.BackIn)
     {
         return((v) => Easing.BackIn(v));
     }
     else if (type == EzEaseType.BackOut)
     {
         return((v) => Easing.BackOut(v));
     }
     else if (type == EzEaseType.BackInOut)
     {
         return((v) => Easing.BackInOut(v));
     }
     else if (type == EzEaseType.BounceIn)
     {
         return((v) => Easing.BounceIn(v));
     }
     else if (type == EzEaseType.BounceOut)
     {
         return((v) => Easing.BounceOut(v));
     }
     else if (type == EzEaseType.BounceInOut)
     {
         return((v) => Easing.BounceInOut(v));
     }
     else
     {
         return((v) => Easing.Linear(v));
     }
 }
Ejemplo n.º 14
0
    //
    #endregion

    static Coroutine TweenBaseAct(Object keyObject, float from, float to, float time, System.Action <float> updateAction, System.Action completeAction = null, EzEaseType easeType = EzEaseType.Linear, AnimationCurve curve = null)
    {
        Cancel(keyObject);
        Coroutine co = INSTANCE._StartTween(from, to, time, updateAction, () => {
            // complete
            INSTANCE.tweenDic.Remove(keyObject);
            completeAction?.Invoke();
        }, easeType, curve);

        INSTANCE.tweenDic.Add(keyObject, co);

        return(co);
    }