Answer the question
In order to leave comments, you need to log in
Do I need to somehow fix such overloads?
Hello! I have a static class with extension methods. And there is a Move method.
public static void Move(this Transform transform, Vector3 target, float time)
{
if (time < 0) Debug.LogError("Time can't be negative");
var start = transform.position;
var deltaTime = 0f;
var thread = _updateThreads.CreateThread();
Observable.EveryUpdate().Subscribe(action =>
{
if (deltaTime >= 1)
{
transform.position = target;
_updateThreads.ClearThread(thread);
}
transform.position = Vector3.Lerp(start, target, deltaTime);
deltaTime += Time.deltaTime / time;
}).AddTo(thread);
}
public static void Move(this Transform transform, Vector3 target, float time, AnimationCurve curve)
{
if (time < 0) Debug.LogError("Time can't be negative");
if (curve == null) Debug.LogError("Curve is null");
var start = transform.position;
var deltaTime = 0f;
var thread = _updateThreads.CreateThread();
Observable.EveryUpdate().Subscribe(action =>
{
if (deltaTime >= 1)
{
transform.position = target;
_updateThreads.ClearThread(thread);
}
transform.position = Vector3.Lerp(start, target, curve.Evaluate(deltaTime));
deltaTime += Time.deltaTime / time;
}).AddTo(thread);
}
Answer the question
In order to leave comments, you need to log in
The fact that you introduce new methods is normal. But inside they can use each other. You have violated the DRY principle.
Rewrite it so that the first Move calls the overloaded variant with some default parameter.
Yes, there seems to be such a thing as default parameter values, but now in .NET the general trend is to abandon them in the direction of adding method overloads.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question