private static void SaveMapping() { bool exist = true; AssetBundleMapping assetbundleMapping = AssetDatabase.LoadAssetAtPath <AssetBundleMapping>(ConstantData.assetBundleMappingPath); if (null == assetbundleMapping) { exist = false; assetbundleMapping = new AssetBundleMapping(); } assetbundleMapping.Init(s_AssetbundleNameMapFilePaths); if (exist) { EditorUtility.SetDirty(assetbundleMapping); } else { AssetDatabase.CreateAsset(assetbundleMapping, ConstantData.assetBundleMappingPath); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); s_AssetbundleNameMapFilePaths.Clear(); Reimport(ConstantData.assetBundleMappingPath, ConstantData.assetBundleMappingName); }
private void ClearAfterPatch() { m_AssetBundleManifest = null; m_mapping = null; UnloadAssetBundle(ConstantData.assetbundleManifest, true); UnloadAssetBundle(ConstantData.assetbundleMapping, true); Clear(true); }
/// <summary> /// 加载assetbundle 映射表 /// file map assetbundle name /// </summary> private void LoadAssetBundleMapping() { LoadAssetFromBundle(ConstantData.assetBundleMappingName, ConstantData.assetBundleMappingName, typeof(AssetBundleMapping), (data) => { m_Mapping = data as AssetBundleMapping; if (null != m_Mapping) { m_Mapping.Init(); } }, false, false, true); }
static void SaveMapping() { string path = "Assets/Data/ab_mapping.asset"; bool exist = true; AssetBundleMapping assetBundleMapping = AssetDatabase.LoadAssetAtPath <AssetBundleMapping>(path); if (null == assetBundleMapping) { exist = false; assetBundleMapping = new AssetBundleMapping(); } assetBundleMapping.assetBundleInfos = new AssetBundleMapping.AssetBundleInfo[s_AssetBundleNameMapFilePaths.Count]; int i = 0; foreach (var map in s_AssetBundleNameMapFilePaths) { AssetBundleMapping.AssetBundleInfo info = new AssetBundleMapping.AssetBundleInfo(); info.assetBundleName = map.Key.ToLower(); HashSet <string> paths = map.Value; info.paths = new string[paths.Count]; int j = 0; foreach (string file in paths) { info.paths[j] = file.Replace("\\", "/").Replace("Assets/Data/", "").Replace("Assets/", "").ToLower(); ++j; } assetBundleMapping.assetBundleInfos[i] = info; ++i; } if (exist) { EditorUtility.SetDirty(assetBundleMapping); } else { AssetDatabase.CreateAsset(assetBundleMapping, path); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); s_AssetBundleNameMapFilePaths.Clear(); Reimport(path, "ab_mapping"); }
static void SaveMapping() { string path = "Assets/Data/ab_mapping.asset"; bool exist = true; AssetBundleMapping data = AssetDatabase.LoadAssetAtPath <AssetBundleMapping>(path); if (data == null) { exist = false; data = new AssetBundleMapping(); } data.Assetbundles = new AssetBundleMapping.AssetBundleInfo[ms_mapping.Count]; int i = 0; var iter = ms_mapping.GetEnumerator(); while (iter.MoveNext()) { AssetBundleMapping.AssetBundleInfo info = new AssetBundleMapping.AssetBundleInfo(); info.Name = iter.Current.Key.ToLower(); info.Files = new string[iter.Current.Value.Count]; int j = 0; foreach (string file in iter.Current.Value) { info.Files[j] = file.Replace("\\", "/").Replace("Assets/Data/", "").Replace("Assets/", "").ToLower(); ++j; } data.Assetbundles[i] = info; ++i; } if (exist) { EditorUtility.SetDirty(data); AssetDatabase.SaveAssets(); } else { AssetDatabase.CreateAsset(data, path); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); ms_mapping.Clear(); Reimport(path, "ab_mapping"); }
/*private void InitVersionData(bool start = true) * { * Clear(); * * m_origns.Clear(); * for (int i = 0; i < VersionData.Inst.Items.Length; ++i) * { * VersionData.VersionItem item = VersionData.Inst.Items[i]; * m_origns.Add(item.Name, item.Md5); * } * * if (start) * { * LoadManifest(); * } * }*/ /*public void SetPatchData(JSONClass list, bool clear = false) * { * if (clear) * { * Clear(); * } * * m_patchs.Clear(); * if (list != null) * { * foreach (KeyValuePair<string, JSONNode> item in list) * { * m_patchs.Add(item.Key, item.Value["md5"]); * } * } * * LoadManifest(); * }*/ /*private void LoadVersion() * { * Logger.Log("LoadVersion"); * if (ConstantData.EnableMd5Name) * { * string pathPatch = string.Format("{0}/version_patch", Application.persistentDataPath); * bool hasPatch = false; * * if (ConstantData.EnablePatch) * { * hasPatch = File.Exists(pathPatch); * } * * InitVersionData(!hasPatch); * * if (hasPatch) * { * LoadStream(pathPatch, (data) => * { * byte[] bytes = data as byte[]; * if (bytes == null) * { * Logger.LogError("Load patch version Failed!"); * return; * } * * string text = Encoding.UTF8.GetString(bytes); * JSONClass json = JSONNode.Parse(text) as JSONClass; * if (json == null) * { * Logger.LogError("Load patch version Failed!"); * return; * } * * JSONClass jsonList = null; * if (string.Equals(json["version"], LogicConstantData.Version)) * { * jsonList = json["list"] as JSONClass; * } * * m_urlPatch = json["url"]; * SetPatchData(jsonList); * }, false, false, true); * } * } * else * { * LoadManifest(); * } * }*/ // 加载资源清单 private void LoadManifest() { Logger.Log("LoadManifest"); if (m_manifest != null) { Object.DestroyImmediate(m_manifest, true); m_manifest = null; } if (m_mapping != null) { Object.DestroyImmediate(m_mapping, true); m_mapping = null; } // 加载AssetBundle依赖文件 LoadAssetBundle(null, ConstantData.AssetbundleManifest, (group, data) => { AssetBundleInfo ab = data as AssetBundleInfo; if (ab != null) { m_manifest = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); } }, false, false, false); // 加载资源到AssetBundle映射表 string name = ConstantData.AssetbundleMapping; LoadAssetFromBundle(null, name, name, typeof(AssetBundleMapping), (group, data) => { m_mapping = data as AssetBundleMapping; if (m_mapping != null) { m_mapping.Init(); } }, false); Logger.Log("LoadManifest End"); }