void Awake() { // 得到UI根节点对象 _goCanvasRoot = GameObject.FindGameObjectWithTag(UIFrameSysDefine.SYS_TAG_CANVAS); // UI脚本节点对象,并挂载本脚本实例 _traUiScriptsNode = UnityHelper.FindTheChildNode(_goCanvasRoot, UIFrameSysDefine.SYS_SCRIPTMANAGER_NODE); UnityHelper.AddChildNodeToParentNode(_traUiScriptsNode, transform); // 顶层面板 _goTopPanel = _goCanvasRoot; _goTopPanelIndex = _goTopPanel.transform.GetSiblingIndex(); // 遮罩面板 _goMaskPanel = UnityHelper.FindTheChildNode(_goCanvasRoot, UIFrameSysDefine.SYS_UIMASK_PANEL_NODE).gameObject; _goMaskPanel.SetActive(false); // UI摄像机 和 UI摄像机 “初始的层深” _uiCamera = UnityHelper.FindTheChildNode(_goCanvasRoot, UIFrameSysDefine.SYS_UICAMERA_NODE).GetComponent <Camera>(); if (_uiCamera != null) { //UI摄像机 “初始的层深” _originalUiCameraDepth = _uiCamera.depth; } else { Debug.Log(GetType() + "/Awake()/UIcamera is NULL"); } }
/// <summary> /// 注册下拉框事件 /// </summary> /// <param name="dropName">按钮名称</param> /// <param name="delHandle">委托事件</param> protected void RigisterDropDownObjectEvent(string dropName, UnityAction <int> delHandle) { Dropdown drop = UnityHelper.FindTheChildNode(this.gameObject, dropName).GetComponent <Dropdown>(); if (drop != null) { drop.onValueChanged.AddListener(delHandle); } }
/* 有需啊哟还可以自行添加 */ /// <summary> /// 注册按钮事件,简化了寻找路径 /// </summary> /// <param name="buttonName">按钮名称</param> /// <param name="delHandle">委托事件</param> protected void RigisterButtonObjectEvent(string buttonName, UnityAction delHandle) { Button btn = UnityHelper.FindTheChildNode(this.gameObject, buttonName).GetComponent <Button>(); if (btn != null) { btn.onClick.AddListener(delHandle); } }
// 初始化核心数据,加载"UI窗体路径"到集合中 public void Awake() { // 字段初始化 _dicAllUiForms = new Dictionary <string, BaseUIForm>(); _dicCurrentShowUiForms = new Dictionary <string, BaseUIForm>(); _dicFormsPaths = new Dictionary <string, string>(); _staCurrentUiForms = new Stack <BaseUIForm>(); // 初始化加载(根UI窗体)Canvas预设 GameObject _Canvas = InitRootCanvasLoading(); // 获取UI根节点 全屏节点 固定节点 弹出节点 _traCanvasTransform = _Canvas.transform; _traNormal = UnityHelper.FindTheChildNode(_Canvas, SysDefine.SYS_NORMAL_NODE); _traFixed = UnityHelper.FindTheChildNode(_Canvas, SysDefine.SYS_FIXED_NODE); _traPopUp = UnityHelper.FindTheChildNode(_Canvas, SysDefine.SYS_POPUP_NODE); _traUiScripts = UnityHelper.FindTheChildNode(_Canvas, SysDefine.SYS_SCRIPTMANAGER_NODE); // 将本脚本对象作为“根UI窗体”的子节点 gameObject.transform.SetParent(_traUiScripts, false); // “根UI窗体”在场景转换的时候,不允许销毁 DontDestroyOnLoad(_traCanvasTransform); // 初始化“UI窗体预设”路径数据 InitUIFormPathData(SysDefine.SYS_PATH_UIFORMS_CONFIG_INFO); }