/// <summary>
 /// OTTween constructor
 /// </summary>
 /// <param name="owner">Object on which to tween properties</param>
 /// <param name="duration">Tween duration</param>
 /// <param name="easing">Tween 'default' easing function</param>
 public OTTween(object owner, float duration, OTEase easing)
 {
     this.owner    = owner;
     this.duration = duration;
     this.easing   = easing;
     CheckController();
 }
    /// <summary>
    /// Tween a 'public' property of the tween's owner object
    /// </summary>
    /// <param name="var">Property name</param>
    /// <param name="fromValue">From value</param>
    /// <param name="toValue">To value</param>
    /// <param name="easing">Easing function</param>
    /// <param name="pongEasing">Easing when 'ponging'</param>
    /// <returns>Tween object</returns>
    public OTTween Tween(string var, object fromValue, object toValue, OTEase easing, OTEase pongEasing)
    {
        vars.Add(var);
        SetVar(var);
        if (fromValue != null)
        {
            object fv = fromValues[fromValues.Count - 1];
            if (fv != null)
            {
#if UNITY_FLASH
                if (fv is float && fromValue is int)
                {
                    ActionScript.Statement("$fromValue = Number($fromValue);");
                }
#else
                if (fv is float && fromValue is int)
                {
                    fromValue = System.Convert.ToSingle(fromValue);
                }
                else
                if (fv is double && fromValue is int)
                {
                    fromValue = System.Convert.ToDouble(fromValue);
                }
#endif
            }
            fromValues[fromValues.Count - 1] = fromValue;
        }
        toValues.Add(toValue);
        easings.Add(easing);
        pongEasings.Add(pongEasing);
        return(this);
    }
예제 #3
0
 /// <summary>
 /// OTTween constructor
 /// </summary>
 /// <param name="owner">Object on which to tween properties</param>
 /// <param name="duration">Tween duration</param>
 /// <param name="easing">Tween 'default' easing function</param>
 public OTTween(object owner, float duration, OTEase easing)
 {
     this.owner = owner;
     this.duration = duration;
     this.easing = easing;
     CheckController();
 }
예제 #4
0
    /// <summary>
    /// Tween a 'public' property, adding a value, of the tween's target object.
    /// </summary>
    /// <param name="var">Property name</param>
    /// <param name="addValue">Value to add</param>
    /// <param name="easing">Easing function</param>
    /// <param name="pongEasing">Easing when 'ponging'</param>
    /// <returns>Tween object</returns>
    public OTTween TweenAdd(string var, object addValue, OTEase easing, OTEase pongEasing)
    {
        vars.Add(var);
        SetVar(var);
        easings.Add(easing);
        pongEasings.Add(pongEasing);
        object fromValue = fromValues[fromValues.Count - 1];

        if (fromValue is int)
        {
            try
            {
                addValue = System.Convert.ToInt32(addValue);
            }
            catch (System.Exception)
            {
                addValue = 0;
            }
        }
        else
        if (fromValue is float)
        {
            try
            {
                addValue = System.Convert.ToSingle(addValue);
            }
            catch (System.Exception)
            {
                addValue = 0.0f;
            }
        }
        else
        if (fromValue is double)
        {
            try
            {
                addValue = System.Convert.ToDouble(addValue);
            }
            catch (System.Exception)
            {
                addValue = 0.0;
            }
        }

        switch (fromValue.GetType().Name.ToLower())
        {
        case "single": toValues.Add((float)fromValue + (float)addValue); break;

        case "double": toValues.Add((double)fromValue + (double)addValue); break;

        case "int": toValues.Add((int)fromValue + (int)addValue); break;

        case "vector2": toValues.Add((Vector2)fromValue + (Vector2)addValue); break;

        case "vector3": toValues.Add((Vector3)fromValue + (Vector3)addValue); break;

        default: toValues.Add(null); break;
        }
        return(this);
    }
예제 #5
0
 /// <summary>
 /// OTTween constructor (easing Linear)
 /// </summary>
 /// <param name="owner">Object on which to tween properties</param>
 /// <param name="duration">Tween duration</param>
 public OTTween(object owner, float duration)
 {
     this.owner = owner;
     this.duration = duration;
     this.easing = OTEasing.Linear;
     CheckController();
 }
 /// <summary>
 /// OTTween constructor (easing Linear)
 /// </summary>
 /// <param name="owner">Object on which to tween properties</param>
 /// <param name="duration">Tween duration</param>
 public OTTween(object owner, float duration)
 {
     this.owner    = owner;
     this.duration = duration;
     this.easing   = OTEasing.Linear;
     CheckController();
 }
예제 #7
0
 /// <summary>
 /// OTTween constructor (easing Linear)
 /// </summary>
 /// <param name="target">Object on which to tween properties</param>
 /// <param name="duration">Tween duration</param>
 public OTTween(object target, float duration)
 {
     this._target = target;
     this.duration = duration;
     this.easing = OTEasing.Linear;
     CheckController();
 }
예제 #8
0
파일: OTTween.cs 프로젝트: jedirandy/Eileen
 /// <summary>
 /// OTTween constructor
 /// </summary>
 /// <param name="target">Object on which to tween properties</param>
 /// <param name="duration">Tween duration</param>
 /// <param name="easing">Tween 'default' easing function</param>
 public OTTween(object target, float duration, OTEase easing)
 {
     this._target  = target;
     this.duration = duration;
     this.easing   = easing;
     CheckController();
 }
예제 #9
0
파일: OTTween.cs 프로젝트: jedirandy/Eileen
 /// <summary>
 /// Tween a 'public' property of the tween's target object
 /// </summary>
 /// <param name="var">Property name</param>
 /// <param name="fromValue">From value</param>
 /// <param name="toValue">To value</param>
 /// <param name="easing">Easing function</param>
 /// <param name="pongEasing">Easing when 'ponging'</param>
 /// <returns>Tween object</returns>
 public OTTween Tween(string var, object fromValue, object toValue, OTEase easing, OTEase pongEasing)
 {
     vars.Add(var);
     SetVar(var);
     if (fromValue != null)
     {
         object fv = fromValues[fromValues.Count - 1];
         if (fv != null)
         {
             if (fv is float && fromValue is int)
             {
                 fromValue = System.Convert.ToSingle(fromValue);
             }
             else
             if (fv is double && fromValue is int)
             {
                 fromValue = System.Convert.ToDouble(fromValue);
             }
         }
         fromValues[fromValues.Count - 1] = fromValue;
     }
     toValues.Add(toValue);
     easings.Add(easing);
     pongEasings.Add(pongEasing);
     return(this);
 }
예제 #10
0
파일: OTTween.cs 프로젝트: jedirandy/Eileen
 /// <summary>
 /// OTTween constructor (easing Linear)
 /// </summary>
 /// <param name="target">Object on which to tween properties</param>
 /// <param name="duration">Tween duration</param>
 public OTTween(object target, float duration)
 {
     this._target  = target;
     this.duration = duration;
     this.easing   = OTEasing.Linear;
     CheckController();
 }
예제 #11
0
 /// <summary>
 /// OTTween constructor
 /// </summary>
 /// <param name="target">Object on which to tween properties</param>
 /// <param name="duration">Tween duration</param>
 /// <param name="easing">Tween 'default' easing function</param>
 public OTTween(object target, float duration, OTEase easing)
 {
     this._target = target;
     this.duration = duration;
     this.easing = easing;
     CheckController();
 }
예제 #12
0
 /// <summary>
 /// Path controller constructor
 /// </summary>
 /// <param name="owner">Owner object that must be moved</param>
 /// <param name="name">Name of this controller</param>
 /// <param name="shape">Path shape</param>
 /// <param name="duration">Movement duration in seconds</param>
 /// <param name="easing">Movement easing function</param>
 public OTPathController(Object owner, string name, OTShape shape, float duration, OTEase easing)
     : base(owner, name)
 {
     this.shape = shape;
     this.duration = duration;
     this.easing = easing;
 }
예제 #13
0
 public OTActionTween(string name, object toValue, float duration, OTEase easing)
     : base(name)
 {
     getFromValue = true;
     this.toValue = toValue;
     this._duration = duration;
     this.easing = easing;
 }
예제 #14
0
 public OTActionTween(string name, object toValue, float duration, OTEase easing)
     : base(name)
 {
     getFromValue   = true;
     this.toValue   = toValue;
     this._duration = duration;
     this.easing    = easing;
 }
예제 #15
0
파일: OTTween.cs 프로젝트: jedirandy/Eileen
    public bool Update(float deltaTime)
    {
        if (_doStop)
        {
            _running = false;
            return(true);
        }

        if (waitTime > 0)
        {
            waitTime -= Time.deltaTime;
            if (waitTime > 0)
            {
                return(false);
            }
        }
        if (vars.Count == 0)
        {
            return(false);
        }
        _running = true;

        time += deltaTime;
        if (time > duration)
        {
            time = duration;
        }
        for (int v = 0; v < vars.Count; v++)
        {
            OTEase easing = this.easing;
            if (easings[v] != null)
            {
                easing = easings[v];
            }
            TweenVar(fromValues[v], toValues[v], easing, fields[v], props[v]);
        }
        if (time == duration)
        {
            _running = false;
            if (onTweenFinish != null)
            {
                onTweenFinish(this);
            }
            if (!CallBack("onTweenFinish", new object[] { this }))
            {
                CallBack("OnTweenFinish", new object[] { this });
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }
예제 #16
0
 /// <summary>
 /// Tween a 'public' property, adding a value, of the tween's target object.
 /// </summary>
 /// <param name="var">Property name</param>
 /// <param name="addValue">Value to add</param>
 /// <param name="easing">Easing function</param>
 /// <param name="pongEasing">Easing when 'ponging'</param>
 /// <returns>Tween object</returns>
 public OTTween TweenAdd(string var, object addValue, OTEase easing, OTEase pongEasing)
 {
     vars.Add(var);
     addValues.Add(addValue);
     SetVar(var);
     easings.Add(easing);
     pongEasings.Add(pongEasing);
     toValues.Add(null);
     AddValue(fromValues.Count - 1, addValue);
     return(this);
 }
예제 #17
0
 /// <summary>
 /// Incremental movement action constructor
 /// </summary>
 /// <param name="byValue">Incremental movement value</param>
 /// <param name="duration">Movement duration</param>
 /// <param name="easing">Movement easing function</param>
 public OTActionMoveBy(Vector2 byValue, float duration, OTEase easing)
     : base("position", Vector2.zero, duration, easing)
 {
     this.byValue = byValue;
 }
예제 #18
0
 /// <summary>
 /// Fade in action constructor
 /// </summary>
 /// <param name="duration">Fade in duration in seconds</param>
 /// <param name="easing">Fade in easing function</param>
 public OTActionFadeIn(float duration, OTEase easing) :
     base(1, duration, easing)
 {
 }
예제 #19
0
 public OTActionRotate(float toValue, float duration, OTEase easing)
     : base("rotation", toValue, duration, easing)
 {
 }
예제 #20
0
    public bool Update(float deltaTime)
    {
        if (_pauzed)
        {
            return(false);
        }

        if (_doStop)
        {
            _running = false;
            return(true);
        }

        if (waitTime > 0)
        {
            waitTime -= Time.deltaTime;
            if (waitTime > 0)
            {
                return(false);
            }
        }
        if (vars.Count == 0)
        {
            return(false);
        }
        _running = true;

        float dur = duration;

        if (pingPong)
        {
            dur /= 2;
        }

        _restarted = false;
        time      += deltaTime;
        if (time > dur)
        {
            time = dur;
        }
        for (int v = 0; v < vars.Count; v++)
        {
            OTEase easing = this.easing;
            if (pingPong && !ping && pongEasings[v] != null)
            {
                easing = pongEasings[v];
            }
            else
            if (easings[v] != null)
            {
                easing = easings[v];
            }
            TweenVar(fromValues[v], toValues[v], easing, fields[v], props[v]);
        }

        if (time == dur)
        {
            if (_pingPong)
            {
                time = 0;
                for (int v = 0; v < vars.Count; v++)
                {
                    object t = toValues[v];
                    toValues[v]   = fromValues[v];
                    fromValues[v] = t;
                }

                if (ping)
                {
                    ping = false;
                    if (onTweenPing != null)
                    {
                        onTweenPing(this);
                    }
                    if (!CallBack("onTweenPing", new object[] { this }))
                    {
                        CallBack("OnTweenPing", new object[] { this });
                    }
                    time = 0;
                    return(false);
                }
                else
                {
                    ping = true;
                    if (onTweenPong != null)
                    {
                        onTweenPong(this);
                    }
                    if (!CallBack("onTweenPong", new object[] { this }))
                    {
                        CallBack("OnTweenPong", new object[] { this });
                    }
                }
            }
            _played++;
            if (playCount > 0)
            {
                --playCount;
            }
            if (onTweenPlayed != null)
            {
                onTweenPlayed(this);
            }
            if (!CallBack("onTweenPlayed", new object[] { this }))
            {
                CallBack("OnTweenPlayed", new object[] { this });
            }

            if (playCount == 0)
            {
                _running = false;
                if (onTweenFinish != null)
                {
                    onTweenFinish(this);
                }
                if (!CallBack("onTweenFinish", new object[] { this }))
                {
                    CallBack("OnTweenFinish", new object[] { this });
                }
                return(true);
            }
            else
            {
                if (!pingPong)
                {
                    // reset add tween start values to new values
                    for (int v = 0; v < vars.Count; v++)
                    {
                        object t = addValues[v];
                        if (t != null)
                        {
                            fromValues[v] = toValues[v];
                            AddValue(v, t);
                        }
                    }
                }
            }

            time = 0;
            return(false);
        }
        else
        {
            return(false);
        }
    }
예제 #21
0
 /// <summary>
 /// Incremental movement action constructor
 /// </summary>
 /// <param name="byValue">Incremental movement value</param>
 /// <param name="duration">Movement duration</param>
 /// <param name="easing">Movement easing function</param>
 public OTActionMoveBy(Vector2 byValue, float duration, OTEase easing)
     : base("position",Vector2.zero,duration,easing)
 {
     this.byValue = byValue;
 }
예제 #22
0
 public OTTimeCyclePart(string name, float length, OTEase ease)
 {
     this.name = name;
     this.length = length;
     this.ease = ease;
 }
예제 #23
0
 /// <summary>
 /// Tween a 'public' property of the tween's owner object
 /// </summary>
 /// <param name="var">Property name</param>
 /// <param name="toValue">To value</param>
 /// <param name="easing">Easing function</param>
 /// <returns>Tween object</returns>
 public OTTween Tween(string var, object toValue, OTEase easing)
 {
     return Tween(var, null, toValue, easing, null);
 }
예제 #24
0
 public OTTimeCyclePart(string name, float length, OTEase ease)
 {
     this.name   = name;
     this.length = length;
     this.ease   = ease;
 }
예제 #25
0
 public OTActionFade(float toValue, float duration, OTEase easing) :
     base("alpha", toValue, duration, easing)
 {
 }
예제 #26
0
 public OTActionFade(float toValue, float duration, OTEase easing) :
     base("alpha", toValue, duration, easing)
 {
 }
예제 #27
0
파일: OTTween.cs 프로젝트: jedirandy/Eileen
    private void TweenVar(object fromValue, object toValue, OTEase easing, FieldInfo field, PropertyInfo prop)
    {
        object value = null;

        if (toValue == null || fromValue == null)
        {
            return;
        }

        switch (fromValue.GetType().Name.ToLower())
        {
        case "single":
            if (!(toValue is float))
            {
                toValue = System.Convert.ToSingle(toValue);
            }
            value = easing.ease(time, (float)fromValue, (float)toValue - (float)fromValue, duration);
            break;

        case "double":
            if (!(toValue is double))
            {
                toValue = System.Convert.ToDouble(toValue);
            }
            value = easing.ease(time, (float)fromValue, (float)toValue - (float)fromValue, duration);
            break;

        case "int":
        case "int32":
            if (!(toValue is int))
            {
                toValue = System.Convert.ToInt32(toValue);
            }

            value = (int)easing.ease(time, (int)fromValue, (int)toValue - (int)fromValue, duration);
            break;

        case "vector2":
            Vector2 _toValue2   = (Vector2)toValue;
            Vector2 _fromValue2 = (Vector2)fromValue;
            Vector2 _value2     = Vector2.zero;

            if ((_toValue2 - _fromValue2).x != 0)
            {
                _value2.x = easing.ease(time, _fromValue2.x, (_toValue2 - _fromValue2).x, duration);
            }
            else
            {
                _value2.x = _fromValue2.x;
            }

            if ((_toValue2 - _fromValue2).y != 0)
            {
                _value2.y = easing.ease(time, _fromValue2.y, (_toValue2 - _fromValue2).y, duration);
            }
            else
            {
                _value2.y = _fromValue2.y;
            }

            value = _value2;
            break;

        case "vector3":
            Vector3 _toValue3   = (Vector3)toValue;
            Vector3 _fromValue3 = (Vector3)fromValue;
            Vector3 _value3     = Vector3.zero;

            if ((_toValue3 - _fromValue3).x != 0)
            {
                _value3.x = easing.ease(time, _fromValue3.x, (_toValue3 - _fromValue3).x, duration);
            }
            else
            {
                _value3.y = _fromValue3.y;
            }
            if ((_toValue3 - _fromValue3).y != 0)
            {
                _value3.y = easing.ease(time, _fromValue3.y, (_toValue3 - _fromValue3).y, duration);
            }
            else
            {
                _value3.y = _fromValue3.y;
            }
            if ((_toValue3 - _fromValue3).z != 0)
            {
                _value3.z = easing.ease(time, _fromValue3.z, (_toValue3 - _fromValue3).z, duration);
            }
            else
            {
                _value3.z = _fromValue3.z;
            }


            value = _value3;
            break;

        case "color":
            Color _toColor   = (Color)toValue;
            Color _fromColor = (Color)fromValue;

            float r = easing.ease(time, _fromColor.r, _toColor.r - _fromColor.r, duration);
            float g = easing.ease(time, _fromColor.g, _toColor.g - _fromColor.g, duration);
            float b = easing.ease(time, _fromColor.b, _toColor.b - _fromColor.b, duration);
            float a = easing.ease(time, _fromColor.a, _toColor.a - _fromColor.a, duration);

            value = new Color(r, g, b, a);
            break;
        }

        try
        {
            if (field != null)
            {
                field.SetValue(target, value);
            }
            else
            if (prop != null)
            {
                prop.SetValue(target, value, null);
            }
        }
        catch (System.Exception)
        {
            _doStop = true;
            return;
        };
    }
예제 #28
0
 /// <summary>
 /// Fade in action constructor
 /// </summary>
 /// <param name="duration">Fade in duration in seconds</param>
 /// <param name="easing">Fade in easing function</param>
 public OTActionFadeIn(float duration, OTEase easing) :
     base( 1, duration, easing) 
 { 
 }
예제 #29
0
    public bool Update(float deltaTime)
    {
        if (_pauzed)
            return false;

        if (_doStop)
        {
            _running = false;
            return true;
        }

        if (waitTime > 0)
        {
            waitTime -= Time.deltaTime;
            if (waitTime > 0) return false;
        }
        if (vars.Count == 0) return false;
        _running = true;

        float dur = duration;
        if (pingPong) dur/=2;

        _restarted = false;
        time += deltaTime;
        if (time > dur) time = dur;
        for (int v = 0; v < vars.Count; v++)
        {
            OTEase easing = this.easing;
            if (pingPong && !ping && pongEasings[v]!=null)
                easing = pongEasings[v];
            else
            if (easings[v] != null)
                easing = easings[v];
            TweenVar(fromValues[v], toValues[v], easing, fields[v], props[v]);
        }

        if (time == dur)
        {
            if (_pingPong)
            {
                time = 0;
                for (int v = 0; v < vars.Count; v++)
                {
                    object t = toValues[v];
                    toValues[v] = fromValues[v];
                    fromValues[v] = t;
                }

                if (ping)
                {
                    ping = false;
                    if (onTweenPing != null)
                        onTweenPing(this);
                    if (!CallBack("onTweenPing", new object[] { this }))
                        CallBack("OnTweenPing", new object[] { this });
                    time = 0;
                    return false;
                }
                else
                {
                    ping = true;
                    if (onTweenPong != null)
                        onTweenPong(this);
                    if (!CallBack("onTweenPong", new object[] { this }))
                        CallBack("OnTweenPong", new object[] { this });
                }

            }
            _played++;
            if (playCount>0)
                --playCount;
            if (onTweenPlayed != null)
                onTweenPlayed(this);
            if (!CallBack("onTweenPlayed", new object[] { this }))
                CallBack("OnTweenPlayed", new object[] { this });

            if (playCount==0)
            {
                _running = false;
                if (onTweenFinish != null)
                    onTweenFinish(this);
                if (!CallBack("onTweenFinish", new object[] { this }))
                    CallBack("OnTweenFinish", new object[] { this });
                return true;
            }
            else
            {
                if (!pingPong)
                {
                    // reset add tween start values to new values
                    for (int v = 0; v < vars.Count; v++)
                    {
                        object t = addValues[v];
                        if (t!=null)
                        {
                            fromValues[v] = toValues[v];
                            AddValue(v, t);
                        }
                    }
                }
            }

            time = 0;
            return false;

        }
        else
            return false;
    }
예제 #30
0
 /// <summary>
 /// Tween a 'public' property, adding a value, of the tween's target object.
 /// </summary>
 /// <param name="var">Property name</param>
 /// <param name="addValue">Value to add</param>
 /// <param name="easing">Easing function</param>
 /// <param name="pongEasing">Easing when 'ponging'</param>
 /// <returns>Tween object</returns>
 public OTTween TweenAdd(string var, object addValue, OTEase easing, OTEase pongEasing)
 {
     vars.Add(var);
     addValues.Add(addValue);
     SetVar(var);
     easings.Add(easing);
     pongEasings.Add(pongEasing);
     toValues.Add(null);
     AddValue(fromValues.Count-1, addValue);
     return this;
 }
예제 #31
0
 public OTActionRotate(float toValue, float duration, OTEase easing)
     : base("rotation", toValue, duration, easing)
 {
 }
예제 #32
0
파일: OTTween.cs 프로젝트: jedirandy/Eileen
 /// <summary>
 /// Tween a 'public' property, adding a value, of the tween's target object.
 /// </summary>
 /// <param name="var">Property name</param>
 /// <param name="addValue">Value to add</param>
 /// <param name="easing">Easing function</param>
 /// <returns>Tween object</returns>
 public OTTween TweenAdd(string var, object addValue, OTEase easing)
 {
     return(TweenAdd(var, addValue, easing, null));
 }
예제 #33
0
 public OTActionSize(Vector2 toValue, float duration, OTEase easing)
     : base("size", toValue, duration, easing)
 {
 }
예제 #34
0
파일: OTTween.cs 프로젝트: jedirandy/Eileen
 /// <summary>
 /// Tween a 'public' property of the tween's target object
 /// </summary>
 /// <param name="var">Property name</param>
 /// <param name="toValue">To value</param>
 /// <param name="easing">Easing function</param>
 /// <returns>Tween object</returns>
 public OTTween Tween(string var, object toValue, OTEase easing)
 {
     return(Tween(var, null, toValue, easing, null));
 }
예제 #35
0
 /// <summary>
 /// Incremental size action constructor
 /// </summary>
 /// <param name="byValue">Incremental size value</param>
 /// <param name="duration">Sizing duration</param>
 /// <param name="easing">Sizing easing function</param>
 public OTActionSizeBy(Vector2 byValue, float duration, OTEase easing)
     : base("size",Vector2.zero,duration,easing)
 {
     this.byValue = byValue;
 }
예제 #36
0
 public OTActionMove(Vector2 toValue, float duration, OTEase easing)
     : base("position", toValue, duration, easing)
 {
 }
예제 #37
0
 /// <summary>
 /// Tween a 'public' property, adding a value, of the tween's owner object.
 /// </summary>
 /// <param name="var">Property name</param>
 /// <param name="addValue">Value to add</param>
 /// <param name="easing">Easing function</param>
 /// <returns>Tween object</returns>
 public OTTween TweenAdd(string var, object addValue, OTEase easing)
 {
     return TweenAdd(var, addValue, easing, null);
 }
예제 #38
0
 /// <summary>
 /// Tween a 'public' property of the tween's owner object
 /// </summary>
 /// <param name="var">Property name</param>
 /// <param name="fromValue">From value</param>
 /// <param name="toValue">To value</param>
 /// <param name="easing">Easing function</param>
 /// <param name="pongEasing">Easing when 'ponging'</param>
 /// <returns>Tween object</returns>
 public OTTween Tween(string var, object fromValue, object toValue, OTEase easing, OTEase pongEasing)
 {
     vars.Add(var);
     SetVar(var);
     if (fromValue != null)
     {
         object fv = fromValues[fromValues.Count - 1];
         if (fv != null)
         {
             if (fv is float && fromValue is int)
                 fromValue = System.Convert.ToSingle(fromValue);
             else
                 if (fv is double && fromValue is int)
                     fromValue = System.Convert.ToDouble(fromValue);
         }
         fromValues[fromValues.Count - 1] = fromValue;
     }
     toValues.Add(toValue);
     easings.Add(easing);
     pongEasings.Add(pongEasing);
     return this;
 }
예제 #39
0
    private void TweenVar(object fromValue, object toValue, OTEase easing, FieldInfo field, PropertyInfo prop)
    {
        object value = null;
        if (toValue == null || fromValue == null) return;

        switch (fromValue.GetType().Name.ToLower())
        {
            case "single":
                if (!(toValue is float))
                    toValue = System.Convert.ToSingle(toValue);
                value = easing.ease(time, (float)fromValue, (float)toValue - (float)fromValue, duration);
                break;
            case "double":
                if (!(toValue is double))
                    toValue = System.Convert.ToDouble(toValue);
                value = easing.ease(time, (float)fromValue, (float)toValue - (float)fromValue, duration);
                break;
            case "int":
                if (!(toValue is int))
                    toValue = System.Convert.ToInt32(toValue);

                value = easing.ease(time, (int)fromValue, (int)toValue - (int)fromValue, duration);
                break;
            case "vector2":
                Vector2 _toValue2 = (Vector2)toValue;
                Vector2 _fromValue2 = (Vector2)fromValue;
                Vector2 _value2 = Vector2.zero;

                if ((_toValue2 - _fromValue2).x != 0)
                    _value2.x = easing.ease(time, _fromValue2.x, (_toValue2 - _fromValue2).x, duration);
                else
                    _value2.x = _fromValue2.x;

                if ((_toValue2 - _fromValue2).y != 0)
                    _value2.y = easing.ease(time, _fromValue2.y, (_toValue2 - _fromValue2).y, duration);
                else
                    _value2.y = _fromValue2.y;

                value = _value2;
                break;
            case "vector3":
                Vector3 _toValue3 = (Vector3)toValue;
                Vector3 _fromValue3 = (Vector3)fromValue;
                Vector3 _value3 = Vector3.zero;

                if ((_toValue3 - _fromValue3).x != 0)
                    _value3.x = easing.ease(time, _fromValue3.x, (_toValue3 - _fromValue3).x, duration);
                else
                    _value3.y = _fromValue3.y;
                if ((_toValue3 - _fromValue3).y != 0)
                    _value3.y = easing.ease(time, _fromValue3.y, (_toValue3 - _fromValue3).y, duration);
                else
                    _value3.y = _fromValue3.y;
                if ((_toValue3 - _fromValue3).z != 0)
                    _value3.z = easing.ease(time, _fromValue3.z, (_toValue3 - _fromValue3).z, duration);
                else
                    _value3.z = _fromValue3.z;

                value = _value3;
                break;
            case "color":
                Color _toColor = (Color)toValue;
                Color _fromColor = (Color)fromValue;

                float r = easing.ease(time, _fromColor.r, _toColor.r - _fromColor.r, duration);
                float g = easing.ease(time, _fromColor.g, _toColor.g - _fromColor.g, duration);
                float b = easing.ease(time, _fromColor.b, _toColor.b - _fromColor.b, duration);
                float a = easing.ease(time, _fromColor.a, _toColor.a - _fromColor.a, duration);

                value = new Color(r, g, b, a);
                break;
        }

        if (field != null)
            field.SetValue(owner, value);
        else
            if (prop != null)
                prop.SetValue(owner, value, null);
    }
예제 #40
0
    /// <summary>
    /// Tween a 'public' property, adding a value, of the tween's owner object.
    /// </summary>
    /// <param name="var">Property name</param>
    /// <param name="addValue">Value to add</param>
    /// <param name="easing">Easing function</param>
    /// <param name="pongEasing">Easing when 'ponging'</param>
    /// <returns>Tween object</returns>
    public OTTween TweenAdd(string var, object addValue, OTEase easing, OTEase pongEasing)
    {
        vars.Add(var);
        SetVar(var);
        easings.Add(easing);
        pongEasings.Add(pongEasing);
        object fromValue = fromValues[fromValues.Count - 1];

        if (fromValue is int)
        {
            try
            {
                addValue = System.Convert.ToInt32(addValue);
            }
            catch (System.Exception)
            {
                addValue = 0;
            }
        }
        else
            if (fromValue is float)
            {
                try
                {
                    addValue = System.Convert.ToSingle(addValue);
                }
                catch (System.Exception)
                {
                    addValue = 0.0f;
                }
            }
            else
                if (fromValue is double)
                {
                    try
                    {
                        addValue = System.Convert.ToDouble(addValue);
                    }
                    catch (System.Exception)
                    {
                        addValue = 0.0;
                    }
                }

        switch (fromValue.GetType().Name.ToLower())
        {
            case "single": toValues.Add((float)fromValue + (float)addValue); break;
            case "double": toValues.Add((double)fromValue + (double)addValue); break;
            case "int": toValues.Add((int)fromValue + (int)addValue); break;
            case "vector2": toValues.Add((Vector2)fromValue + (Vector2)addValue); break;
            case "vector3": toValues.Add((Vector3)fromValue + (Vector3)addValue); break;
            default: toValues.Add(null); break;
        }
        return this;
    }
예제 #41
0
 /// <summary>
 /// Incremental size action constructor
 /// </summary>
 /// <param name="byValue">Incremental size value</param>
 /// <param name="duration">Sizing duration</param>
 /// <param name="easing">Sizing easing function</param>
 public OTActionSizeBy(Vector2 byValue, float duration, OTEase easing)
     : base("size", Vector2.zero, duration, easing)
 {
     this.byValue = byValue;
 }
예제 #42
0
    /// <exclude />
    public bool Update(float deltaTime)
    {
        if (_doStop)
        {
            _running = false;
            return true;
        }

        if (waitTime > 0)
        {
            waitTime -= Time.deltaTime;
            if (waitTime > 0) return false;
        }
        if (vars.Count == 0) return false;
        _running = true;

        time += deltaTime;
        if (time > duration) time = duration;
        for (int v = 0; v < vars.Count; v++)
        {
            OTEase easing = this.easing;
            if (easings[v] != null)
                easing = easings[v];
            TweenVar(fromValues[v], toValues[v], easing, fields[v], props[v]);
        }
        if (time == duration)
        {
            _running = false;
            if (onTweenFinish != null)
                onTweenFinish(this);
            if (!CallBack("onTweenFinish", new object[] { this }))
                CallBack("OnTweenFinish", new object[] { this });
            return true;
        }
        else
            return false;
    }
예제 #43
0
 /// <summary>
 /// Incremental rotate action constructor
 /// </summary>
 /// <param name="byValue">Incremental rotate value</param>
 /// <param name="duration">Rotation duration</param>
 /// <param name="easing">Rotation easing function</param>
 public OTActionRotateBy(float byValue, float duration, OTEase easing)
     : base("rotation", 0, duration, easing)
 {
     this.byValue = byValue;
 }
예제 #44
0
 /// <summary>
 /// Tween a 'public' property of the tween's owner object
 /// </summary>
 /// <param name="var">Property name</param>
 /// <param name="fromValue">From value</param>
 /// <param name="toValue">To value</param>
 /// <param name="easing">Easing function</param>
 /// <param name="pongEasing">Easing when 'ponging'</param>
 /// <returns>Tween object</returns>
 public OTTween Tween(string var, object fromValue, object toValue, OTEase easing, OTEase pongEasing)
 {
     vars.Add(var);
     SetVar(var);
     if (fromValue != null)
     {
         object fv = fromValues[fromValues.Count - 1];
         if (fv != null)
         {
     #if UNITY_FLASH
             if (fv is float && fromValue is int)
                 ActionScript.Statement("$fromValue = Number($fromValue);");
     #else
             if (fv is float && fromValue is int)
                 fromValue = System.Convert.ToSingle(fromValue);
             else
                 if (fv is double && fromValue is int)
                     fromValue = System.Convert.ToDouble(fromValue);
     #endif
         }
         fromValues[fromValues.Count - 1] = fromValue;
     }
     toValues.Add(toValue);
     easings.Add(easing);
     pongEasings.Add(pongEasing);
     return this;
 }
예제 #45
0
 /// <summary>
 /// Fade out action constructor
 /// </summary>
 /// <param name="duration">Fade out duration in seconds</param>
 /// <param name="easing">Fade out easing function</param>
 public OTActionFadeOut(float duration, OTEase easing) :
     base(0, duration, easing)
 {
 }
예제 #46
0
 /// <summary>
 /// Incremental rotate action constructor
 /// </summary>
 /// <param name="byValue">Incremental rotate value</param>
 /// <param name="duration">Rotation duration</param>
 /// <param name="easing">Rotation easing function</param>
 public OTActionRotateBy(float byValue, float duration, OTEase easing)
     : base("rotation",0,duration,easing)
 {
     this.byValue = byValue;
 }
예제 #47
0
 /// <summary>
 /// Fade out action constructor
 /// </summary>
 /// <param name="duration">Fade out duration in seconds</param>
 /// <param name="easing">Fade out easing function</param>
 public OTActionFadeOut(float duration, OTEase easing) :
     base( 0, duration, easing)
 {
 }
예제 #48
0
 public OTActionSize(Vector2 toValue, float duration, OTEase easing)
     : base("size", toValue, duration, easing)
 {
 }
예제 #49
0
 public OTActionMove(Vector2 toValue, float duration, OTEase easing)
     : base("position", toValue, duration, easing)
 {
 }