/// <summary> /// Returns the function used for this ease /// </summary> /// <param name="ease"></param> /// <returns></returns> public static EaseFunction ToFunction(this StratusEase ease) { switch (ease) { case StratusEase.Linear: return(Linear); case StratusEase.QuadraticIn: return(QuadIn); case StratusEase.QuadraticInOut: return(QuadInOut); case StratusEase.QuadraticOut: return(QuadOut); case StratusEase.CubicIn: return(CubicIn); case StratusEase.CubicOut: return(CubicOut); case StratusEase.CubicInOut: return(CubicInOut); case StratusEase.ElasticIn: return(ElasticIn); case StratusEase.ElasticOut: return(ElasticOut); case StratusEase.ElasticInOut: return(ElasticInOut); case StratusEase.ExponentialIn: return(ExponentialIn); case StratusEase.ExponentialOut: return(ExponentialOut); case StratusEase.ExponentialInOut: return(ExponentialInOut); case StratusEase.SineIn: return(SineIn); case StratusEase.SineOut: return(SineOut); case StratusEase.SineInOut: return(SineInOut); case StratusEase.Smoothstep: return(Smoothstep); } throw new System.Exception($"No function found for the ease {ease}"); }
public static float Evaluate(this StratusEase ease, float t) => easingFunctions[ease](t);
//--------------------------------------------------------------------------------------------/ // Functions: Calculate t //--------------------------------------------------------------------------------------------/ /// <summary> /// Recalculates the given t value based on the ease selected /// </summary> /// <param name="t"></param> /// <param name="ease"></param> /// <returns></returns> public static float Calculate(StratusEase ease, float t) => easingFunctions[ease](t);
public StratusActionPropertyBase(object target, FieldInfo field, T endValue, float duration, StratusEase ease) : base(duration, ease) { this.target = target; this.field = field; this.endValue = endValue; base.duration = duration; this.easeType = ease; }
/// <summary> /// Constructor /// </summary> /// <param name="duration">How long should the action delay for</param> /// <param name="ease">The interpolation algorithm to use</param> public StratusActionProperty(float duration, StratusEase ease) { this.duration = duration; this.easeType = ease; }
public static IEnumerator Interpolate(Vector3 initialValue, Vector3 finalValue, float duration, System.Action <Vector3> setter, StratusEase ease = StratusEase.Linear, System.Action onFinished = null, StratusTimeScale timeScale = StratusTimeScale.Delta) { Vector3 diff = finalValue - initialValue; StratusEasing.EaseFunction easeFunc = ease.ToFunction(); System.Action <float> lerp = (float t) => { Vector3 currentValue = initialValue + diff * easeFunc(t); setter.Invoke(currentValue); }; yield return(Lerp(lerp, duration, timeScale)); setter.Invoke(finalValue); onFinished?.Invoke(); }
//----------------------------------------------------------------------/ // CTOR //----------------------------------------------------------------------/ public StratusActionPropertyBase(object target, PropertyInfo property, T endValue, float duration, StratusEase ease) : base(duration, ease) { this.target = target; this.property = property; this.endValue = endValue; base.duration = duration; this.easeType = ease; }
public StratusActionPropertyVector4(object target, FieldInfo field, Vector4 endValue, float duration, StratusEase ease) : base(target, field, endValue, duration, ease) { }
public StratusActionPropertyVector4(object target, PropertyInfo property, Vector4 endValue, float duration, StratusEase ease) : base(target, property, endValue, duration, ease) { }
public StratusActionPropertyQuaternion(object target, FieldInfo field, Quaternion endValue, float duration, StratusEase ease) : base(target, field, endValue, duration, ease) { }
public StratusActionPropertyQuaternion(object target, PropertyInfo property, Quaternion endValue, float duration, StratusEase ease) : base(target, property, endValue, duration, ease) { }
/// <summary> /// Adds a property change to the action set. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="set">A reference to the set.</param> /// <param name="varExpr">A lambda expression encapsulating a reference to the property which will be modified</param> /// <param name="value">The new value for the property</param> /// <param name="duration">Over how long should the property be changed</param> /// <param name="ease">What interpolation algorithm to use</param> public static void Property <T>(StratusActionSet set, Expression <Func <T> > varExpr, T value, float duration, StratusEase ease) { MemberExpression memberExpr = varExpr.Body as MemberExpression; Expression inst = memberExpr.Expression; string variableName = memberExpr.Member.Name; object targetObj = Expression.Lambda <Func <object> >(inst).Compile()(); // Construct an action then branch depending on whether the member to be // interpolated is a property or a field StratusAction action = null; // Property PropertyInfo property = targetObj.GetType().GetProperty(variableName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); if (property != null) { Type propertyType = property.PropertyType; if (propertyType == typeof(float)) { action = new StratusActionPropertyFloat(targetObj, property, Convert.ToSingle(value), duration, ease); } else if (propertyType == typeof(int)) { action = new StratusActionPropertyInt(targetObj, property, Convert.ToInt32(value), duration, ease); } else if (propertyType == typeof(bool)) { action = new StratusActionPropertyBool(targetObj, property, Convert.ToBoolean(value), duration, ease); } else if (propertyType == typeof(Vector2)) { action = new StratusActionPropertyVector2(targetObj, property, (Vector2)Convert.ChangeType(value, typeof(Vector2)), duration, ease); } else if (propertyType == typeof(Vector3)) { action = new StratusActionPropertyVector3(targetObj, property, (Vector3)Convert.ChangeType(value, typeof(Vector3)), duration, ease); } else if (propertyType == typeof(Vector4)) { action = new StratusActionPropertyVector4(targetObj, property, (Vector4)Convert.ChangeType(value, typeof(Vector4)), duration, ease); } else if (propertyType == typeof(Color)) { action = new StratusActionPropertyColor(targetObj, property, (Color)Convert.ChangeType(value, typeof(Color)), duration, ease); } else if (propertyType == typeof(Quaternion)) { action = new StratusActionPropertyQuaternion(targetObj, property, (Quaternion)Convert.ChangeType(value, typeof(Quaternion)), duration, ease); } else { Stratus.StratusDebug.Log("Couldn't find the property!"); } } // Field else { FieldInfo field = targetObj.GetType().GetField(variableName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); Type fieldType = field.FieldType; if (fieldType == typeof(float)) { action = new StratusActionPropertyFloat(targetObj, field, Convert.ToSingle(value), duration, ease); } else if (fieldType == typeof(int)) { action = new StratusActionPropertyInt(targetObj, field, Convert.ToInt32(value), duration, ease); } else if (fieldType == typeof(bool)) { action = new StratusActionPropertyBool(targetObj, field, Convert.ToBoolean(value), duration, ease); } else if (fieldType == typeof(Vector2)) { action = new StratusActionPropertyVector2(targetObj, field, (Vector2)Convert.ChangeType(value, typeof(Vector2)), duration, ease); } else if (fieldType == typeof(Vector3)) { action = new StratusActionPropertyVector3(targetObj, field, (Vector3)Convert.ChangeType(value, typeof(Vector3)), duration, ease); } else if (fieldType == typeof(Vector4)) { action = new StratusActionPropertyVector4(targetObj, field, (Vector4)Convert.ChangeType(value, typeof(Vector4)), duration, ease); } else if (fieldType == typeof(Color)) { action = new StratusActionPropertyColor(targetObj, field, (Color)Convert.ChangeType(value, typeof(Color)), duration, ease); } else if (fieldType == typeof(Quaternion)) { action = new StratusActionPropertyQuaternion(targetObj, field, (Quaternion)Convert.ChangeType(value, typeof(Quaternion)), duration, ease); } else { Stratus.StratusDebug.Log("Couldn't find the field!"); } } // Now add it! set.Add(action); }