public static UIBase Produce(UIKey InUIKey, Transform InParent, bool InIsStayInMemory = true) { if (_uiBasePools.TryGetValue(InUIKey, out var bindBase)) { if (null != bindBase) { bindBase.Trans.SetAsLastSibling(); return(bindBase); } } UIConfigTable configTable = GetConfigTable((int)InUIKey); if (null == configTable) { Debug.LogError($"Can not find UI Config table named '{InUIKey}'."); return(null); } GameObject prefab = Object.Instantiate(LoadUIPrefab(configTable.Path)); if (null == prefab) { Debug.LogError($"No resource named '{InUIKey}' was found under path {configTable.Path}."); return(null); } Transform trans = prefab.transform; trans.SetParent(InParent); trans.localPosition = Vector3.zero; trans.rotation = Quaternion.identity; trans.localScale = Vector3.one; trans.SetAsLastSibling(); bindBase = prefab.GetComponent <UIBase>(); if (null == bindBase) { Debug.LogError($"Unbound 'UIBase' script on this resource could not be loaded."); return(null); } if (InIsStayInMemory) { _uiBasePools.Add(InUIKey, bindBase); } bindBase.Handle.SelfLoaded(InUIKey); return(bindBase); }
/// <summary> /// CS脚本显示UI /// </summary> public void ShowCSUI(uint id, Action <GameObject> callback) { if (callback != null) { _Callback[id] = callback; } //看此UI是否已加载 if (_AllUI.ContainsKey(id)) { LoggerHelper.Debug("一个UI显示出来了: " + _AllUI[id].ConfigTable.Name); //已加载,开始显示 MyShowUI(id); var _obj = _AllUI[id].MyCanvas.gameObject; //显示完成后,回调 Action <GameObject> _callback; _Callback.TryGetValue(id, out _callback); if (_callback != null) { _Callback.Remove(id); _callback.Invoke(_obj); } //发送MVC消息 Facade.Instance.SendNotification(string.Concat(_obj.name, MVCNameConst.UI_UIShow)); } else { //未加载,开始加载 if (_UIConfig != null) { UIConfigTable _table = _UIConfig.GetData(id); if (_table != null) { PoolTool.GetGameObject(_table.Name, _table.AssetName, LoadUIBack, _table, EPoolAddType.No); } else { Debug.Log("在UIConfigTable中,不存在此ID:" + id); } } else { Debug.Log("UI配置表未加载!"); } } }
//-----------------内部方法------------------ #region 内部方法 /// <summary> /// UI加载成功后,会直接调用对应UI的创建成功方法 /// </summary> void LoadUIBack(PoolLoadData _data) { //将加载完的UI,放在临时存储中 UIConfigTable tData = _data.data as UIConfigTable; UIToolData tToolData = new UIToolData(tData.Id, _data.transform, tData); tToolData.MyCanvas.renderMode = RenderMode.ScreenSpaceCamera; tToolData.MyCanvas.worldCamera = UICamera; //设置父物体 _AllUI.Add(tToolData.Id, tToolData); SetUIParent(tToolData.Id); //显示UI MyShowUI(tToolData.Id); //创建成功后,将obj传过去 if (_Callback.ContainsKey(tData.Id)) { _Callback[tData.Id].Invoke(_data.transform.gameObject); _Callback.Remove(tData.Id); } //发送MVC消息 Facade.Instance.SendNotification(string.Concat(_data.transform.gameObject.name, MVCNameConst.UI_UIShow)); }
public UIToolData BgLater; //链表,下一个显示的遮罩UI public UIToolData(uint id, Transform obj, UIConfigTable configTable) { Id = id; MyCanvas = obj.GetComponent <Canvas>(); ConfigTable = configTable; }