전체 글 (45) 썸네일형 리스트형 template method ... using System; public abstract class Dragon { public int hp; public int atk; public abstract void UpGround(); public abstract void DownGround(); public bool IsCheackTargetAlive() { return true; } public void Attack() { UpGround(); Debug.Log("공격한다"); DownGround(); if(IsCheackTargetAlive()) { Attack(); } } } public class BlueDragon : Dragon { public override void UpGround() { Debug.Log("올라왔다");.. EventHandler public event EventHandler 이벤트핸들러이름; 규격: public delegate void EventHandler(object sender, EventArgs e); sender: 호출한 애. 일반적으론 자기 자신. e: 추가적으로 전달해야할 부분이 있을 때 씀. 이벤트에 대한 매개 변수 호출 시 onDieHandler(this, null); 이런 식 *this -> object 형태로 보내주게 됨 묶을 때 atk +=((Monster)sender).atk; 이런 식으로 Monster로 만들어줘야. 이벤트가 발생하면 이벤트핸들러가 그걸 받아 이벤트핸들러에게 구독되어있는 이벤트 리스너들에게 알려줌. 그럼 리스너들이 그걸 받아 처리할거 처리함. 상황을 컨트롤하는 역할. public dele.. 프로퍼티 get 접근자에 대한 코드 블록은 속성을 읽을 때(호출 시) 실행 set 접근자에 대한 코드 블록은 속성에 새로운 값을 할당시킬 때 실행 class 클래스명 { 데이터타입 필드명; 접근한정자 데이터타입 프로퍼티명 { get{ return 필드명; } set{ 필드명 = value; } } } 전략적 패턴 다양한 객체에 접근이 필요할 때 공통 분모를 추상화하여 인터페이스 클래스를 만들어 이를 접근점으로 활용 public Interface I이름 { void function(); } using System.Collections; using System.Collections.Generic; using UnityEngine; public interface IWeapon{ void Shoot(GameObject obj); } using System.Collections; using System.Collections.Generic; using UnityEngine; public class Arrow : MonoBehaviour, IWeapon { void Start () { } public void Shoot(Ga.. 람다 이름이 없는 메서드. 즉석에서 구현할 수 있음 대충 한 줄 짜리 함수 만들기 아까울 때 쓰면 될 듯 형식 ( ) => { }; (매개변수들..) => { 리턴 타입에 맞는 값 } ; 예시 onAction += () => Debug.Log("처리A"); 오버라이딩 가능성 있을 경우 X.. 3줄 이상 돼도 X.. 가독성 떨어짐 예시 private int health = 0; public void RestoreHealth(int amount) { health += amount; } public bool IsDead() { return (health health += amount; public bool IsDead() => (health health = value; } public bool IsDead => (.. Event event라는 수식어가 붙은 delegate는 클래스 내부에서만 호출 가능. 제약이 좀 더 걸린 delegate 라 생각하면 됨. 체인으로 묶는 것은 가능하지만 함수를 호출할 수는 없음 물론 클래스 내부에선 뭔 짓을 해도 가능가능 사용 형태 예시 public event Action onAction; ... FindObject... ().onAction += Func(); Delegate - Action, Func using System; ... public Action onReduceHp; //리턴타입이 없고 매개변수가 없는 형태의 delegate public void Progress(Action testDel) { Debug.Log("어쩌고"); } 리턴타입이 없고 매개변수가 없는 형태의 delegate는 하도 많이 쓰다보니까... 앞사람이 틀을 아예 만들어놨음 public Action 이름; 이런 식으로 쓰면 됨 리턴 타입은 없지만 매개변수가 있는 경우 ( public delefate void OnDamage(float damage) public Action onDamage; 이런 식으로 적으면 됨. public Func returnInDel; Func한텐 가 리턴타입. 매개변수가 아님!! public Fun.. Delegate //delegate 리턴타입 델리게이트명(매개변수) public delegate void PrintInfoDel(); void Start() { PrintInfoDel printInfoDel; } public delegate int TestDel(int valueA, int valueB); int Sum(int A, int B) { return A + B; } void Start() { TestDel testDel; testDel = Sum; } public delegate 데이터타입 이름(변수 ... ) 이건 채용 공고같은 것. 조건이다. 함수를 대신 실행해주는 녀석이다! 어떠한 처리 A와 B 사이에 내가 실행하고 싶은 처리가 있을 때 사용해줌. public void TestPrint(PrintInfo.. 이전 1 2 3 4 5 6 다음