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