hello everyone
I’ trying to write a globe script in c# to control the overall execute order, the project i’m working is a educational software, whose every steps must be executed one by one, first thing i realize is using delegate like :
public class demo : MonoBehaviour {
public delegate void OnStepChangeHandler(int step);
public static event OnStepChangeHandler OnStepChange;
//step
public int Step{get;private set;}
//to make sure step is changed
private int stepCache = 0;
public void SetStep(int i)
{
if(stepCache!=i)
{
//if step is changed, fire the overall event
this.Step = i;
OnStepChange(this.Step);
}
this.stepCache = this.Step;
}
}
and other scripts will listen to the event, as camera:
void OnEnable()
{
demo.OnStepChange += moveCam;
}
void OnDisable()
{
demo.OnStepChange -= moveCam;
}
void moveCam(int step)
{
switch (step)
{
case 1:
//move camera
break;
case 2:
//move camera
break;
}
}
it’s works , however, i realize it‘s maybe not a good idea to control overall steps by events: anyone can change overall steps and the whole game logic becomes a mess
sorry, i gonna work, update later