unity NGUI 创建Dlg流程

1.创建Atlas
NGUI->Atlas Maker

2.创建Dlg的prefabs
假设取名为AAADlg,添加脚本,假设为UIAAADlg.cs  类继承NvUIDialogBase,脚本内处理该Dlg的下属控件的事件
设置Layer为UI摄像机的层

AAADlg添加子Obj,取名为Anchor,添加脚本Component->NGUI->UI->Anchor

Anchor添加子Obj,取名为Panel,添加脚本Component->NGUI->UI->Panel

Panel下可添加控件,举例添加一个button,bttton添加脚本Component->NGUI->Interaction->ButtonMessage
target设置为AAADlg,functionName假设为TestBtn,在UIAAADlg.cs中添加函数private void TestBtn()

2.创建一个新场景
假设命名为AAARoot,添加脚本NvUIDialogManager和NvUIDialogStarter
修改mContextTable下Size为1,dialogName为AAADlg,dialogPrefab为第二步创建的AAADlg

3.动态创建Dlg
在主场景的GameController中添加代码
private bool AAA_m_IsLoadUISceneOver = false;
public NvUIDialogManager m_DialogMgr = null;
public UIAAADlg AAA_m_TestDlg = null;
IEnumerator OnInit()
{
AAA_LoadUIScene();
        while (!AAA_m_IsLoadUISceneOver)
        {
            yield return new WaitForSeconds(0.1f);
        }
        GameObject AAA_obj = GameObject.Find("AAARoot");
        m_DialogMgr = AAA_obj.GetComponent(typeof(NvUIDialogManager)) as NvUIDialogManager;
        AAA_CreateUI();
}
private void AAA_CreateUI()
{
        AAA_m_TestDlg = m_DialogMgr.OpenDialog("AAADlg") as UIAAADlg;
}
protected void AAA_LoadUIScene()
{
        SceneManager mgr = Singlton.getInstance("SceneManager") as SceneManager;
        mgr.AddScene("AAA", AAA_onLoadedScene);
}
void AAA_onLoadedScene(string str)
{
       Debug.Log("Finish Load Scene: " + str);
       AAA_m_IsLoadUISceneOver = true;
}

4.File->Buildsetting中添加AAA场景

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页