功能需求:點擊退出按鈕,彈出“退出”UI,詢問玩家是否退出游戲;
退出按鈕
退出UI:
publicclass GameQuit : MonoBehaviour {
// 取消按鈕
public GameObject closeBt;
// 退出UI
public GameObject goUI;
// 退出按鈕
public GameObject openBt;
//確定退出游戲按鈕
public GameObject quitBt;
void Start () {
NGUIAddListener();
}
void NGUIAddListener(){
if(openBt) UIEventListener.Get(openBt).onPress += openMethod;
if(quitBt) UIEventListener.Get(quitBt).onPress += quitMethod;
if(closeBt) UIEventListener.Get(closeBt).onPress += clooseMethod;
}
// /確定退出游戲
void quitMethod(GameObject go, bool istrue) {
if (istrue)
return;
Application.Quit();
}
//點擊退出按鈕,彈出退出UI
void openMethod(GameObject go, bool istrue) {
if (istrue)
return;
openCloseQuitUI(true);
}
//取消游戲退出,關閉彈出UI
void clooseMethod(GameObject go, bool istrue) {
if (istrue)
return;
openCloseQuitUI(false);
}
void openCloseQuitUI( bool isbool){
if(goUI && goUI.active!=isbool) goUI.SetActiveRecursively(isbool);
}
}