public static IEnumerator <CoroutineState> EaseColorProperty(Func <float, float, float, float> easingFunction, object target, string propertyName, Color from, Color to, float lerpTime) { PropertyInfo property = target.GetType().GetProperty(propertyName); if (property == null) { throw new Exception($"Could not find property {propertyName} on type {target.GetType().AssemblyQualifiedName}"); } if (property.PropertyType != typeof(Color)) { throw new Exception($"Property {propertyName} on type {target.GetType().AssemblyQualifiedName} is not of type 'Color'"); } float elapsedTime = 0; while (elapsedTime < lerpTime) { float t = elapsedTime / lerpTime; Color lerpedValue = new Color() { A = (byte)easingFunction(from.A, to.A, t), R = (byte)easingFunction(from.R, to.R, t), G = (byte)easingFunction(from.G, to.G, t), B = (byte)easingFunction(from.B, to.B, t), }; property.SetValue(target, lerpedValue); elapsedTime += Time.DeltaTime; yield return(CoroutineState.Tick()); } }
public static IEnumerator <CoroutineState> EaseFloatProperty(Func <float, float, float, float> easingFunction, object target, string propertyName, float from, float to, float lerpTime) { PropertyInfo property = target.GetType().GetProperty(propertyName); if (property == null) { throw new Exception($"Could not find property {propertyName} on type {target.GetType().AssemblyQualifiedName}"); } if (property.PropertyType != typeof(float)) { throw new Exception($"Property {propertyName} on type {target.GetType().AssemblyQualifiedName} is not of type 'float'"); } float elapsedTime = 0; while (elapsedTime < lerpTime) { float t = elapsedTime / lerpTime; float lerpedValue = easingFunction(from, to, t); property.SetValue(target, lerpedValue); elapsedTime += Time.DeltaTime; yield return(CoroutineState.Tick()); } }
private void ResumeCoroutine() { bool completed = !this.coroutine.MoveNext(); this.currentState = this.coroutine.Current; if (completed || this.currentState.Item1 == CoroutineStatus.Halt) { this.IsComplete = true; } }
public void Run() { if (this.IsCancelled) { this.IsComplete = true; return; } if (this.currentState != null) { switch (this.currentState.Item1) { case CoroutineStatus.Halt: this.IsComplete = true; break; case CoroutineStatus.Delay: float remainingTime = (float)this.currentState.Item2; remainingTime -= Time.DeltaTime; if (remainingTime <= 0) { ResumeCoroutine(); } else { this.currentState = new CoroutineState(this.currentState.Item1, remainingTime); } break; default: ResumeCoroutine(); break; } } else { this.ResumeCoroutine(); } if (this.IsComplete) { foreach (Action <Component> after in this.after) { after(this.parent); } } }
public static IEnumerator <CoroutineState> WaitForSeconds(float seconds) { yield return(CoroutineState.Wait(seconds)); yield return(CoroutineState.Halt()); }
public static CoroutineState Wait(int milliseconds) { return(CoroutineState.Wait(milliseconds / 1000f)); }