1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 5 public class callback : MonoBehaviour { 6 public bool IsSuccessCallBack = true; 7 private delegate void VoidDelegate(); 8 [ContextMenu("Build")] 9 public void Build() 10 { 11 StartCoroutine(Builder(SuccessCallBack, FailureCallBack)); 12 } 13 14 private IEnumerator Builder(VoidDelegate success, VoidDelegate failure) 15 { 16 if (!IsSuccessCallBack) 17 { 18 failure(); 19 yield break; 20 } 21 //前面是种种导致执行失败的判断 22 success(); 23 } 24 25 private void SuccessCallBack() 26 { 27 Debug.Log("该函数执行成功"); 28 } 29 30 private void FailureCallBack() 31 { 32 Debug.Log("该函数执行失败"); 33 } 34 }