Delegate를 메서드 파라미터로 전달
main.cs
test.setDelegateFunc(btnDeleteImage);
void btnDeleteImage(int idx){
//소스코드
}
test.cs
public delegate void DelItemIndex(int idx);
private DelItemIndex delItemIndex;
public void setDelegateFunc(DelItemIndex func)
{
delItemIndex = func;
}
public void btnDeleteItem()
{
delItemIndex(itemIndex);
}
event를 사용하여 추가제거하는 방법
ColliderCheck.cs
public delegate void ColliderExitCheck(String item,string name);
public static event ColliderExitCheck colliderExitCheck;
test.cs
void Start(){
ColliderCheck.colliderExitCheck += checkExitCollider;
}
private void OnDestroy()
{
ColliderCheck.colliderExitCheck -= checkExitCollider;
}
void checkExitCollider(String item,string name)
{
}
Action함수 delegate와 큰 차이는 없는듯. |
[Serializable]
public class SelectionPageChangedEvent : UnityEvent<int> { }
[SerializeField]
private SelectionPageChangedEvent m_OnSelectionPageChangedEvent
= new SelectionPageChangedEvent();
public SelectionPageChangedEvent OnSelectionPageChangedEvent {
get { return m_OnSelectionPageChangedEvent; }
set { m_OnSelectionPageChangedEvent = value; }
}
scrollSnap.OnSelectionPageChangedEvent.AddListener(endScrollChangeEvent);
scrollSnap.OnSelectionPageChangedEvent.RemoveListener(endScrollChangeEvent);
'응용프로그램 > 유니티(Unity)' 카테고리의 다른 글
Unity2D_UI_Image(Health Point)기능 (0) | 2017.02.16 |
---|---|
Unity2D_UI_Button(다시시작,씬이동, 종료)기능 (3) | 2017.02.15 |
Unity2D_UI_Button(일시정지, 진행)기능구현 (0) | 2017.02.14 |
Unity2D_UI_Panel, Text, Button 만들기 (0) | 2017.02.14 |
Unity2D_UI_Canvas 설정하기 (0) | 2017.02.14 |