Unity3d NGUI 按钮委托跳转场景
_LoadLevelBt.cs
publicclass _LoadLevelBt : MonoBehaviour {
public delegatevoid ButtonLoading(string loadingLevel);
public static event ButtonLoading buttonLoading;
public GameObject[] loadLevelBtS;
public string[] loadLevelNameS;
void Start(){
addListener();
}
void addListener(){
foreach(GameObject go in loadLevelBtS){
UIEventListener.Get(go).onPress+=loadList;
}
}
void loadList(GameObject go,bool canwith){
int listener=0;
if(!canwith){
if(listener==0){
listener=1;
int index=int.Parse(go.name.Split('_')[1]);
waitButtonLoading(loadLevelNameS[index]);
}
}
}
public static void waitButtonLoading(string loadingLevel){
if(buttonLoading!=null) buttonLoading(loadingLevel);
}
}
waitButtonLoading.cs 为代理类;
public class _ButtonLoadingList : MonoBehaviour {
float waitButtonLoadTime=1f;
void OnEnable(){
_LoadLevelBt.buttonLoading += buttonLoading;
}
void OnDisable(){
_LoadLevelBt.buttonLoading -= buttonLoading;
}
public void buttonLoading(string loadingName){
hideCollider();
StartCoroutine(waitLoading(loadingName));
}
IEnumerator waitLoading(string loadingName){
yieldreturnnewWaitForSeconds(waitButtonLoadTime);
Application.LoadLevel(loadingName);
}
void hideCollider(){
Collider[] cols=Physics.OverlapSphere(Vector3.zero,1000f);
foreach(Collider col in cols){
col.enabled=false;
}
}
}