static int New(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); CFramework.LuaComponent obj = (CFramework.LuaComponent)ToLua.CheckObject <CFramework.LuaComponent>(L, 1); LuaTable arg0 = ToLua.CheckLuaTable(L, 2); CFramework.BaseView arg1 = (CFramework.BaseView)ToLua.CheckObject <CFramework.BaseView>(L, 3); obj.New(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 启动loading场景 /// </summary> /// <returns></returns> private IEnumerator StartLoadingScene(string sceneId, string loadingWindowId, LuaTable loadingWindowClass) { Scene loadingScene = SceneManager.GetSceneByName("LoadingScene"); yield return(new WaitUntil(delegate() { return loadingScene.isLoaded; })); Debug.Log("LoadingScene complete"); string assetName = ("prefabs/" + loadingWindowId + ".unity3d").ToLower(); ResourceManager.Instance.LoadPrefabAsync("LoadingScene", assetName, delegate(AssetBundle asset) { //先显示加载窗口 GameObject loadingWindowAsset = ResourceManager.Instance.GetAsset(asset, loadingWindowId).gameObject; loadingWindowAsset.AddComponent <LuaComponent>(); GameObject loadingWindow = Instantiate(loadingWindowAsset, GameObject.Find("WindowLayer").transform); LuaComponent luaComponent = loadingWindow.GetComponent <LuaComponent>(); luaComponent.New(loadingWindowClass, new BaseWindow(loadingWindowId, null, false, loadingWindow.transform)); loadingWindow.name = loadingWindowId; //启动预加载资源加载 ResourceManager.Instance.LoadPrefabAsync(_id, _preloadList, delegate(List <AssetBundle> assetBundle) { _preloadIsEnd = true; //启动场景加载 _prog = SceneManager.LoadSceneAsync(sceneId); _prog.allowSceneActivation = false; //如果加载完成,也不进入场景 }); //启动加载进度条 StartCoroutine(LoadingScene(loadingWindowClass)); }); }
/// <summary> /// 加载场景 /// </summary> /// <param name="loadingWindowClass"></param> /// <returns></returns> private IEnumerator LoadingScene(LuaTable loadingWindowClass) { int showProgress = 80; while (showProgress < 100) { if (showProgress < 30) { showProgress++; if (_progressCallback != null) { _progressCallback(showProgress); loadingWindowClass.Call("OnProgress", loadingWindowClass, showProgress); yield return(new WaitForEndOfFrame()); //等待一帧 } } else if (showProgress < 90) { yield return(new WaitUntil(delegate() { return _preloadIsEnd; })); showProgress++; if (_progressCallback != null) { _progressCallback(showProgress); loadingWindowClass.Call("OnProgress", loadingWindowClass, showProgress); yield return(new WaitForEndOfFrame()); //等待一帧 } } else { yield return(new WaitUntil(delegate() { return _prog.progress >= 0.9f; })); showProgress++; if (_progressCallback != null) { _progressCallback(showProgress); loadingWindowClass.Call("OnProgress", loadingWindowClass, showProgress); yield return(new WaitForEndOfFrame()); //等待一帧 } } } //-----------------------------预加载资源加载完成,进入场景------------------------------ _prog.allowSceneActivation = true; //如果加载完成,可以进入场景 Scene scene = SceneManager.GetSceneByName(_id); yield return(new WaitUntil(delegate() { return scene.isLoaded; })); DebugManager.Log("enter scene:" + scene.name); GameObject[] objs = scene.GetRootGameObjects(); foreach (GameObject go in objs) { DebugManager.Log("go.name:" + go.name); if (go.name.Equals("Canvas")) { _loadBaseScene = new BaseScene(_id, _preloadList, _completeCallback, _progressCallback, _isCache, go.transform); LuaComponent luaComponent = go.AddComponent <LuaComponent>(); luaComponent.New(_luaSceneClass, _loadBaseScene); _completeCallback(_loadBaseScene); this.CurrScene = _loadBaseScene; _loadBaseScene = null; _id = null; break; } } }