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; }; }
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); }
protected override bool Execute() { if (value == null) { time = _duration; return(true); } if (time > _duration) { time = _duration; } switch (value.GetType().Name.ToLower()) { case "single": value = easing.ease(time, (float)fromValue, (float)toValue - (float)fromValue, _duration); break; case "double": value = easing.ease(time, (float)fromValue, (float)toValue - (float)fromValue, _duration); break; case "int": 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)value; 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)value; if ((_toValue3 - _fromValue3).x != 0) { _value3.x = easing.ease(time, _fromValue3.x, (_toValue3 - _fromValue3).x, _duration); } else { _value3.x = _fromValue3.x; } 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); } if (time == _duration) { return(true); } else { return(false); } }