private void Start() { AssetBundle abConfig = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/abconfig"); TextAsset textAsset = abConfig.LoadAsset <TextAsset>("AssetBundleConfig"); MemoryStream ms = new MemoryStream(textAsset.bytes); BinaryFormatter bf = new BinaryFormatter(); AssetBundleConfig config = (AssetBundleConfig)bf.Deserialize(ms); ms.Close(); string path = "Assets/GameData/Prefabs/Attack.prefab"; uint crc = CRC32.GetCRC32(path); ABBase abBase = null; for (int i = 0; i < config.ABList.Count; i++) { if (config.ABList[i].Crc == crc) { abBase = config.ABList[i]; } } for (int i = 0; i < abBase.ABDependce.Count; i++) // 加载依赖项 { AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + abBase.ABDependce[i]); } AssetBundle ab = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + abBase.ABName); // 加载 ab GameObject go = GameObject.Instantiate(ab.LoadAsset <GameObject>(abBase.AssetName)); // 实例化资源 }
private void TestLoadAB() { // AssetBundle configAB = AssetBundle.LoadFromFile(string.Format("{0}/RealFram/Data/ABData/AssetBundleConfig", Application.dataPath)); // TextAsset textAsset = configAB.LoadAsset<TextAsset>("AssetBundleConfig"); TextAsset textAsset = Resources.Load <TextAsset>("AssetBundleConfig"); AssetBundleConfig config = null; using (MemoryStream ms = new MemoryStream(textAsset.bytes)) { BinaryFormatter bf = new BinaryFormatter(); config = bf.Deserialize(ms) as AssetBundleConfig; } string path = "Assets/RealFram/ABTest/Cube.prefab"; uint crc = Crc32.GetCrc32(path); ABBase abBase = null; for (int i = 0; i < config.ABList.Count; i++) { if (config.ABList[i].Crc == crc) { abBase = config.ABList[i]; } } for (int i = 0; i < abBase.ABDependce.Count; i++) { AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + abBase.ABDependce[i]); } AssetBundle assetBundle = AssetBundle.LoadFromFile(Application.dataPath + "/" + "Resources/" + abBase.ABName); GameObject obj = GameObject.Instantiate(assetBundle.LoadAsset <GameObject>(abBase.AssetName)); GameObject obj2 = GameObject.Instantiate(assetBundle.LoadAsset <GameObject>("cylinder")); }
void TestLoad() { AssetBundle assetBundleconfig = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/assetbundleconfig"); TextAsset textAsset = assetBundleconfig.LoadAsset <TextAsset>("AssetBundleConfig"); MemoryStream stream = new MemoryStream(textAsset.bytes); BinaryFormatter bf = new BinaryFormatter(); AssetBundleConfig testserilize = (AssetBundleConfig)bf.Deserialize(stream); stream.Close(); string path = "Assets/Prefabs/Attack.prefab"; string crc = CRC32.GetCRC32(path).ToString(); ABBase abbase = null; for (int i = 0; i < testserilize.ABList.Count; i++) { if (testserilize.ABList[i].Crc == crc) { abbase = testserilize.ABList[i]; } } for (int i = 0; i < abbase.ABDependce.Count; i++) { AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + abbase.ABDependce[i]); } AssetBundle assetbundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + abbase.ABName); GameObject obj = GameObject.Instantiate(assetbundle.LoadAsset <GameObject>(abbase.AssetName)); }
public bool LoadAssetBundleConfig() { string configPath = Application.streamingAssetsPath + "/assetbundleconfig"; AssetBundle configAB = AssetBundle.LoadFromFile(configPath); TextAsset textAsset = configAB.LoadAsset <TextAsset>("assetbundleconfig"); if (textAsset == null) { Debug.Log("AssetBundleConfig is not exist."); return(false); } MemoryStream stream = new MemoryStream(textAsset.bytes); BinaryFormatter bf = new BinaryFormatter(); AssetBundleConfig config = (AssetBundleConfig)bf.Deserialize(stream); stream.Close(); for (int i = 0; i < config.ABList.Count; i++) { ABBase abBase = config.ABList[i]; ResourceItem item = new ResourceItem(); item.m_CRC = abBase.Crc; item.m_AssetName = abBase.AssetName; item.m_ABName = abBase.ABName; item.m_DependAssetBundle = abBase.ABDependce; if (m_ResourceItemDic.ContainsKey(item.m_CRC)) { Debug.Log("重复的CRC:" + item.m_AssetName + " ab包名:" + item.m_ABName); } else { m_ResourceItemDic.Add(item.m_CRC, item); } } return(true); }
public static void LoadPrefab(string path) { AssetBundle ab = AssetBundle.LoadFromFile(AssetBundleManager.BundleTargetPath + AssetBundleManager.m_ABConfigABName); TextAsset ta = ab.LoadAsset <TextAsset>("AssetBundleConfig"); MemoryStream ms = new MemoryStream(ta.bytes); BinaryFormatter bf = new BinaryFormatter(); AssetBundleConfig ab_config = (AssetBundleConfig)bf.Deserialize(ms); ms.Close(); uint crc = Crc32.GetCrc32(path); AssetBundleBase ab_base = null; for (int i = 0; i < ab_config.ABList.Count; i++) { if (crc == ab_config.ABList[i].Crc) { ab_base = ab_config.ABList[i]; break; } } if (ab_base == null) { Debug.LogError("LoadAssetManager.LoadPrefab:预制不存在,path:" + path); return; } for (int i = 0; i < ab_base.ABDependce.Count; i++) { AssetBundle.LoadFromFile(AssetBundleManager.BundleTargetPath + "/" + ab_base.ABDependce[i]); } AssetBundle asset_bundle = AssetBundle.LoadFromFile(AssetBundleManager.BundleTargetPath + "/" + ab_base.ABName); GameObject.Instantiate(asset_bundle.LoadAsset <GameObject>(ab_base.ABName)); }
void InitAbStartup() { AssetBundleConfig.InitConfig(true); AssetBundleUtil.SetExternAssetBundleDir(GetAbDir()); #if UNITY_IPHONE XFileUtil.SetFolderNoSaveImp((folderPath) => { UnityEngine.iOS.Device.SetNoBackupFlag(folderPath); }); #endif AssetBundleUtil.m_abHashMd5 = false; GameCoreConfig.UseAssetBundle = true; #if UNITY_EDITOR AssetBundleUtil.traceAssetBundleDebug = false; #endif InitFileProtocol(); BLogger.Info("******dataPath: {0}", Application.dataPath); BLogger.Info("******streamingAssetsPath:{0}", Application.streamingAssetsPath); BLogger.Info("******temporaryCachePath:{0}", Application.temporaryCachePath); BLogger.Info("******persistentDataPath:{0}", Application.persistentDataPath); BLogger.Info("******asset bundle dir: {0}", GetAbDir()); BLogger.Info("******storage free space:{0}", ReleaseUtil.GetStorageFreeSpace()); }
void TestLoadAB() { AssetBundle asset = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/AssetBundleConfig"); TextAsset t = asset.LoadAsset <TextAsset>("AssetBundleConfig"); MemoryStream stream = new MemoryStream(t.bytes); BinaryFormatter bf = new BinaryFormatter(); AssetBundleConfig abc = bf.Deserialize(stream) as AssetBundleConfig; stream.Close(); string path = "Assets/GameData/Prefabs/Attack.prefab"; uint crc = CRC32.GetCRC32(path); ABBase abBase = null; for (int i = 0; i < abc.ABList.Count; i++) { if (abc.ABList[i].Crc == crc) { abBase = abc.ABList[i]; } } for (int i = 0; i < abBase.ABDenpends.Count; i++) { AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + abBase.ABDenpends[i]); } AssetBundle assetBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + abBase.ABName); GameObject go = Instantiate(assetBundle.LoadAsset <GameObject>(abBase.AssetName), Vector3.forward, Quaternion.identity); }
private void ResetCfg() { if (ABUtility.LoadMode != LoadModeEnum.EditorOrigin) { // asset to ab name 读取 if (m_assetToABNames.Count > 0) { UnloadAssetBundle("configs"); m_assetToABNames.Clear(); m_ABToDependence.Clear(); } ABItem ab = LoadAssetBundle("configs"); AssetBundleConfig cfg2 = ab.AssetBundle.LoadAsset <AssetBundleConfig>("AssetBundleConfig.asset"); foreach (var item in cfg2.ResDict) { m_assetToABNames.Add(item.Path, item.ABName); } foreach (var item in cfg2.ABDict) { m_ABToDependence.Add(item.Name, item.DependenceNames); } } }
void TestLoadAB() { //TextAsset textAsset = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>("Assets/GameData/Data/ABData/AssetbundleConfig.bytes"); AssetBundle configAB = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/assetbundleconfig"); TextAsset textAsset = configAB.LoadAsset <TextAsset>("AssetBundleConfig"); MemoryStream stream = new MemoryStream(textAsset.bytes); BinaryFormatter bf = new BinaryFormatter(); AssetBundleConfig testSerilize = (AssetBundleConfig)bf.Deserialize(stream); stream.Close(); string path = "Assets/GameData/Prefabs/Attack.prefab"; uint crc = CRC32.GetCRC32(path); ABBase abBase = null; for (int i = 0; i < testSerilize.ABList.Count; i++) { if (testSerilize.ABList[i].Crc == crc) { abBase = testSerilize.ABList[i]; break; } } // 加载依赖ab包 for (int i = 0; i < abBase.ABDependce.Count; i++) { AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + abBase.ABDependce[i]); } AssetBundle assetBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + abBase.ABName); GameObject obj = GameObject.Instantiate(assetBundle.LoadAsset <GameObject>(abBase.AssetName)); }
/// <summary> 开始热更新 </summary> private void StartUpdate(Action <bool, string> UpdateCallBack) { LocalPath = PlatformManager.Instance.GetDataPath(PlatformManager.Instance.Name) + "/"; ServerUrl = NetcomManager.ABUrl + PlatformManager.Instance.Name + "/"; XmlLocalVersionPath = LocalPath + "AssetBundleConfig.xml"; XmlServerVersionPath = ServerUrl + "AssetBundleConfig.xml"; if (FileManager.FileExist(XmlLocalVersionPath)) { //读取本地热更文件 DownLoad(XmlLocalVersionPath, (byte[] bytes) => { localABConfig = bytes != null ? XmlSerializeManager.ProtoDeSerialize <AssetBundleConfig>(bytes) : null; //检查版本更新信息 CheckUpdate(localABConfig, () => { UpdateCallBack?.Invoke(downloadScenes.Count > 0, serverABConfig.Des); }); }); } else { //检查版本更新信息 CheckUpdate(localABConfig, () => { UpdateCallBack?.Invoke(downloadScenes.Count > 0, serverABConfig.Des); }); } }
public AssetBundle LoadAssetBundle(uint crc) { AssetBundleConfig config = null; if (!assetBundleConfigDic.TryGetValue(crc, out config)) { return(null); } var bundleCrc = CRC32.GetCRC32(config.BundleName); var item = GetCacheBundle(bundleCrc); if (item != null) { return(item.Bundle); } var bundle = LoadAssetBundle(config.BundleName); if (config.DependBundles != null && config.DependBundles.Count > 0) { for (int i = 0; i < config.DependBundles.Count; ++i) { LoadAssetBundle(config.DependBundles[i]); } } return(bundle); }
private static void BuildAssetBundleConfig() { string path = Application.dataPath + "/" + AssetBundleConfigPath; if (!File.Exists(path)) { return; } ClearAssetBundlesName(); string str = File.ReadAllText(path); AssetBundleConfig config = JsonHelper.Deserialize <AssetBundleConfig>(str); if (config == null || config.bundles == null) { return; } List <AssetBundleBuild> list = new List <AssetBundleBuild>(); for (int i = 0; i < config.bundles.Length; i++) { list.AddRange(config.bundles[i].GetBuildList()); } string bundlesPath = Application.dataPath + "/StreamingAssets"; BuildPipeline.BuildAssetBundles(bundlesPath, list.ToArray(), BuildAssetBundleOptions.None | BuildAssetBundleOptions.ForceRebuildAssetBundle, EditorUserBuildSettings.activeBuildTarget); Debug.Log(">> Build AssetBundle Config Compelte."); AssetDatabase.Refresh(); }
private static void MarkAssetBundleConfig() { string path = Application.dataPath + "/" + AssetBundleConfigPath; if (!File.Exists(path)) { return; } ClearAssetBundlesName(); string str = File.ReadAllText(path); AssetBundleConfig config = JsonHelper.Deserialize <AssetBundleConfig>(str); if (config == null || config.bundles == null) { return; } for (int i = 0; i < config.bundles.Length; i++) { //BuildPipeline.BuildAssetBundles(config.bundles, list.ToArray(), BuildAssetBundleOptions.None | BuildAssetBundleOptions.ForceRebuildAssetBundle, EditorUserBuildSettings.activeBuildTarget); config.bundles[i].MarkBundleName(); } Debug.Log(">> Mark AssetBundle Config Compelte."); }
void TestLoadAB() { AssetBundle configAB = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/assetbundleconfig"); TextAsset ta = configAB.LoadAsset <TextAsset>("AssetBundleConfig"); MemoryStream ms = new MemoryStream(ta.bytes); BinaryFormatter bf = new BinaryFormatter(); AssetBundleConfig assetBundleConfig = (AssetBundleConfig)bf.Deserialize(ms); ms.Close(); string path = "Assets/GameData/Prefabs/Attack.prefab"; uint crc = CRC32.GetCRC32(path); ABBase aBBase = null; for (int i = 0; i < assetBundleConfig.ABBaseList.Count; i++) { if (assetBundleConfig.ABBaseList[i].Crc == crc) { aBBase = assetBundleConfig.ABBaseList[i]; } } //先加载预制体依赖项 for (int i = 0; i < aBBase.ABDependceList.Count; i++) { AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + aBBase.ABDependceList[i]); } //再加载预制体 AssetBundle assetBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + aBBase.ABName); GameObject obj = GameObject.Instantiate(assetBundle.LoadAsset <GameObject>(aBBase.ABName)); }
void Test() { string path = "Assets/AssetBundleConfig.bytes"; TextAsset t = AssetDatabase.LoadAssetAtPath <TextAsset>(path); MemoryStream ms = new MemoryStream(t.bytes); BinaryFormatter bf = new BinaryFormatter(); AssetBundleConfig ab = (AssetBundleConfig)bf.Deserialize(ms); string path2 = "Assets/Prefabs/Models/Boss_Bruce/bruce.FBX"; uint crc = CRC32.GetCRC32(path2); ABBase abBase = null; for (int i = 0; i < ab.ABList.Count; ++i) { if (ab.ABList[i].Crc == crc) { abBase = ab.ABList[i]; continue; } } AssetBundle asset = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + abBase.ABName); Debug.Log(asset); GameObject obj = GameObject.Instantiate(asset.LoadAsset <GameObject>(abBase.AssetName)); }
//写入二进制 static void WriteBinary(AssetBundleConfig config) { //清除path字符串,这个内容和解析后的crc一样 foreach (ABBase ab in config.ABList) { ab.Path = ""; } string bytesSavePath = "Assets/GameData/FrameData/ABData/AssetBundleConfig.bytes"; if (File.Exists(bytesSavePath)) { File.Delete(bytesSavePath); } FileStream fileStream = new FileStream(bytesSavePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); //清空二进制文件 fileStream.Seek(0, SeekOrigin.Begin); fileStream.SetLength(0); //写入 BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fileStream, config); fileStream.Close(); AssetDatabase.Refresh(); //设置ab包 SetAB("assetbundleconfig", ABBYTEPATH); }
void TestLoadAB() { assetBundleConfig = LoadAssetBundleConfig(); string prefabPath = "Assets/Prefabs/Canvas.prefab"; GameObject obj = Instantiate(LoadAsset <GameObject>(prefabPath)); obj.name = "NewObj"; }
public override void OnInspectorGUI() { //base.OnInspectorGUI(); DrawDefaultInspector(); AssetBundleConfig assetBundleConfig = target as AssetBundleConfig; assetBundleConfig.update(); }
static void WriteData(Dictionary <string, string> resPathDic) { AssetBundleConfig config = new AssetBundleConfig(); config.ABList = new List <ABBase>(); foreach (string path in resPathDic.Keys) { } }
/// <summary> /// 写入数据 /// </summary> /// <param name="resPathDic">key 为全路径,value为包名</param> static void WriteData(Dictionary <string, string> resPathDic) { //创建数据 AssetBundleConfig assetBundleConfig = new AssetBundleConfig(); assetBundleConfig.ABList = new List <ABBase>(); foreach (string path in resPathDic.Keys) { ABBase aBBase = new ABBase(); aBBase.Path = path; aBBase.Crc = CRC32.GetCRC32(path); aBBase.ABName = resPathDic[path]; aBBase.AssetName = path.Remove(0, path.LastIndexOf("/") + 1); aBBase.ABDependce = new List <string>(); string[] resDependce = AssetDatabase.GetDependencies(path); for (int i = 0; i < resDependce.Length; i++) { string pathTemp = resDependce[i]; if (pathTemp == path || path.EndsWith(".cs")) { continue; } string abName = ""; if (resPathDic.TryGetValue(pathTemp, out abName)) { if (abName == resPathDic[path]) { continue; } if (!aBBase.ABDependce.Contains(abName)) { aBBase.ABDependce.Add(abName); } } } assetBundleConfig.ABList.Add(aBBase); } //写入XML string xmlPath = Application.dataPath + "/AssetbundleConfig.xml"; WriteReadData.CreateXML <AssetBundleConfig>(xmlPath, assetBundleConfig); //写入二进制 //二进制格式不需要Path数据 foreach (ABBase ab in assetBundleConfig.ABList) { ab.Path = ""; } //string binaryPath = BUNDLETARGETPATH + "/AssetbundleConfig.bytes"; string binaryPath = "Assets/GameData/Data/ABData/AssetBundleConfig.bytes"; WriteReadData.CreateBinary <AssetBundleConfig>(binaryPath, assetBundleConfig); }
/// <summary> /// 生成资源配置表 /// </summary> /// <param name="assetPathDic">所有的资源Key 是路径,Value是AB包名</param> public static AssetBundleConfig CreateConfig(Dictionary <string, string> assetPathDic) { AssetBundleConfig config = new AssetBundleConfig(); config.ABList = new List <BaseAB>(); foreach (var item in assetPathDic) { //引用的资源不在指定的文件夹内,一般针对Prefab if (!ValidPath(item.Key)) { continue; } BaseAB baseAB = new BaseAB(); baseAB.AssetName = item.Key.Substring(item.Key.LastIndexOf("/") + 1); baseAB.ABName = item.Value; baseAB.Path = item.Key; baseAB.Crc = Crc32.GetCrc32(baseAB.Path); baseAB.Depends = new List <string>(); //资源依赖项 string[] allDependAssetPathArr = AssetDatabase.GetDependencies(baseAB.Path); for (int i = 0; i < allDependAssetPathArr.Length; i++) { //自身 if (allDependAssetPathArr[i] == baseAB.Path) { continue; } //不添加脚本依赖 if (allDependAssetPathArr[i].EndsWith(".cs")) { continue; } string abName = ""; //判断资源的依赖项 if (assetPathDic.TryGetValue(allDependAssetPathArr[i], out abName)) { //如果这个依赖的资源和本身在同一个包,则不添加 //按照规则,这是Prefab依赖的资源 if (abName == baseAB.ABName) { continue; } if (!baseAB.Depends.Contains(abName)) { baseAB.Depends.Add(abName); } } } config.ABList.Add(baseAB); } return(config); }
AssetBundleConfig LoadAssetBundleConfig() { string configPath = Application.streamingAssetsPath + "/assetbundleconfig"; AssetBundle bundleConfig = AssetBundle.LoadFromFile(configPath); TextAsset textAsset = bundleConfig.LoadAsset <TextAsset>("AssetBundleConfigByte"); MemoryStream stream = new MemoryStream(textAsset.bytes); BinaryFormatter bf = new BinaryFormatter(); AssetBundleConfig assetBundleConfig = (AssetBundleConfig)bf.Deserialize(stream); stream.Close(); bundleConfig.Unload(true); return(assetBundleConfig); }
private void UpdateLocalConfig(Folder folder) { if (!FileManager.FileExist(XmlLocalVersionPath)) { AssetBundleConfig config = new AssetBundleConfig(); config.GameVersion = serverABConfig.GameVersion; config.Platform = serverABConfig.Platform; config.Scenes = serverABConfig.Scenes; FileManager.CreateFile(XmlLocalVersionPath, XmlSerializeManager.ProtoByteSerialize <AssetBundleConfig>(config)); UpdateConfig(); } UpdateConfig(folder); }
/// <summary> /// 加载AssetBundleConfig /// </summary> /// <returns></returns> public bool LoadAssetBundleConfig() { // TextAsset textAsset = null; //#if UNITY_EDITOR // textAsset = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(m_AssetConfigPath); //#endif // if (textAsset == null) // { // Debug.LogError("assetbundleConfig不存在!"+ m_AssetConfigPath); // return false; // } #if UNITY_EDITOR if (!ResourceManger.Instance.m_LoadFromAssetBundle) { return(false); } #endif m_ResourceItemDic.Clear(); string assetConfigPath = ABLoadpath + m_ABConfigABName; AssetBundle abConfigBundle = AssetBundle.LoadFromFile(assetConfigPath); TextAsset textAsset = abConfigBundle.LoadAsset <TextAsset>(m_ABConfigABName); if (textAsset == null) { Debug.LogError("assetbundleConfig不存在!"); return(false); } MemoryStream stream = new MemoryStream(textAsset.bytes); BinaryFormatter formatter = new BinaryFormatter(); AssetBundleConfig config = formatter.Deserialize(stream) as AssetBundleConfig; stream.Close(); for (int i = 0; i < config.ABList.Count; i++) { ABBase ab = config.ABList[i]; ResourceItem item = new ResourceItem(); item.m_Crc = ab.Crc; item.m_AssetName = ab.AssetName; item.m_AssetBundleName = ab.ABName; item.m_DependAssetBundle = ab.ABDependce; if (m_ResourceItemDic.ContainsKey(item.m_Crc)) { Debug.LogError("重复的Crc 资源名:" + item.m_AssetName + "ab包名:" + item.m_AssetBundleName); } else { m_ResourceItemDic.Add(item.m_Crc, item); } } return(true); }
private void OnGUI() { float padding = 0; //command button bar GUILayout.BeginHorizontal(EditorStyles.toolbar); { if (GUILayout.Button("Save", EditorStyles.toolbarButton)) { AssetBundleConfig.SaveConfig(); } if (GUILayout.Button("Apply", EditorStyles.toolbarButton)) { Apply(); } if (GUILayout.Button("DebugManifest", EditorStyles.toolbarButton)) { AssetBundleBuilder.GenerateAssetBundle(BuildTarget.StandaloneWindows64, false); } //GUILayout.FlexibleSpace(); if (GUILayout.Button("Build", EditorStyles.toolbarButton)) { Build(); } padding += 18; } GUILayout.EndHorizontal(); //filters context GUILayout.BeginVertical(); { //Filter item list //float lstH = _filterList.count * 22; _scrollPosition = GUILayout.BeginScrollView(_scrollPosition);//, GUILayout.Height(2+position.height/2)); { _filterList.DoLayoutList(); } GUILayout.EndScrollView(); padding += 18 + 18 + (_filterList.count == 0 ? 1 : _filterList.count) * _filterList.elementHeight; } GUILayout.EndVertical(); //preview _abPreviewTab.OnGUI(new Rect(0, padding, position.width, position.height - padding)); //set dirty //if (GUI.changed) // EditorUtility.SetDirty(_config); }
//写入配置表 static void WriteData(Dictionary <string, string> resPathDic) { //初始化数据 AssetBundleConfig config = new AssetBundleConfig(); config.ABList = new List <ABBase>(); foreach (string path in resPathDic.Keys) { if (!ValidPath(path)) { continue; //不是有效路径 } ABBase ab = new ABBase(); ab.ABName = resPathDic[path]; ab.Path = path; ab.AssetName = path.Remove(0, path.LastIndexOf("/") + 1); ab.Crc = Crc.GetCRC32(path); ab.ABDependce = new List <string>(); //查找关联 string[] depes = AssetDatabase.GetDependencies(path); foreach (string depe in depes) { if (depe.EndsWith(".cs") || depe == path) { continue; } //查看包名 string abName = ""; if (resPathDic.TryGetValue(depe, out abName)) { if (abName == ab.ABName) { continue; } else if (!ab.ABDependce.Contains(abName)) { ab.ABDependce.Add(abName); } } } config.ABList.Add(ab); } //写入xml WriteXml(config); //写入二进制 WriteBinary(config); }
protected override void DoInitUpdate() { //以同步的方式读取以JSON格式存储的Bundle的配置文件 string bundleConfigPath = $"{assetRootDir}/{AssetConst.ASSET_BUNDLE_CONFIG_NAME}"; string bundleConfigContent = File.ReadAllText(bundleConfigPath); bundleConfig = JsonConvert.DeserializeObject <AssetBundleConfig>(bundleConfigContent); //以同步的方式加载AssetBundle,并读取资源地址的配置文件 AssetBundle assetAddressConfigAB; if (GetBundleFilePath(AssetConst.ASSET_ADDRESS_BUNDLE_NAME, out string configPath, out ulong offset)) { assetAddressConfigAB = AssetBundle.LoadFromFile(configPath, 0, offset); }
/// <summary> 获取文件夹名和包名 </summary> private void GetABScenePairs(AssetBundleConfig config) { //获取文件夹名和包名,用来给AssetbundleSceneManager里的folderDic赋值 foreach (var scene in config.Scenes) { Dictionary <string, string> folderPairs = new Dictionary <string, string>(); foreach (var folder in scene.Folders) { if (!folderPairs.ContainsKey(folder.FolderName)) { folderPairs.Add(folder.FolderName, folder.BundleName); } } AssetBundleManager.Instance.SetAbScenePairs(scene.SceneName, folderPairs); } }
/// <summary> /// 加载ab配置表 /// </summary> /// <returns></returns> public bool LoadAssetBundleConfig() { #if UNITY_EDITOR if (!ResourceManager.Instance.m_LoadFormAssetBundle) { return(false); } #endif m_ResouceItemDic.Clear(); string configPath = ABLoadPath + m_ABConfigABName; string hotABPath = HotPatchManager.Instance.ComputeABPath(m_ABConfigABName); configPath = string.IsNullOrEmpty(hotABPath) ? configPath : hotABPath; byte[] bytes = AES.AESFileByteDecrypt(configPath, "Ocean"); AssetBundle configAB = AssetBundle.LoadFromMemory(bytes); TextAsset textAsset = configAB.LoadAsset <TextAsset>(m_ABConfigABName); if (textAsset == null) { Debug.LogError("AssetBundleConfig is no exist!"); return(false); } MemoryStream stream = new MemoryStream(textAsset.bytes); BinaryFormatter bf = new BinaryFormatter(); AssetBundleConfig config = (AssetBundleConfig)bf.Deserialize(stream); stream.Close(); for (int i = 0; i < config.ABList.Count; i++) { ABBase abBase = config.ABList[i]; ResouceItem item = new ResouceItem(); item.m_Crc = abBase.Crc; item.m_AssetName = abBase.AssetName; item.m_ABName = abBase.ABName; item.m_DependAssetBundle = abBase.ABDependce; if (m_ResouceItemDic.ContainsKey(item.m_Crc)) { Debug.LogError("重复的Crc 资源名:" + item.m_AssetName + " ab包名:" + item.m_ABName); } else { m_ResouceItemDic.Add(item.m_Crc, item); } } return(true); }
//写入xml static void WriteXml(AssetBundleConfig config) { string xmlSavePath = "Assets/AssetBundleConfig.xml"; if (File.Exists(xmlSavePath)) { File.Delete(xmlSavePath); } FileStream fileStream = new FileStream(xmlSavePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); StreamWriter sw = new StreamWriter(fileStream); XmlSerializer serializer = new XmlSerializer(config.GetType()); serializer.Serialize(sw, config); sw.Close(); fileStream.Close(); }