I know in javascript, I can pass in a function name, and an array of vars, and then execute that function with those vars at an arbitrary moment in time later.
It makes it easier that everything is basically the same var thing. In C#, there is also var, but it looks like the type gets defined depending on what you place into it.
What I am trying to accomplish is to say:
take the function and parameters: foo(bar1,bar2...barN)
and execute them in 5 seconds.
I'm using Unity, so the timing part is simple, but I can't figure out how to pass a function and specify arbitrary possible parameters of arbitrary types.
pseudo code:
class myTimerClass{
functionHandle myFunction;
var params;
float startTime, delayTime;
bool pending = false;
public myTimerClass(functionHandle myFunction, var params, float delay){
this.myFunction = myFunction;
this.params = params;
this.delay = delay;
this.startTime = System.currentTime;
pending = true;
}
public void update(){
if(System.currentTime>=startTime+delay && pending){
pending = false;
INVOKE(myFunction,params);
}
}
}
<something calls the update() every frame>
I've read up on action and func<> and delegates, but there doesn't seem to be a way to handle an arbitrary function with arbitrary params.