public static SceneProfile[] LoadAll() { SceneProfile[] profiles = null; try { // Found all SceneProfile json files string filePath = AssetManager.assetPath + PATH; string[] fileNames = Directory.GetFiles(filePath, PATTERN); if (fileNames != null && fileNames.Length > 0) { // Deserialize json files profiles = new SceneProfile[fileNames.Length]; for (int i = 0; i < profiles.Length; i++) { string json = File.ReadAllText(fileNames[i]); profiles[i] = JsonUtility.FromJson <SceneProfile>(json); } } } catch (System.Exception e) { profiles = null; Debug.LogError("Load scene profiles failed : " + e.Message); } return(profiles); }
void LoadLocalSceneProfiles() { state = State.LoadingSceneProfiles; var profiles = SceneProfile.LoadAll(); if (profiles != null) { // Add all profiles into lookup foreach (var profile in profiles) { mLocalProfiles.Add(profile.url, profile); } } }
IEnumerator LoadScene(string url, OnSceneLoaded onSceneLoaded) { state = State.LoadingScene; // Get scene profile SceneProfile sceneProfile = null; if (mLocalProfiles.ContainsKey(url)) { sceneProfile = mLocalProfiles[url]; } else { yield return(StartCoroutine(DownloadSceneProfile(url))); sceneProfile = SceneProfile.Load(url); } // Get download list state = State.DownloadingAssets; List <string> downloadList = new List <string>(); foreach (var header in sceneProfile.assetHeaders) { if (!AssetManager.instance.ContainsAsset(header.url, header.version)) { if (!downloadList.Contains(header.url)) { downloadList.Add(header.url); } } } // Download all assets foreach (var assetUrl in downloadList) { yield return(StartCoroutine(AssetManager.instance.DownloadAsset(assetUrl, DownloadCallback))); } // Load all local assets state = State.LoadingLocalAssets; foreach (var header in sceneProfile.assetHeaders) { if (!downloadList.Contains(header.url) && !mSceneAssets.ContainsKey(header.url)) { yield return(StartCoroutine(AssetManager.instance.LoadAsset(header.url, LoadCallback))); } } // Build hierarchy state = State.BuildingHierarchy; foreach (var keyValue in mSceneAssets) { Instantiate(keyValue.Value.bundle.GetMainAsset()); yield return(null); } AssetManager.instance.Cleanup(); if (onSceneLoaded != null) { onSceneLoaded(null); } }