C# 전송 방법 function/테이프 매개 변수 전송 방법 function
1291 단어 스크립트 관련
using UnityEngine;
using System.Collections;
namespace DelegateTools
{
public delegate void VoidDelegate();//
public delegate void IdDelegate(long id);// (long id)
public delegate void StringDelegate(string text);// (string id)
public delegate void IntDelegate(int param, string owner);// (int param, string owner)
}
사용 방법 ()
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DelegateTools;
public class UITestParentItem : MonoBehaviour {
void SetValue()
{
UITestItem com = gameObject.GetComponent();
com.SetValue("test",SetCallBack); // callback
}
void SetCallBack(int id)
{
Debug.Log(id); // id = 0
}
}
public class UITestItem : MonoBehaviour {
private DelegateTools.IdDelegate mFunc = null;
public UILabel _Lable ; // lable
int tId = 0;
//
void Awake()
{
UIEventListener button = gameObject.GetComponent();
UITools.AddOnclick(button,OnButtonClick);
}
// - callback
public void OnButtonClick (GameObject go)
{
if(mFunc != null)
mFunc(tId);
}
// - callback
public void SetValue (string name,DelegateTools.IdDelegate func)
{
_Lable.text = name;
mFunc = func;
}
}