void LoadUIObj(string name, Action <GameObject> onLoaded) { UGUIAssetItem asset = new UGUIAssetItem(UGUIAssetItem.AssetType.Prefab, "pkg_ui_message", name); asset.Load(() => { var obj = asset.AddToPopCanvas(); obj.SetActive(true); onLoaded(obj); }); }
// ReSharper disable Unity.PerformanceAnalysis /// <summary> /// 准备显示的UI预设 加载 /// </summary> IEnumerator PrepareUIAsync(UIType packageID, UIType uiID) { if (uiID != UIType.None) { UIWndBase uiWnd = GetUIWnd(uiID); if (uiWnd == null && !IsUICaching(uiID)) { mCurCacheUIIDList.Add(uiID); // load ui from bundle UGUIAssetItem asset = new UGUIAssetItem(UGUIAssetItem.AssetType.Prefab, packageID, uiID); mAssetList.Add(asset); bool loaded = false; asset.Load(() => { asset.AddToCanvas(); loaded = true; }); while (!loaded) { yield return(null); } // 加载UI的Awake中调用了RegisterUI(UIWndBase uiWnd)方法。已加入map uiWnd = GetUIWnd(uiID); if (uiWnd != null) { uiWnd.SetActiveByRoot(true); } else { Debug.LogError($"prepare ui failed: {uiID}"); } } } }