static public int IsDone(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif AssetBundleLoadOperation self = (AssetBundleLoadOperation)checkSelf(l); var ret = self.IsDone(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
/// <summary> /// 异步加载场景 /// </summary> private async Task _LoadScene(string sceneAssetBundle, string levelName, bool isAdditive, Action <float> cbProgress) { float startTime = Time.realtimeSinceStartup; AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive); if (request != null) { while (request.Progress() < 1f) { await waitFrame; cbProgress?.Invoke(request.Progress()); if (request.IsDone()) { break; } } cbProgress?.Invoke(1f); } float elapsedTime = Time.realtimeSinceStartup - startTime; Utils.ResetShader(null); Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds"); Debug.Log("当前场景 " + UnityEngine.SceneManagement.SceneManager.GetActiveScene().name); }
public IEnumerator LoadLevelAsync(string bundleName, string sceneName, bool isAdditive) { AssetBundleLoadOperation async = AssetBundleManager.LoadLevelAsync(bundleName, sceneName, isAdditive); while (!async.IsDone()) { yield return(null); } yield break; }
/* * summary * 씬 로드시 로드되어있는 씬일 경우 ActiveScene으로 설정 * 씬 로드가 안되어있을 경우 씬의 전환을 이룸. * summary */ public IEnumerator LoadScene(string sceneName, bool isLoading = true, bool isImediately = true, bool isAdditive = true) { Debug.LogFormat("LoadScene {0}", sceneName); // Scene in sceneNameList if (_sceneNameList.Contains(sceneName)) { foreach (var scene in _sceneNameList) { if (scene == sceneName) { Debug.Log("ActiveScene Change : " + sceneName); SceneManager.SetActiveScene(SceneManager.GetSceneByName(sceneName)); yield break; } } } else { yield return(new WaitForSeconds(0.1f)); //LoadLevelAsync함수를 통해 에셋을 로드대기 시키고 AssetBundleLoadOperation생성후 반환 AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(AssetManager.Instance._assetBundleKeys[ASSET_TYPE.GAME_SCENES], sceneName, isAdditive); if (request == null) { yield break; } if (isLoading) { LoadingBarScript loading = GameObject.Find("Script").GetComponent <LoadingBarScript>(); StartCoroutine(loading.SetLoadingProgressBar(request)); } while (!request.IsDone()) { yield return(null); } if (isImediately) { SceneManager.SetActiveScene(SceneManager.GetSceneByName(sceneName)); Debug.Log("씬 활성화 : " + SceneManager.GetActiveScene().name); } _sceneNameList.Add(sceneName); } }
public IEnumerator LoadSceneAsync(string sceneName, string sceneAssetBundle, bool isAdditive = false, Action <float> progressListener = null) { AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, sceneName, isAdditive); if (request == null) { yield break; } if (progressListener == null) { // 方案一 yield return(StartCoroutine(request)); } else { // 方案二 TODO 可能有BUG { int maxTry = 0; while (request.Process() < 0.9f) { if (request.Process() < 0.001f && maxTry++ > 100) { Debug.LogError("网络无法获得资源:" + sceneAssetBundle + " " + sceneName); } // TODO 进度条处理 Debug.Log("加载:" + request.Process() * 100 + "/100"); yield return(new WaitForEndOfFrame()); } while (!request.IsDone()) { Debug.Log("加载:" + request.Process() * 100 + "/100"); yield return(new WaitForEndOfFrame()); } Debug.Log("加载:100/100"); } } }
protected IEnumerator InitializeLevelAsync(string levelName, bool isAdditive) { // This is simply to get the elapsed time for this phase of AssetLoading. float startTime = Time.realtimeSinceStartup; // Load level from assetBundle. AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive); if (request == null) { yield break; } // 方案一 // yield return StartCoroutine(request); // 方案二 { while (request.Process() < 0.9f) { // TODO 进度条处理 Debug.Log("加载:" + request.Process() * 100 + "/100"); yield return(new WaitForEndOfFrame()); } while (!request.IsDone()) { Debug.Log("加载:" + request.Process() * 100 + "/100"); yield return(new WaitForEndOfFrame()); } Debug.Log("加载:100/100"); } // Calculate and display the elapsed time. float elapsedTime = Time.realtimeSinceStartup - startTime; Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds"); }
public override bool IsDone() { return(loadOperation != null && loadOperation.IsDone()); }
IEnumerator Login(string userID, string pletformID = "", LoginType loginType = LoginType.GuestLogin) { Debug.Log("로그인 시작"); loginPanel.SetActive(false); //로그인 시 유저 데이터 구성부분 WWWForm form = new WWWForm(); form.AddField("userID", userID, System.Text.Encoding.UTF8); //테스트 아이디로 로그인한다. string googleID = ""; if (PlayerPrefs.HasKey("google")) { googleID = PlayerPrefs.GetString("google"); } else { if (loginType == LoginType.GoogleLogin) { googleID = pletformID; } } string facebookID = ""; if (PlayerPrefs.HasKey("facebook")) { facebookID = PlayerPrefs.GetString("facebook"); } else { if (loginType == LoginType.FacebookLogin) { facebookID = pletformID; } } tipMessageText.text = "로그인 정보를 내려받는 중.."; form.AddField("google", googleID, System.Text.Encoding.UTF8); form.AddField("facebook", facebookID, System.Text.Encoding.UTF8); form.AddField("deviceModel", SystemInfo.deviceModel); form.AddField("deviceID", SystemInfo.deviceUniqueIdentifier); form.AddField("type", (int)loginType); string result = ""; string php = "Login.php"; yield return(StartCoroutine(WebServerConnectManager.Instance.WWWCoroutine(php, form, x => result = x))); JsonData jsonData = ParseCheckDodge(result); PlayerPrefs.SetString("userID", JsonParser.ToString(jsonData["id"].ToString())); if (loginType == LoginType.GoogleLogin) { PlayerPrefs.SetString("google", JsonParser.ToString(jsonData["google"].ToString())); } if (loginType == LoginType.FacebookLogin) { PlayerPrefs.SetString("facebook", JsonParser.ToString(jsonData["facebook"].ToString())); } // 아틀라스 캐싱 string atlasName = "Atlas_Product"; AssetBundleLoadAssetOperation r = AssetBundleManager.LoadAssetAsync("sprite/product", atlasName, typeof(UnityEngine.U2D.SpriteAtlas)); yield return(StartCoroutine(r)); UnityEngine.U2D.SpriteAtlas atlas = r.GetAsset <UnityEngine.U2D.SpriteAtlas>(); if (atlas != null) { if (!AssetLoader.cachedAtlasDic.ContainsKey(atlasName)) { AssetLoader.cachedAtlasDic.Add(atlasName, atlas); } } string atlasName2 = "Atlas_Material"; AssetBundleLoadAssetOperation r2 = AssetBundleManager.LoadAssetAsync("sprite/material", atlasName2, typeof(UnityEngine.U2D.SpriteAtlas)); yield return(StartCoroutine(r2)); UnityEngine.U2D.SpriteAtlas atlas2 = r2.GetAsset <UnityEngine.U2D.SpriteAtlas>(); if (atlas2 != null) { if (!AssetLoader.cachedAtlasDic.ContainsKey(atlasName2)) { AssetLoader.cachedAtlasDic.Add(atlasName2, atlas2); } } //// 게임 데이타 초기화 끝날 때 까지 대기 //while (!GameDataManager.isInitialized) // yield return null; if (User.Instance) { User.Instance.InitUserData(jsonData); } Debug.Log("유저 데이터 초기화"); while (!User.isInitialized) { yield return(null); } Debug.Log("완료"); // 유저 데이터 초기화 시작 StartCoroutine(UserDataManager.Instance.Init()); // 유저 데이터 초기화 완료 했는가 체크 while (!UserDataManager.isInitialized) { yield return(null); } tipMessageText.text = "왕국으로 진입중.."; Debug.Log("Login UserID : " + JsonParser.ToString(jsonData["id"])); //enterButton.SetActive(true); //if (onFadeOutStart != null) // onFadeOutStart(); ////페이드아웃 기다리는 시간 //yield return new WaitForSeconds(1.5f); yield return(StartCoroutine(LoadingManager.FadeOutScreen())); string nextSceneBundleName = "scene/lobby"; string nextSceneName = "Lobby"; AssetBundleLoadOperation operation = AssetBundleManager.LoadLevelAsync(nextSceneBundleName, nextSceneName, true); //// 몬스터 풀 초기화 끝났는가 체크 //while (!MonsterPool.Instance) // yield return null; //while (!MonsterPool.Instance.isInitialization) // yield return null; //while (!Battle.Instance || !Battle.Instance.isInitialized) // yield return null; while (!operation.IsDone()) { yield return(null); } versionText.gameObject.SetActive(false); messagePanel.SetActive(false); StopCoroutine(messageCoroutine()); //while (!UILoginManager.isFinished) // yield return null; Scene lobby = SceneManager.GetSceneByName("Lobby"); Scene login = SceneManager.GetSceneByName("Login"); Scene preLogin = SceneManager.GetSceneByName("PreLogin"); SceneManager.SetActiveScene(lobby); SceneManager.UnloadSceneAsync(login); SceneManager.UnloadSceneAsync(preLogin); }