I'm trying to figure out how to do something with c# that I've noticed in particular the Unity engine does. it seems like some form of implementation or subclassing but as I don't have the source I don't know.
in Unity all of the scripts do like this:
class someclass : MonoBehavior
{
}
now there is a list of functions you can use that the engine via this MonoBehavior calls in your classes such as
void OnGUI()
{
so something here
}
so if you have say 5 scripts that all contain the OnGUI function it gets called in all 5 scripts
I want to implement this type of thing myself but I can't figure this out.
How do you write a Base class or Implementation or whatever this is that calls pre-defined functions in your sub classes but does not require the subclass to the functions and without having to use override in them ?
here is an example source file from unity Engine:
public class EnemyAttack : MonoBehaviour {
// Use this for initialization
void Start () {
AttackTimer = 0;
CoolDown = 2.0f;
}
// Update is called once per frame
void Update () {
if (AttackTimer > 0) AttackTimer -= Time.deltaTime;
if (AttackTimer < 0) AttackTimer = 0;
if (AttackTimer == 0){
Attack();
AttackTimer = CoolDown;
}
}
}
that code works perfectly and then engine calls start at first startup (single call) and calls Update every frame notice absolutely NO override is in that code anywhere
it sems to be some sort of event system but I can't find anything on google that describes how to do this.