/// <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);
    }
Beispiel #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();
 }
Beispiel #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);
    }
Beispiel #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();
 }
Beispiel #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();
 }
Beispiel #8
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();
 }
Beispiel #9
0
 /// <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);
 }
Beispiel #10
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();
 }
Beispiel #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();
 }
 /// <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;
 }
 public OTActionTween(string name, object toValue, float duration, OTEase easing)
     : base(name)
 {
     getFromValue = true;
     this.toValue = toValue;
     this._duration = duration;
     this.easing = easing;
 }
Beispiel #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;
 }
Beispiel #15
0
    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);
        }
    }
Beispiel #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);
 }
Beispiel #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;
 }
Beispiel #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)
 {
 }
 public OTActionRotate(float toValue, float duration, OTEase easing)
     : base("rotation", toValue, duration, easing)
 {
 }
Beispiel #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);
        }
    }
 /// <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;
 }
Beispiel #22
0
 public OTTimeCyclePart(string name, float length, OTEase ease)
 {
     this.name = name;
     this.length = length;
     this.ease = ease;
 }
Beispiel #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);
 }
Beispiel #24
0
 public OTTimeCyclePart(string name, float length, OTEase ease)
 {
     this.name   = name;
     this.length = length;
     this.ease   = ease;
 }
 public OTActionFade(float toValue, float duration, OTEase easing) :
     base("alpha", toValue, duration, easing)
 {
 }
 public OTActionFade(float toValue, float duration, OTEase easing) :
     base("alpha", toValue, duration, easing)
 {
 }
Beispiel #27
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":
        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;
        };
    }
 /// <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) 
 { 
 }
    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;
    }
 /// <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;
 }
 public OTActionRotate(float toValue, float duration, OTEase easing)
     : base("rotation", toValue, duration, easing)
 {
 }
Beispiel #32
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>
 /// <returns>Tween object</returns>
 public OTTween TweenAdd(string var, object addValue, OTEase easing)
 {
     return(TweenAdd(var, addValue, easing, null));
 }
 public OTActionSize(Vector2 toValue, float duration, OTEase easing)
     : base("size", toValue, duration, easing)
 {
 }
Beispiel #34
0
 /// <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));
 }
 /// <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;
 }
 public OTActionMove(Vector2 toValue, float duration, OTEase easing)
     : base("position", toValue, duration, easing)
 {
 }
Beispiel #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);
 }
Beispiel #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;
 }
Beispiel #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);
    }
Beispiel #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;
    }
Beispiel #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;
 }
Beispiel #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;
    }
Beispiel #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;
 }
Beispiel #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;
 }
Beispiel #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)
 {
 }
 /// <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;
 }
 /// <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)
 {
 }
 public OTActionSize(Vector2 toValue, float duration, OTEase easing)
     : base("size", toValue, duration, easing)
 {
 }
Beispiel #49
0
 public OTActionMove(Vector2 toValue, float duration, OTEase easing)
     : base("position", toValue, duration, easing)
 {
 }