You can define your method as follows:
public static IEnumerator Tweeng<T>(this float duration,
System.Action<T> var, T aa, T zz, Func<T,T,float,T> thing)
{
float sT = Time.time;
float eT = sT + duration;
while (Time.time < eT)
{
float t = (Time.time - sT) / duration;
var(thing(aa, zz, t));
yield return null;
}
var(zz);
}
And then using it:
float a = 5;
float b = 0;
float c = 0;
a.Tweeng(q => {}, b, c, Mathf.SmoothStep);
Or:
float a = 0;
Vector3 b = null;
Vector3 c = null;
a.Tweeng(q => {}, b, c, Vector3.Lerp);
Alternatively, if you want to get rid of the method passing, you can have simple overloads to handle it:
public static IEnumerator Tweeng(this float duration, System.Action<float> var, float aa, float zz)
{
return Tweeng(duration, var, aa, zz, Mathf.SmoothStep);
}
public static IEnumerator Tweeng(this float duration, System.Action<Vector3> var, Vector3 aa, Vector3 zz)
{
return Tweeng(duration, var, aa, zz, Vector3.Lerp);
}
private static IEnumerator Tweeng<T>(this float duration,
System.Action<T> var, T aa, T zz, Func<T,T,float,T> thing)
{
float sT = Time.time;
float eT = sT + duration;
while (Time.time < eT)
{
float t = (Time.time - sT) / duration;
var(thing(aa, zz, t));
yield return null;
}
var(zz);
}
And then using it:
float a = 5;
float b = 0;
float c = 0;
a.Tweeng(q => {}, b, c);
Or:
float a = 0;
Vector3 b = null;
Vector3 c = null;
a.Tweeng(q => {}, b, c);
Stub methods to compile in LINQPad/without unity:
public class Mathf { public static float SmoothStep(float aa, float zz, float t) => 0; }
public class Time { public static float time => DateTime.Now.Ticks; }
public class Vector3 { public static Vector3 Lerp(Vector3 aa, Vector3 zz, float t) => null; }