首页 > 代码库 > C# 事件event

C# 事件event

public class AAA: MonoBehaviour {

    public delegate void PlayEndDelegate();
    public event PlayEndDelegate playEndEvent;

    private void playEndHandler(){
        playEndEvent();
    }

}
public class BBB: MonoBehaviour {
    public AAA aaa;

     void Start () {
        aaa.playEndEvent+=playEndHandler;
    }

    private void playEndHandler(){
        Debug.Log("bbb playEndHandler");
    }
}
//output: bbb playEndHandler

 

C# 事件event