반응형
예시 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | //델리게이트 전역 선언 public delegate void Next_Process(); public class Main: MonoBehaviour { public LoadManager _LoadManager; public void ChangeScene() { _LoadManager.LoadScene("Battle", Callbakc_SceneLoadMidProcess, Callback_SceneLoadComplete); } void Callbakc_SceneLoadMidProcess() { debug.Log("Mid process"); } void Callback_SceneLoadComplete() { debug.Log("complete process"); } } public class LoadManager : MonoBehaviour { public void LoadScene(string sceneName,Next_Process midProcess, Next_Process completeProcess) { StartCoroutine(routine_LoadScene(sceneName, midProcess, completeProcess)); } IEnumerator routine_LoadScene(string sceneName,Next_Process midProcess, Next_Process completeProcess) { asyncLoadScene = SceneManager.LoadSceneAsync(sceneName); asyncLoadScene.allowSceneActivation = false; while (true) { if (asyncLoadScene.isDone) { Debug.Log("DONE"); //완료시 콜백 if (completeProcess != null) completeProcess(); break; } if (asyncLoadScene.progress == 0.9f) { Debug.Log("mid"); //90퍼시 진행시 콜백 if(midProcess != null) midProcess(); } Debug.Log(asyncLoadScene.progress + " % "); yield return null; } } } | cs |
ㅇ
예시예시2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | //델리게이트 전역선언 public delegate void Next_Process(); // void형 델리게이트 public delegate void Next_AttackProcess(RaycastHit _hitInfo); //RaycastHit 형 델리게이트 public class AttackComponent : ComponentBase { private Next_AttackProcess SuccessAttack; private Next_Process FailAttack; //생성자 public AttackComponent(UnitBase _uInfo, string _attackTagName, Next_AttackProcess _SuccessAttack = null, Next_Process _FailAttack = null) { uInfo = _uInfo; attackTagName = _attackTagName; SuccessAttack = _SuccessAttack; FailAttack = _FailAttack; } public override void Updating() { if (!uInfo.unitData.isDie) { //레이쏘기 ShotRay(uInfo.Get_Transform().position + addUpStartShootPosition, uInfo.Get_Transform().forward, uInfo.unitData.AttDistance, attackTagName, SuccessAttack, FailAttack); } } Color hitColor = Color.white; void ShotRay(Vector3 start, Vector3 direction, float distance, string tagName, Next_AttackProcess successNxt, Next_Process failNxt) { Debug.DrawRay(start, direction * distance, hitColor); hitColor = Color.white; bool isFind = false; RaycastHit[] hits = Physics.RaycastAll(start, direction, distance); for (int i = 0; i < hits.Length; i++) { if (isFind) break; if (string.Equals(hits[i].collider.tag, tagName)) { isFind = true; //공격성공시 콜백 if (successNxt != null) successNxt(hits[i]); hitColor = Color.red; } } if (!isFind) { //공격실패시 콜백 if (failNxt != null) failNxt(); } } } | cs |
반응형
'C#' 카테고리의 다른 글
[C#] 정의한 enum 을 array로 변환해 처리하기 (0) | 2019.02.19 |
---|---|
[C#] 홀수, 짝수 구분하기 (0) | 2019.01.24 |
[C#] enum 에서 Flags 속성달기 (1) | 2019.01.10 |
[C#] 문자열에 특정 문자열이 포함 여부 확인 (0) | 2018.12.03 |
[C#] 삼항연산자 (0) | 2018.11.23 |