From cb4ebb6306694a46bd70c85d063d7c5c1396e390 Mon Sep 17 00:00:00 2001 From: hevinci Date: Sat, 22 Oct 2022 10:51:14 +0800 Subject: [PATCH] Update document --- Docs/CodeTutorial1.md | 10 -------- Docs/CodeTutorial3.md | 56 ++++++++++++++++++------------------------- Docs/CodeTutorial4.md | 20 ++++++++-------- Docs/FAQ.md | 2 +- 4 files changed, 34 insertions(+), 54 deletions(-) diff --git a/Docs/CodeTutorial1.md b/Docs/CodeTutorial1.md index 3e780a8..83756c9 100644 --- a/Docs/CodeTutorial1.md +++ b/Docs/CodeTutorial1.md @@ -25,7 +25,6 @@ YooAssets.SetDefaultAssetsPackage(defaultPackage); private IEnumerator InitializeYooAsset() { var initParameters = new EditorSimulateModeParameters(); - initParameters.LocationServices = new DefaultLocationServices("Assets/GameRes"); initParameters.SimulatePatchManifestPath = EditorSimulateModeHelper.SimulateBuild("DefaultPackage"); yield return defaultPackage.InitializeAsync(initParameters); } @@ -41,7 +40,6 @@ private IEnumerator InitializeYooAsset() private IEnumerator InitializeYooAsset() { var initParameters = new OfflinePlayModeParameters(); - initParameters.LocationServices = new DefaultLocationServices("Assets/GameRes"); yield return defaultPackage.InitializeAsync(initParameters); } ```` @@ -52,14 +50,6 @@ private IEnumerator InitializeYooAsset() 注意:该模式需要构建资源包 -- LocationServices : 资源定位的实例类。 - - (1) 默认的资源定位服务类(DefaultLocationServices) - - (2) 可寻址的资源定位服务类(AddressLocationServices) - - (3) 开发者自定义的资源定位服务类,需要提供实现ILocationServices接口的实例类。 - - DecryptionServices : 如果资源包在构建的时候有加密,需要提供实现IDecryptionServices接口的实例类。 - QueryServices:内置资源查询服务接口。 diff --git a/Docs/CodeTutorial3.md b/Docs/CodeTutorial3.md index 5b6c25a..4445d37 100644 --- a/Docs/CodeTutorial3.md +++ b/Docs/CodeTutorial3.md @@ -2,52 +2,41 @@ **加载方法** -- YooAssets.LoadAssetSync() 同步加载资源对象 -- YooAssets.LoadAssetAsync() 异步加载资源对象 -- YooAssets.LoadSubAssetsSync() 同步加载子资源对象 -- YooAssets.LoadSubAssetsAsync() 异步加载子资源对象 -- YooAssets.LoadSceneAsync() 异步加载场景 -- YooAssets.GetRawFileAsync() 异步获取原生文件 +- LoadAssetSync() 同步加载资源对象 +- LoadAssetAsync() 异步加载资源对象 +- LoadSubAssetsSync() 同步加载子资源对象 +- LoadSubAssetsAsync() 异步加载子资源对象 +- LoadSceneAsync() 异步加载场景 +- GetRawFileAsync() 异步获取原生文件 **统一约定** **Location**为资源的定位地址,也是加载资源对象的唯一标识符。 -- DefaultLocationServices 默认资源定位服务,location代表的是资源对象的相对路径。 +- 在未开启可寻址模式下,location代表的是资源对象的完整路径。 ```c# // 以工程内的音频文件为例:"Assets/GameRes/Audio/bgMusic.mp3" -// 设定资源路径的根目录为:"Assets/GameRes",后续加载的资源定位地址填写相对路径:"Audio/bgMusic" -var createParameters = new EditorSimulateModeParameters(); -createParameters.LocationServices = new DefaultLocationServices("Assets/GameRes"); -yield return defaultPackage.InitializeAsync(createParameters); -...... -YooAssets.LoadAssetAsync("Audio/bgMusic"); +package.LoadAssetAsync("Assets/GameRes/Audio/bgMusic"); ``` -- AddressLocationServices 可寻址资源定位服务,location代表的是资源对象可寻址地址。 +- 在开启可寻址模式下,location代表的是资源对象可寻址地址。 ````c# // 以工程内的音频文件为例:"Assets/GameRes/Audio/bgMusic.mp3" // 需要在资源配置界面启用可寻址功能(Enable Addressable)。 // 配置界面的可寻址规则为AddressByFileName,那么资源定位地址填写文件名称:"bgMusic" -var createParameters = new EditorSimulateModeParameters(); -createParameters.LocationServices = new AddressLocationServices(); -yield return defaultPackage.InitializeAsync(createParameters); -...... -YooAssets.LoadAssetAsync("bgMusic"); +package.LoadAssetAsync("bgMusic"); ```` -**注意**:以下范例执行环境是在DefaultLocationServices下。 - **加载路径的匹配方式** ````C# // 不带扩展名的模糊匹配 -YooAssets.LoadAssetAsync("Audio/bgMusic"); +package.LoadAssetAsync("Assets/GameRes/Audio/bgMusic"); // 带扩展名的精准匹配 -YooAssets.LoadAssetAsync("Audio/bgMusic.mp3"); +package.LoadAssetAsync("Assets/GameRes/Audio/bgMusic.mp3"); ```` **异步加载范例** @@ -56,7 +45,7 @@ YooAssets.LoadAssetAsync("Audio/bgMusic.mp3"); // 委托加载方式 void Start() { - AssetOperationHandle handle = YooAssets.LoadAssetAsync("Audio/bgMusic.mp3"); + AssetOperationHandle handle = package.LoadAssetAsync("Assets/GameRes/Audio/bgMusic.mp3"); handle.Completed += Handle_Completed; } void Handle_Completed(AssetOperationHandle handle) @@ -68,7 +57,7 @@ void Handle_Completed(AssetOperationHandle handle) // 协程加载方式 IEnumerator Start() { - AssetOperationHandle handle = YooAssets.LoadAssetAsync("Audio/bgMusic.mp3"); + AssetOperationHandle handle = package.LoadAssetAsync("Assets/GameRes/Audio/bgMusic.mp3"); yield return handle; AudioClip audioClip = handle.AssetObject as AudioClip; } @@ -77,7 +66,7 @@ IEnumerator Start() // Task加载方式 async void Start() { - AssetOperationHandle handle = YooAssets.LoadAssetAsync("Audio/bgMusic.mp3"); + AssetOperationHandle handle = package.LoadAssetAsync("Assets/GameRes/Audio/bgMusic.mp3"); await handle.Task; AudioClip audioClip = handle.AssetObject as AudioClip; } @@ -88,7 +77,7 @@ async void Start() ````C# IEnumerator Start() { - AssetOperationHandle handle = YooAssets.LoadAssetAsync("Audio/bgMusic.mp3"); + AssetOperationHandle handle = package.LoadAssetAsync("Assets/GameRes/Audio/bgMusic.mp3"); yield return handle; ... handle.Release(); @@ -114,7 +103,7 @@ private void UnloadAssets() ````C# IEnumerator Start() { - AssetOperationHandle handle = YooAssets.LoadAssetAsync("Panel/login.prefab"); + AssetOperationHandle handle = package.LoadAssetAsync("Assets/GameRes/Panel/login.prefab"); yield return handle; GameObject go = handle.InstantiateSync(); Debug.Log($"Prefab name is {go.name}"); @@ -128,7 +117,7 @@ IEnumerator Start() ````c# IEnumerator Start() { - SubAssetsOperationHandle handle = YooAssets.LoadSubAssetsAsync(location); + SubAssetsOperationHandle handle = package.LoadSubAssetsAsync(location); yield return handle; var sprite = handle.GetSubAssetObject("spriteName"); Debug.Log($"Sprite name is {sprite.name}"); @@ -142,9 +131,10 @@ IEnumerator Start() ````c# IEnumerator Start() { + string location = "Assets/GameRes/Scene/Login"; var sceneMode = UnityEngine.SceneManagement.LoadSceneMode.Single; bool activateOnLoad = true; - SceneOperationHandle handle = YooAssets.LoadSceneAsync("Scene/Login", sceneMode, activateOnLoad); + SceneOperationHandle handle = package.LoadSceneAsync(location, sceneMode, activateOnLoad); yield return handle; Debug.Log($"Scene name is {handle.Scene.name}"); } @@ -157,9 +147,9 @@ IEnumerator Start() ````c# IEnumerator Start() { - string location = "wwise/init.bnk"; + string location = "Assets/GameRes/wwise/init.bnk"; string copyPath = $"{Application.persistentDataPath}/Audio/init.bnk"; - RawFileOperation operation = YooAssets.GetRawFileAsync(location, copyPath); + RawFileOperation operation = package.GetRawFileAsync(location, copyPath); yield return operation; byte[] fileData = operation.GetFileData(); string fileText = operation.GetFileText(); @@ -173,7 +163,7 @@ IEnumerator Start() ````c# private GetAssetInfosByTag(string tag) { - AssetInfo[] assetInfos = YooAssets.GetAssetInfos(tag); + AssetInfo[] assetInfos = package.GetAssetInfos(tag); foreach (var assetInfo in assetInfos) { Debug.Log(assetInfo.AssetPath); diff --git a/Docs/CodeTutorial4.md b/Docs/CodeTutorial4.md index b245431..5147809 100644 --- a/Docs/CodeTutorial4.md +++ b/Docs/CodeTutorial4.md @@ -12,8 +12,9 @@ private List _handles = new List(100 private object LoadFunc(string name, string extension, System.Type type, out DestroyMethod method) { method = DestroyMethod.None; //注意:这里一定要设置为None - string location = $"FairyRes/{name}{extension}"; - var handle = YooAssets.LoadAssetSync(location , type); + string location = $"Assets/FairyRes/{name}{extension}"; + var assetPackage = YooAssets.GetAssetsPackage("DefaultPackage"); + var handle = assetPackage.LoadAssetSync(location , type); _handles.Add(handle); return handle.AssetObject; } @@ -43,7 +44,8 @@ private void ReleaseHandles() 代码示例 ```csharp -var handle = YooAssets.LoadAssetAsync("Assets/Res/Prefabs/TestImg.prefab"); +var assetPackage = YooAssets.GetAssetsPackage("DefaultPackage"); +var handle = assetPackage.LoadAssetAsync("Assets/Res/Prefabs/TestImg.prefab"); await handle.ToUniTask(); @@ -65,32 +67,30 @@ go.transform.localScale = Vector3.one; 在运行游戏之前,请保证资源包可以构建成功! ```c# -public static AssetPackage DefaultPackage; - IEnumerator Start() { // 初始化YooAssets资源系统(必须代码) YooAssets.Initialize(); // 创建资源包实例 - DefaultPackage = YooAssets.CreateAssetPackage("DefaultPackage"); + var package = YooAssets.CreateAssetPackage("DefaultPackage"); // 初始化资源包 ...... - yield return DefaultPackage.InitializeAsync(createParameters); + yield return package.InitializeAsync(createParameters); // 更新资源包版本 ...... - var operation = DefaultPackage.UpdateManifestAsync(packageCRC); + var operation = package.UpdateManifestAsync(packageCRC); yield return operation; // 下载更新文件 - var downloader = DefaultPackage.CreatePatchDownloader(downloadingMaxNum, failedTryAgain); + var downloader = package.CreatePatchDownloader(downloadingMaxNum, failedTryAgain); downloader.BeginDownload(); yield return downloader; // 加载资源对象 - var assetHandle = DefaultPackage.LoadAssetAsync("Assets/GameRes/npc.prefab"); + var assetHandle = package.LoadAssetAsync("Assets/GameRes/npc.prefab"); yield return assetHandle; ...... } diff --git a/Docs/FAQ.md b/Docs/FAQ.md index 315b243..50bea1a 100644 --- a/Docs/FAQ.md +++ b/Docs/FAQ.md @@ -32,7 +32,7 @@ internal class FsmClearCache : IFsmNode void IFsmNode.OnEnter() { Debug.Log("清理未使用的缓存文件!"); - var operation = YooAsset.YooAssets.ClearUnusedCacheFiles(); + var operation = YooAssets.ClearUnusedCacheFiles(); operation.Completed += Operation_Completed; }