public TweenProperty(object target, PropertyInfo property, LerpFunction <T> lerpFunction) : base(lerpFunction) { this.target = target; this.property = property; initialValue = (T)property.GetValue(target); }
public TweenField(object target, FieldInfo field, LerpFunction <T> lerpFunction) : base(lerpFunction) { this.target = target; this.field = field; initialValue = (T)field.GetValue(target); }
static IEnumerator lerpColor(Renderer renderer, Color start, Color end, Timer timer, LerpFunction function){ while (!timer.IsFinished ()){ renderer.material.color = Color.Lerp(start, end, function(timer.Percent())); yield return 0; } renderer.material.color = end; }
public TweenSetter(T initialValue, Action <T> setter, LerpFunction <T> lerpFunction) : base(lerpFunction) { this.setter = setter; }
/// <summary> /// Creates a new tween and timeline. /// </summary> /// <param name="obj">The object to tween.</param> /// <param name="easingFunction">The easing function to use. (e.g. Easing.Linear)</param> /// <param name="endTime">The time, in milliseconds when the tween will end.</param> /// <param name="startTime">The time in milliseconds when the tween will begin.</param> /// <returns>A TweenTimeline with a tween attached.</returns> public static void Tween <T>(object target, string propertyName, T value, float duration, EasingFunction easingFunction, LerpFunction <T> lerpFunction, float delay = 0) { var timeline = new TweenTimeline(); var property = timeline.AddProperty <T>(target, propertyName, lerpFunction); property.AddFrame(duration, value); singleTimelines.Add(timeline); }
public TweenableProperty(LerpFunction <T> lerpFunction) { keyFrames = new List <TweenKeyFrame <T> >(); this.lerpFunction = lerpFunction; }
public TweenableProperty <T> AddProperty <T>(T initialValue, Action <T> setter, LerpFunction <T> lerpFunction) { var t = new TweenSetter <T>(initialValue, setter, lerpFunction); return(t); }
public TweenableProperty <T> AddProperty <T>(object target, string propertyName, LerpFunction <T> lerpFunction) { var properties = target.GetType().GetProperties(); var fields = target.GetType().GetFields(); var property = properties.FirstOrDefault(x => x.Name == propertyName); if (property != null) { if (property.PropertyType == typeof(T)) { var t = new TweenProperty <T>(target, property, lerpFunction); tweeningProperties.Add(t); return(t); } } else { var field = fields.FirstOrDefault(x => x.Name == propertyName); if (field != null) { if (field.FieldType == typeof(T)) { var t = new TweenField <T>(target, field, lerpFunction); tweeningProperties.Add(t); return(t); } } } return(null); }
private IEnumerator LerpToPositionAndRotation(Transform transfOfObject, Vector3 lerpTargetPos, Quaternion lerpTargetRot, LerpFunction function, float timeFactor) { lerpToPosAndRot = true; Vector3 lerpStartPos = transfOfObject.position; Quaternion lerpStartRot = transfOfObject.rotation; float timeSinceLerpStarted = 0;//Time.fixedDeltaTime; //float deltaTime = 0; float t = 0; while (t <= 1) { //float currLoopStart = Time.time; timeSinceLerpStarted += Time.deltaTime; t = timeSinceLerpStarted / timeFactor; switch (function) { case LerpFunction.linear: break; case LerpFunction.exponentialEase: t = 1f - Mathf.Pow(0.2f, t); break; case LerpFunction.sinEase: t = Mathf.Sin(t * Mathf.PI * 0.5f); break; case LerpFunction.smoothStep: t = t * t * (3f - 2f * t); break; case LerpFunction.smootherStep: t = t * t * t * (t * (6f * t - 15f) + 10f); break; } // Update camera rotation and position. transfOfObject.position = Vector3.Lerp(lerpStartPos, lerpTargetPos, t); transfOfObject.rotation = Quaternion.Slerp(lerpStartRot, lerpTargetRot, t); yield return(null); //deltaTime = Time.time - currLoopStart; //Debug.Log(deltaTime); } lerpToPosAndRot = false; }
public static IEnumerator LerpColor(this Material material, Color start, Color end, Timer timer, LerpFunction function){ return lerpColor(material, start, end, timer, function); }
public static IEnumerator LerpColor(this Renderer renderer, Color start, Color end, Timer timer, LerpFunction function){ return lerpColor(renderer, start, end, timer, function); }
static IEnumerator lerpRotation(Transform transform, Quaternion start, Quaternion end, Timer timer, LerpFunction function){ while (!timer.IsFinished ()){ transform.rotation = Quaternion.Lerp(start, end, function(timer.Percent())); yield return 0; } transform.rotation = end; }
public static IEnumerator LerpRotation(this Transform transform, Quaternion start, Quaternion end, Timer timer, LerpFunction function){ return lerpRotation(transform, start, end, timer, function); }
static IEnumerator lerpScale(Transform transform, Vector3 start, Vector3 end, Timer timer, LerpFunction function){ while (!timer.IsFinished ()){ transform.localScale = Vector3.Lerp(start, end, function(timer.Percent())); yield return 0; } transform.localScale = end; }
public static IEnumerator LerpScale(this Transform transform, Vector3 start, Vector3 end, Timer timer, LerpFunction function){ return lerpScale(transform, start, end, timer, function); }
/// <summary> /// Sets the linear interpolation function to use /// </summary> /// <param name="lerpFunction">A (T, T, float) => T function that defines a linear interpolation for the type that's being tweened</param> /// <returns>InBetween object with the new value set</returns> public InBetween <T> LerpWith(LerpFunction lerpFunction) { this.lerpFunction = lerpFunction; return(this); }