public bool LoadBundles(string[] nameLists, bool bUseCache = true) { if (m_preLoadList == null) { m_preLoadList = nameLists; m_bIsDone = LoadResultEnum.LOAD; StartCoroutine("DoLoadBundle", bUseCache); return(true); } return(false); }
void Awake() { Debug.Log("Application.persistentDataPath is " + Application.persistentDataPath); m_mBundle = new Dictionary <string, AssetBundle>(); m_mCacheID = new Dictionary <string, int>(); m_mCachePath = new Dictionary <string, string>(); m_mLocalLevel = new Dictionary <string, string>(); m_resourceList = new List <string>(); m_bIsDone = LoadResultEnum.LOAD; m_preLoadList = null; m_charLoadList = new List <string>(); m_bIsLoadingCharacter = false; m_CommonBundleReady = false; }
IEnumerator DoLoadBundle(bool bUseCache) { Debug.Log("Start Load Bundle..."); bool bSuccess = true; int c = 1; foreach (string bundName in m_preLoadList) { m_loadingPub.NotifyLoadingName(bundName); m_loadingPub.NotifyPhase(c++, m_preLoadList.Length); if (GameDefines.IsUseStream()) { string url = GameDefines.GetUrlBase() + GetCachePath(bundName) + bundName + ".assetbundle"; Debug.Log("url:" + url); WWW www = null; int cacheID = GetCacheID(bundName); if (cacheID >= 0 && bUseCache) { www = WWW.LoadFromCacheOrDownload(url, cacheID); } else { www = new WWW(url); } while (!www.isDone) { m_loadingPub.NotifyProgress(www.progress); yield return(0); } if (www.error != null) { m_loadingPub.NotifyProgress(1.0f); Debug.Log("Error: " + bundName + " " + www.error); bSuccess = false; break; } else { Debug.Log("OK: " + bundName + "" + www.assetBundle.ToString()); m_mBundle.Add(bundName, www.assetBundle); } } else { m_loadingPub.NotifyProgress(1.0f); Debug.Log("Downloading Local " + bundName.ToLower()); yield return(new WaitForSeconds(0.05f)); } } Debug.Log("work flow end"); m_preLoadList = null; if (bSuccess) { m_bIsDone = LoadResultEnum.SUCC; } else { m_bIsDone = LoadResultEnum.FAIL; } Debug.Log("Load Result is " + m_bIsDone); }
public LoadResultEnum Load(string path) { var info = new FileInfo(path); var lowerExtension = info.Extension.ToLower(); Stream stream = null; LoadResultEnum result = LoadResultEnum.OK; try { if (lowerExtension.StartsWith(".z")) { stream = new MemoryStream(); using (var fileStream = File.OpenRead(path)) { using (var gzip = new GZipStream(fileStream, CompressionMode.Decompress, false)) { gzip.CopyTo(stream); } stream.Position = 0; } } else { stream = File.OpenRead(path); } switch (info.Extension.ToLower()) { case ".sav": case ".zsav": BinParser.Instance.Load(stream); if (!EnshueBinCompatibility(stream)) { result = LoadResultEnum.NotCompatible; } break; case ".jsav": JsonParser.Instance.Load(stream); #if DEBUG JsonParser.Instance.TestReadWrite(path); #endif break; case ".zjsav": JsonParser.Instance.Load(stream); break; default: break; } } finally { if (stream != null) { stream.Close(); stream.Dispose(); stream = null; } } return(result); }