string IBundleServices.GetAssetBundleLoadPath(string manifestPath) { PatchManifest patchManifest; if (_patcher.WebPatchManifest != null) { patchManifest = _patcher.WebPatchManifest; } else { patchManifest = _patcher.SandboxPatchManifest; } manifestPath = GetVariantManifestPath(patchManifest, manifestPath); if (patchManifest.Elements.TryGetValue(manifestPath, out PatchElement element)) { // 先查询APP内的资源 if (_patcher.AppPatchManifest.Elements.TryGetValue(manifestPath, out PatchElement appElement)) { if (appElement.MD5 == element.MD5) { return(AssetPathHelper.MakeStreamingLoadPath(manifestPath)); } } // 如果APP里不存在或者MD5不匹配,则从沙盒里加载 return(AssetPathHelper.MakePersistentLoadPath(manifestPath)); } else { MotionLog.Warning($"Not found element in patch manifest : {manifestPath}"); return(AssetPathHelper.MakeStreamingLoadPath(manifestPath)); } }
private static void WriteMd5Record(Dictionary <string, string> value, string folderPath, Md5Record record) { if (record == null) { record = new Md5Record(); record.value = new Dictionary <string, List <string> >(); } string buildTarget = AssetPathHelper.GetBuildTarget(AssetPathHelper.GetBuildTarget()); List <string> tokenList = new List <string>(); foreach (string key in value.Keys) { tokenList.Add(key); tokenList.Add(value[key]); } if (record.value.Keys.Contains(buildTarget)) { record.value[buildTarget] = tokenList; } else { record.value.Add(buildTarget, tokenList); } string content = JsonMapper.ToJson(record); content = content.Replace("\"Assets/Things/", "\n\"Assets/Things/"); string path = GetMd5RecordPath(folderPath); WriteJson(content, path); }
/// <summary> /// 异步初始化 /// </summary> public IEnumerator InitializeAsync(bool simulationOnEditor) { if (simulationOnEditor) { yield break; } // 解析APP里的补丁清单 string filePath = AssetPathHelper.MakeStreamingLoadPath(PatchDefine.PatchManifestBytesFileName); string url = AssetPathHelper.ConvertToWWWPath(filePath); WebDataRequest downloader = new WebDataRequest(url); yield return(downloader.DownLoad()); if (downloader.States == EWebRequestStates.Success) { _patchManifest = new PatchManifest(); _patchManifest.Parse(downloader.GetData()); downloader.Dispose(); } else { throw new System.Exception($"Fatal error : Failed download file : {url}"); } }
/// <summary> /// 异步初始化 /// </summary> public IEnumerator InitializeAsync(bool simulationOnEditor) { if (simulationOnEditor) { yield break; } // 解析APP里的补丁清单 string filePath = AssetPathHelper.MakeStreamingLoadPath(PatchDefine.PatchManifestFileName); string url = AssetPathHelper.ConvertToWWWPath(filePath); WebGetRequest downloader = new WebGetRequest(url); downloader.DownLoad(); yield return(downloader); if (downloader.HasError()) { downloader.ReportError(); downloader.Dispose(); throw new System.Exception($"Fatal error : Failed download file : {url}"); } _patchManifest = PatchManifest.Deserialize(downloader.GetText()); downloader.Dispose(); }
/// <summary> /// 同步加载接口 /// 注意:仅支持特殊的无依赖资源 /// </summary> public T SyncLoad <T>(string resName) where T : UnityEngine.Object { UnityEngine.Object result = null; if (AssetSystem.AssetLoadMode == EAssetLoadMode.EditorMode) { #if UNITY_EDITOR string loadPath = AssetSystem.GetDatabaseAssetPath(resName); result = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(loadPath); #else throw new Exception("AssetDatabaseLoader only support unity editor."); #endif } else if (AssetSystem.AssetLoadMode == EAssetLoadMode.ResourceMode) { result = Resources.Load <T>(resName); } else if (AssetSystem.AssetLoadMode == EAssetLoadMode.BundleMode) { string fileName = System.IO.Path.GetFileNameWithoutExtension(resName); string manifestPath = AssetPathHelper.ConvertResourcePathToManifestPath(resName); string loadPath = AssetSystem.BundleMethod.GetAssetBundleLoadPath(manifestPath); AssetBundle bundle = AssetBundle.LoadFromFile(loadPath); result = bundle.LoadAsset <T>(fileName); bundle.Unload(false); } else { throw new NotImplementedException($"{AssetSystem.AssetLoadMode}"); } return(result as T); }
string IBundleServices.GetAssetBundleLoadPath(string manifestPath) { // 尝试获取变体资源清单路径 manifestPath = _variantCollector.TryGetVariantManifestPath(manifestPath); // 从流文件夹内加载所有文件 return(AssetPathHelper.MakeStreamingLoadPath(manifestPath)); }
public void SaveRemotePatchManifest() { // 注意:这里会覆盖掉沙盒内的补丁清单文件 MotionLog.Log("Save remote patch manifest."); string savePath = AssetPathHelper.MakePersistentLoadPath(PatchDefine.PatchManifestFileName); PatchManifest.Serialize(savePath, _localPatchManifest); }
/// <summary> /// 清空沙盒目录 /// </summary> public static void ClearSandbox() { string directoryPath = AssetPathHelper.MakePersistentLoadPath(string.Empty); if (Directory.Exists(directoryPath)) { Directory.Delete(directoryPath, true); } }
private static string Log(string entryPath, string bundlePath, StrategyNode node) { string outputPath = AssetPathHelper.GetOutputPath(bundlePath); string content = string.Format("策略名称:{0}\n模式:{1}\n入口:{2}\nProcessor:{3}\nPattern:{4}\n输出:{5}\n体积:{6}KB", node.strategy, node.mode, entryPath, node.processor, node.pattern, bundlePath, GetFileSize(outputPath).ToString()); Logger.GetLogger(AssetBundleExporter.LOGGER_NAME).Log(content); return(content); }
public void SaveWebPatchManifest() { if (_webPatchManifestCacheData == null) { throw new Exception("WebPatchManifest cached data is null."); } // 注意:这里会覆盖掉旧文件 string savePath = AssetPathHelper.MakePersistentLoadPath(PatchDefine.PatchManifestBytesFileName); File.WriteAllBytes(savePath, _webPatchManifestCacheData); }
AssetBundleInfo IBundleServices.GetAssetBundleInfo(string bundleName) { if (_patchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle)) { string localPath = AssetPathHelper.MakeStreamingLoadPath(patchBundle.Hash); AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, localPath, patchBundle.Version, patchBundle.IsEncrypted); return(bundleInfo); } else { MotionLog.Warning($"Not found bundle in patch manifest : {bundleName}"); AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, string.Empty); return(bundleInfo); } }
// 返回贴图打包的平台名字 public static string GetTextureBuildTargetName() { switch (AssetPathHelper.GetBuildTarget()) { case BuildTarget.StandaloneWindows: case BuildTarget.StandaloneWindows64: case BuildTarget.StandaloneOSX: return("Standalone"); case BuildTarget.Android: return("Android"); case BuildTarget.iOS: return("iPhone"); } return("Standalone"); }
private static Dictionary <string, string> BuildSingleNode(string entryPath, List <string> assetPathList, StrategyNode node) { Dictionary <string, string> result = new Dictionary <string, string>(); for (int i = 0; i < assetPathList.Count; i++) { string assetPath = assetPathList[i]; string bundlePath = AssetPathHelper.GetSingleModeBundlePath(assetPath); result.Add(assetPath, bundlePath); if (CanBuild(entryPath, bundlePath) == false) { continue; } AddAssetBundleBuildWrapper(assetPath, bundlePath, new string[] { assetPath }, node); } return(result); }
public static TextureImporterFormat GetTextureFormat() { switch (AssetPathHelper.GetBuildTarget()) { case BuildTarget.StandaloneWindows: case BuildTarget.StandaloneWindows64: case BuildTarget.StandaloneOSXIntel: case BuildTarget.StandaloneOSXIntel64: return(TextureImporterFormat.DXT5); case BuildTarget.Android: return(TextureImporterFormat.ETC_RGB4); case BuildTarget.iOS: return(TextureImporterFormat.PVRTC_RGBA4); } return(TextureImporterFormat.DXT1); }
private static string[] GetFolderModeAssetPaths(List <string> assetPathList, StrategyNode node) { string folderPath = AssetPathHelper.GetFolderModeStartPath(assetPathList[0], node.pattern); string systemFolderPath = AssetPathHelper.ToFileSystemPath(folderPath); string[] filePaths = Directory.GetFiles(systemFolderPath, "*.*", SearchOption.AllDirectories); List <string> filteredPathList = new List <string>(); for (int i = 0; i < filePaths.Length; i++) { filePaths[i] = filePaths[i].Replace(@"\", @"/"); if (filePaths[i].Contains(".mata") == false && node.pattern.IsMatch(filePaths[i]) == true) { filteredPathList.Add(AssetPathHelper.ToAssetPath(filePaths[i])); } } return(filteredPathList.ToArray()); }
/// <summary> /// 返回值 Key为资源路径,Value为资源Md5值,资源包括meta文件 /// </summary> /// <param name="folderPath"></param> /// <returns></returns> private static Dictionary <string, string> ReadMd5(Md5Record record) { Dictionary <string, string> result = new Dictionary <string, string>(); if (record != null) { string buildTarget = AssetPathHelper.GetBuildTarget(AssetPathHelper.GetBuildTarget()); if (record.value.Keys.Contains(buildTarget)) { List <string> tokenList = record.value[buildTarget]; for (int i = 0; i < tokenList.Count; i += 2) { result.Add(tokenList[i], tokenList[i + 1]); } } } return(result); }
private static Dictionary <string, string> BuildSelectionMode(string entryPath, List <string> assetPathList, StrategyNode node) { Dictionary <string, string> result = new Dictionary <string, string>(); string bundlePath = AssetPathHelper.GetSelectionModeBundlePath(entryPath, assetPathList, node.pattern); foreach (string s in assetPathList) { result.Add(s, bundlePath); } if (CanBuild(entryPath, bundlePath) == false) { return(result); } //TODO: 验证Selection中存在不同路径下,同类型同名但是内容不同时可能引起的问题 VerifySelectionAssets(assetPathList); AddAssetBundleBuildWrapper(entryPath, bundlePath, assetPathList.ToArray(), node); return(result); }
public string transformPath; // for Transform / GameObject public static ObjectMeta GetAt(UnityEngine.Object obj, ExtraData extraData) { ObjectMeta r = new ObjectMeta(); if (obj != null) { r.name = obj.name; r.typeName = obj.GetType().FullName; r.extraDataObjectIndex = -1; r.assetPath = UnityEditor.AssetDatabase.GetAssetPath(obj); if (!string.IsNullOrEmpty(r.assetPath)) { r.guid = UnityEditor.AssetDatabase.AssetPathToGUID(r.assetPath); if (!string.IsNullOrEmpty(extraData.rootDirectory)) { r.relativeAssetPath = AssetPathHelper.GenerateRelativeAssetPath(extraData.rootDirectory, r.assetPath); } } r.transformPath = ""; if (extraData != null && extraData.rootTransform != null) { Transform transform = null; if (obj is GameObject) { transform = ((GameObject)obj).transform; } else if (obj is Transform) { transform = (Transform)obj; } if (transform != null && transform.IsChildOf(extraData.rootTransform)) { r.transformPath = _GetTransformPath(extraData.rootTransform, transform); } } } return(r); }
AssetBundleInfo IBundleServices.GetAssetBundleInfo(string bundleName) { if (_variantCollector != null) { bundleName = _variantCollector.RemapVariantName(_patchManifest, bundleName); } if (_patchManifest.Elements.TryGetValue(bundleName, out PatchElement element)) { string localPath = AssetPathHelper.MakeStreamingLoadPath(element.MD5); AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, localPath, string.Empty, element.Version, element.IsEncrypted); return(bundleInfo); } else { MotionLog.Warning($"Not found element in patch manifest : {bundleName}"); AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, string.Empty); return(bundleInfo); } }
void IFsmNode.OnEnter() { PatchEventDispatcher.SendPatchStatesChangeMsg(EPatchStates.ParseSandboxPatchManifest); // 读取并解析沙盒内的补丁清单 if (PatchHelper.CheckSandboxPatchManifestFileExist()) { string filePath = AssetPathHelper.MakePersistentLoadPath(PatchDefine.PatchManifestFileName); string fileContent = PatchHelper.ReadFile(filePath); PatchHelper.Log(ELogLevel.Log, $"Parse sandbox patch file."); _patcher.ParseSandboxPatchManifest(fileContent); } else { _patcher.ParseSandboxPatchManifest(_patcher.AppPatchManifest); } _patcher.SwitchNext(); }
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { var GUIDProp = property.FindPropertyRelative(AssetPathHelper.GUIDPropName); var FolderProp = property.FindPropertyRelative(AssetPathHelper.FolderPropName); var FileProp = property.FindPropertyRelative(AssetPathHelper.FilePropName); var NameProp = property.FindPropertyRelative(AssetPathHelper.NamePropName); AssetPathHelper.TranslatePathPairToAssetsPath(GUIDProp, FolderProp, FileProp, out var assetPath, out var file, out var guidPath, out var guidFile); Object obj = null; if (File.Exists(file)) { obj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)); } else if (File.Exists(guidFile)) { obj = AssetDatabase.LoadAssetAtPath(guidPath, typeof(GameObject)); } obj = EditorGUI.ObjectField(rect, label, obj, typeof(GameObject), false); if (obj != null) { var path = AssetDatabase.GetAssetPath(obj); if (path.Contains("Assets/ResClient/")) { var tmpPath = path.Replace("Assets/ResClient/", ""); GUIDProp.stringValue = AssetDatabase.AssetPathToGUID(path); FolderProp.stringValue = (tmpPath.Substring(0, tmpPath.LastIndexOf('/')) + ".ab").ToLower(); FileProp.stringValue = Path.GetFileName(path).ToLower(); NameProp.stringValue = Path.GetFileNameWithoutExtension(path); } else { EditorUtility.DisplayDialog("Info", "目前资源加载只支持Assets/ResClient/目录", "知道了"); } } else { GUIDProp.stringValue = FolderProp.stringValue = FileProp.stringValue = ""; } }
private static Dictionary <string, string> BuildFolderMode(string entryPath, List <string> assetPathList, StrategyNode node) { Dictionary <string, string> result = new Dictionary <string, string>(); Dictionary <string, List <string> > splitPathListDict = SplitAssetPathList(assetPathList, node); foreach (string k in splitPathListDict.Keys) { string bundlePath = AssetPathHelper.GetFolderModeBundlePath(splitPathListDict[k], node.pattern); string[] folderAssetPaths = GetFolderModeAssetPaths(splitPathListDict[k], node); foreach (string s in folderAssetPaths) { result.Add(s, bundlePath); } if (CanBuild(entryPath, bundlePath) == false) { continue; } AddAssetBundleBuildWrapper(entryPath, bundlePath, folderAssetPaths, node); } return(result); }
public override void Enter() { PatchManager.SendPatchStatesChangeMsg((EPatchStates)_system.Current()); // 读取并解析沙盒内的补丁文件 if (PatchManager.CheckSandboxPatchFileExist()) { string filePath = AssetPathHelper.MakePersistentLoadPath(PatchDefine.StrPatchFileName); string fileContent = PatchManager.ReadFile(filePath); // 解析补丁文件 PatchManager.Log(ELogType.Log, $"Parse sandbox patch file."); PatchManager.Instance.ParseSandboxPatchFile(fileContent); } else { PatchManager.Instance.ParseSandboxPatchFile(PatchManager.Instance.AppPatchFile); } _system.SwitchNext(); }
private IEnumerator DownLoad() { // 解析APP里的补丁清单 string filePath = AssetPathHelper.MakeStreamingLoadPath(PatchDefine.PatchManifestFileName); string url = AssetPathHelper.ConvertToWWWPath(filePath); WebDataRequest downloader = new WebDataRequest(url); yield return(downloader.DownLoad()); if (downloader.States == EWebRequestStates.Success) { PatchHelper.Log(ELogLevel.Log, "Parse app patch manifest."); _patcher.ParseAppPatchManifest(downloader.GetText()); downloader.Dispose(); _patcher.SwitchNext(); } else { throw new System.Exception($"Fatal error : Failed download file : {url}"); } }
private IEnumerator DownLoad(ProcedureSystem system) { // 解析APP里的补丁文件 string filePath = AssetPathHelper.MakeStreamingLoadPath(PatchDefine.StrPatchFileName); string url = AssetPathHelper.ConvertToWWWPath(filePath); WebDataRequest downloader = new WebDataRequest(url); yield return(downloader.DownLoad()); if (downloader.States == EWebRequestStates.Succeed) { PatchManager.Log(ELogType.Log, "Parse app patch file."); PatchManager.Instance.ParseAppPatchFile(downloader.GetText()); downloader.Dispose(); system.SwitchNext(); } else { throw new System.Exception($"Fatal error : Failed download file : {url}"); } }
private static Texture2D CreateAtlas(string atlasPath, TextureData[] textureDatas) { Texture2D atlas = new Texture2D(ATLAS_MAX_SIZE, ATLAS_MAX_SIZE); Rect[] rects = atlas.PackTextures(GetPackTextures(textureDatas), 0, ATLAS_MAX_SIZE, false); AtlasWriter.Write(atlas, atlasPath); int atlasWidth = atlas.width; int atlasHeight = atlas.height; string alphaAtlasPath = atlasPath.Replace(".png", "_alpha.png"); AssetDatabase.ImportAsset(atlasPath, ImportAssetOptions.ForceUpdate); //安卓平台图集分离通道 if (AssetPathHelper.GetBuildTarget() == BuildTarget.Android && !atlasPath.Contains("UI_Base")) { try { ImageChannelSpliterWrapper.Execute(atlasPath); AssetDatabase.ImportAsset(alphaAtlasPath, ImportAssetOptions.ForceUpdate); TextureImporterUtil.CreateAlphaChannelImporter(alphaAtlasPath); AssetDatabase.ImportAsset(alphaAtlasPath, ImportAssetOptions.ForceUpdate); } catch (Exception e) { Debug.LogError("通道分离过程中发生错误: " + e.Message); Debug.LogException(e); } } TextureImporterFormat textureFormat = TextureImporterUtil.GetTextureFormat(); if (atlasPath.Contains("UI_Base")) { textureFormat = TextureImporterFormat.ARGB32; } AssetDatabase.ImportAsset(atlasPath, ImportAssetOptions.ForceUpdate); TextureImporterUtil.CreateMultipleSpriteImporter(atlasPath, rects, GetPackTexturesNames(textureDatas), GetSpriteBorders(textureDatas), atlasWidth, atlasHeight, textureFormat, ATLAS_MAX_SIZE); AssetDatabase.ImportAsset(atlasPath, ImportAssetOptions.ForceUpdate); MaterialCreator.Create(atlasPath, alphaAtlasPath); return(atlas); }
string IBundleServices.GetAssetBundleLoadPath(string manifestPath) { PatchManifest patchManifest; if (_patcher.WebPatchManifest != null) { patchManifest = _patcher.WebPatchManifest; } else { patchManifest = _patcher.SandboxPatchManifest; } // 尝试获取变体资源清单路径 manifestPath = _variantCollector.TryGetVariantManifestPath(manifestPath); // 注意:可能从APP内加载,也可能从沙盒内加载 PatchElement element; if (patchManifest.Elements.TryGetValue(manifestPath, out element)) { // 先查询APP内的资源 PatchElement appElement; if (_patcher.AppPatchManifest.Elements.TryGetValue(manifestPath, out appElement)) { if (appElement.MD5 == element.MD5) { return(AssetPathHelper.MakeStreamingLoadPath(manifestPath)); } } // 如果APP里不存在或者MD5不匹配,则从沙盒里加载 return(AssetPathHelper.MakePersistentLoadPath(manifestPath)); } else { PatchHelper.Log(ELogLevel.Warning, $"Not found element in patch manifest : {manifestPath}"); return(AssetPathHelper.MakeStreamingLoadPath(manifestPath)); } }
/// <summary> /// 获取AssetBundle的加载信息 /// </summary> public AssetBundleInfo GetAssetBundleInfo(string bundleName) { if (_localPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle)) { // 查询APP资源 if (_appPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle appPatchBundle)) { if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash) { string appLoadPath = AssetPathHelper.MakeStreamingLoadPath(appPatchBundle.Hash); AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, appLoadPath, appPatchBundle.Version, appPatchBundle.IsEncrypted); return(bundleInfo); } } // 查询缓存资源 // 注意:如果沙盒内缓存文件不存在,那么将会从服务器下载 string sandboxLoadPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash); if (_cache.Contains(patchBundle.Hash)) { AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, sandboxLoadPath, patchBundle.Version, patchBundle.IsEncrypted); return(bundleInfo); } else { string remoteURL = GetPatchDownloadURL(patchBundle.Version, patchBundle.Hash); string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Version, patchBundle.Hash); AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, sandboxLoadPath, remoteURL, remoteFallbackURL, patchBundle.Version, patchBundle.IsEncrypted); return(bundleInfo); } } else { MotionLog.Warning($"Not found bundle in patch manifest : {bundleName}"); AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, string.Empty); return(bundleInfo); } }
private IEnumerator Download() { // 注意:等所有文件下载完毕后,下载并替换补丁清单 int newResourceVersion = _patcher.RequestedResourceVersion; string url = _patcher.GetWebDownloadURL(newResourceVersion.ToString(), PatchDefine.PatchManifestFileName); string savePath = AssetPathHelper.MakePersistentLoadPath(PatchDefine.PatchManifestFileName); WebFileRequest download = new WebFileRequest(url, savePath); yield return(download.DownLoad()); if (download.States != EWebRequestStates.Success) { download.Dispose(); PatchEventDispatcher.SendWebPatchManifestDownloadFailedMsg(); yield break; } else { PatchHelper.Log(ELogLevel.Log, "Web patch manifest is download."); download.Dispose(); _patcher.SwitchNext(); } }
public IEnumerator Download(ProcedureSystem system) { // 注意:等所有文件下载完毕后,再替换版本文件 int newResourceVersion = PatchManager.Instance.GameVersion.Revision; string url = PatchManager.MakeWebDownloadURL(newResourceVersion.ToString(), PatchDefine.StrPatchFileName); string savePath = AssetPathHelper.MakePersistentLoadPath(PatchDefine.StrPatchFileName); WebFileRequest download = new WebFileRequest(url, savePath); yield return(download.DownLoad()); if (download.States != EWebRequestStates.Succeed) { download.Dispose(); system.Switch((int)EPatchStates.PatchError); yield break; } else { PatchManager.Log(ELogType.Log, "Download web files is finish."); download.Dispose(); system.SwitchNext(); } }