public UiBase OpenUi(UiType uiType, ulong sn) { UiComplexType key = new UiComplexType(uiType, sn); if (_uiInses.ContainsKey(key)) { _uiInses[key].Show(); return(_uiInses[key]); } if (_addObjs.ContainsKey(key)) { return(_addObjs[key]); } UiBase uiIns = UiFactory.GetInstance().Create(uiType, sn); if (uiIns == null) { GameLogger.GetInstance().Output("!!!! OpenUi Error. Create ui == null. uiType:" + uiType); return(null); } _addObjs.Add(uiIns.GetUiComplexType(), uiIns); return(uiIns); }
public void CloseUi(UiType uiType, ulong sn) { UiComplexType key = new UiComplexType(uiType, sn); // 处理删除的UI if (!_uiInses.ContainsKey(key)) { return; } GameLogger.GetInstance().Trace("-- ui remove:" + _uiInses[key].GetType()); _removeObjs.Add(key); }
private void AsyncLoadCallBack(object context, AssetBundle ab) { UiComplexType key = (UiComplexType)context; UiBase uiObj = null; if (_uiInses.ContainsKey(key)) { uiObj = _uiInses[key]; } if (uiObj == null && _addObjs.ContainsKey(key)) { uiObj = _addObjs[key]; } // 回调的时候,界面已经没有了 if (uiObj == null) { return; } Canvas canvas = FindObjectOfType <Canvas>(); if (canvas == null) { string canvasUrl = _urlCanvas; //if (key.UiType == UiType.LoadingBar || key.UiType == UiType.Login) //{ // // 登录和加载界面的背影略有不同 // canvasUrl = _urlCanvasBg; //} AssetBundle abBg = AssetBundleMgr.GetInstance().GetAb(canvasUrl); if (abBg == null) { GameLogger.GetInstance().Debug($"!!!!!GetAb failed. {canvasUrl}"); return; } GameObject canvasObj = MonoBehaviour.Instantiate(abBg.LoadAsset(abBg.GetAllAssetNames()[0])) as GameObject; if (canvasObj == null) { return; } canvasObj.transform.Rotate(0, 0, 0); canvas = canvasObj.GetComponent <Canvas>(); } // 对像挂在 canvas 之下 GameObject obj = MonoBehaviour.Instantiate(ab.LoadAsset(ab.GetAllAssetNames()[0]), canvas.transform) as GameObject; if (obj == null) { return; } obj.transform.Rotate(0, 0, 0); //obj.transform.localScale = new Vector3( 1, 1, 1 ); uiObj.AttachGameObject(obj); }