1.导入资源包
2.把NGUI面板制作成预设体,然后把预设体拖到Resources/UIPanel中(一定要放在Resources/UIPanel中,后面路径读取的时候就是这个路径)
3.为各自面板建立对应的脚本,然后再把脚本挂给对应的面板
4.为各个面板添加Canvas Group组件(每一个面板都要)
5.复制RegPanel中的脚本代码粘贴到你自己建立中脚本中
6.更改UIManager脚本(用UGUI的就不用改了)把Canvas改成UI Root
7.在UIPanelType.json与UIPanelType中添加自己的面板
,{"panelType": "RegPanel","path": "UIPanel/RegPanel"},{"panelType": "ResginPanel","path": "UIPanel/ResginPanel"},{"panelType": "LoginPPanel","path": "UIPanel/LoginPPanel"},{"panelType": "GamePanel","path": "UIPanel/GamePanel"}
///
/// 保存面板类型
///
public enum UIPanelType
{ItemMessagePanel, CharacterPanel,KnapsackPanel,MainMenuPanel,ShopPanel,SkillPanel,SystemPanel,TaskPanel,Panel,Panel2,RegPanel,LoginPanel,LoginPPanel,ResginPanel,GamePanel}
8.创建UI Root
9.建立Test脚本挂给UI Root
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
*文件描述:
*创始人:
*创建时间:
*修改时间:
*版本:1.0
*/
public class Test : MonoBehaviour {void Start () {MainMenuPanel mp = GetComponent<MainMenuPanel>();//获取组件mp.OnPushPanel("GamePanel");//克隆面板}void Update () {}
}
10.实现点击Start按钮跳转到ResginPanel面板
在GamePanel脚本中添加如下代码
UIButton btn;btn = this.gameObject.transform.GetChild(2).GetComponent<UIButton>();EventDelegate es = new EventDelegate(this, "Click");//点击事件btn.onClick.Add(es);void Click() {Transform parent = this.transform.parent;MainMenuPanel mp = parent.GetComponent<MainMenuPanel>();mp.OnPushPanel("ResginPanel");//跳转页面Destroy(this.gameObject);}
部分脚本
using UnityEngine;
using System.Collections;
using DG.Tweening;public class MainMenuPanel : BasePanel
{UIButton btn;void Start() { }public void OnPushPanel(string panelTypeString){UIPanelType panelType = (UIPanelType)System.Enum.Parse(typeof(UIPanelType), panelTypeString);UIManager.Instance.PushPanel(panelType);//克隆面板}
}