委托是一种数据类型
    作用:占位,在不知道将来要执行的方法的具体代码时,可以先用一个委托变量来代替方法调用(委托的返回值,参数列表要确定)。在实际调用之前,需要为委托赋值,否则为null。

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class _1DelegateBasics : MonoBehaviour
    5. {
    6. //一、基础委托 是数据类型
    7. //1.定义阶段
    8. delegate void delegateHandler();
    9. delegateHandler method;
    10. //2.注册阶段
    11. void OnEnable()
    12. {
    13. method = delegateLogic;
    14. }
    15. void delegateLogic()
    16. {
    17. Debug.Log("01-----delegateLogic-------");
    18. }
    19. //3.执行阶段 可以在类外执行
    20. private void Start()
    21. {
    22. method();
    23. }
    24. private void OnDestroy()
    25. {
    26. method -= delegateLogic;
    27. }
    28. }