/// <summary> /// 从文件加载 AssetBundle 文件 /// </summary> /// <param name="assetBundleName"></param> /// <returns></returns> AssetBundle InternalLoadAssetBundleFromFile(string assetBundleName) { AssetBundle assetBundle = null; string assetBundleFullPath = GetAssetBundleFileFullPath(assetBundleName); byte[] fileContent = FileUtility.ReadFileBytes(assetBundleFullPath); if (fileContent != null) { if (AppDefine.IsEncrypted) { fileContent = Utility.AESDecrypt(fileContent, AppDefine.AssetSecretKey); } assetBundle = AssetBundle.LoadFromMemory(fileContent); } return(assetBundle); }
/// <summary> /// 加载资源记录文件 /// </summary> void LoadAssetRecord() { #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] assetBundleNameArray = UnityEditor.AssetDatabase.GetAllAssetBundleNames(); for (int index = 0; index < assetBundleNameArray.Length; index++) { string[] assetNameArray = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleNameArray[index]); for (int i = 0; i < assetNameArray.Length; i++) { string assetName = assetNameArray[i]; if ( // 预知件 assetName.EndsWith(".prefab") // 二进制文件和 Lua 文件 || assetName.EndsWith(".bytes") // 音效文件 || assetName.EndsWith(".wav") || assetName.EndsWith(".map") || assetName.EndsWith(".ogg") ) { string assetRecordKey = AssetRecordInfo.ToAssetRecordKey(assetNameArray[i]); if (m_AssetRecordDict.ContainsKey(assetRecordKey)) { Debug.LogErrorFormat("Some asset with the same assetrecordkey[{0}], please check and fix it! in path:\n{1}\n{2}", assetRecordKey, m_AssetRecordDict[assetRecordKey].RelativePath, assetNameArray[i]); } else { m_AssetRecordDict.Add(assetRecordKey, new AssetRecordInfo(assetRecordKey, assetBundleNameArray[index], assetNameArray[i])); } } } } } else #endif { byte[] contentBytes = FileUtility.ReadFileBytes(GetAssetBundleFileFullPath(AppDefine.AssetRecordsFileName)); if (AppDefine.IsEncrypted) { contentBytes = Utility.AESDecrypt(contentBytes, AppDefine.AssetSecretKey); } string fileContent = Utility.BytesToUTF8String(contentBytes); if (string.IsNullOrEmpty(fileContent)) { Debug.LogError("Load Asset Reocrds file error, please check and fix it!"); return; } string[] assetRecordInfoArray = fileContent.Split(new string[] { "#$" }, StringSplitOptions.RemoveEmptyEntries); for (int index = 0; index < assetRecordInfoArray.Length; index++) { string[] recordItems = assetRecordInfoArray[index].Split(new string[] { "#@" }, StringSplitOptions.None); if (recordItems.Length > 1) { string assetRecordKey = recordItems[0].Trim(); string assetBundleName = recordItems[1].Trim(); if (m_AssetRecordDict.ContainsKey(assetRecordKey)) { Debug.LogErrorFormat("Some asset with the same assetrecordkey[{0}], please check and fix it! in assetBundleName:\n{1}\n{2}", assetRecordKey, m_AssetRecordDict[assetRecordKey].AssetBundleName, assetBundleName); } else { m_AssetRecordDict.Add(assetRecordKey, new AssetRecordInfo(assetRecordKey, assetBundleName)); } } } } }