Update document

pull/4/head
hevinci 2022-03-23 14:58:24 +08:00
parent 6f6ecf845a
commit 02f9e7979a
1 changed files with 27 additions and 39 deletions

View File

@ -2,13 +2,14 @@
在加载资源对象的时候只需要提供相对路径统一约定该相对路径名称为location 在加载资源对象的时候只需要提供相对路径统一约定该相对路径名称为location
资源加载接口: 加载接口:
- YooAssets.LoadAssetSync() 同步加载资源对象接口 - YooAssets.LoadAssetSync() 同步加载资源对象接口
- YooAssets.LoadSubAssetsSync() 同步加载子资源对象接口 - YooAssets.LoadSubAssetsSync() 同步加载子资源对象接口
- YooAssets.LoadAssetAsync() 异步加载资源对象接口 - YooAssets.LoadAssetAsync() 异步加载资源对象接口
- YooAssets.LoadSubAssetsAsync() 异步加载子资源对象接口 - YooAssets.LoadSubAssetsAsync() 异步加载子资源对象接口
- YooAssets.LoadSceneAsync() 异步加载场景接口 - YooAssets.LoadSceneAsync() 异步加载场景接口
- YooAssets.LoadRawFileAsync() 异步读取原生文件接口
**加载路径的匹配方式** **加载路径的匹配方式**
@ -64,54 +65,51 @@ async Task AsyncLoad()
**资源卸载范例** **资源卸载范例**
````C# ````C#
void Start() IEnumerator Start()
{ {
AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3"); AssetOperationHandle handle = YooAssets.LoadAssetAsync<AudioClip>("Audio/bgMusic.mp3");
yield return handle;
... ...
handle.Release(); handle.Release();
} }
```` ````
**预制体同步加载范例** **预制体加载范例**
````C# ````C#
var handle = YooAssets.LoadAssetSync<GameObject>(location); IEnumerator Start()
GameObject go = handle.InstantiateObject; {
AssetOperationHandle handle = YooAssets.LoadAssetAsync<GameObject>("Panel/login.prefab");
yield return handle;
GameObject go = handle.InstantiateSync();
Debug.Log($"Prefab name is {go.name}");
}
```` ````
````c# **子对象加载范例**
var handle = YooAssets.LoadAssetSync<GameObject>(location);
GameObject go = UnityEngine.Object.Instantiate(handle.AssetObject as GameObject);
````
**子对象同步加载范例**
例如通过TexturePacker创建的图集如果需要访问图集的精灵对象可以通过子对象加载接口。 例如通过TexturePacker创建的图集如果需要访问图集的精灵对象可以通过子对象加载接口。
````c# ````c#
var handle = YooAssets.LoadSubAssetsSync<Sprite>(location); IEnumerator Start()
foreach (var asset in handle.AllAssets)
{ {
Debug.Log($"Sprite name is {asset.name}"); SubAssetsOperationHandle handle = YooAssets.LoadSubAssetsAsync<Sprite>(location);
yield return handle;
var sprite = handle.GetSubAssetObject<Sprite>("spriteName");
Debug.Log($"Sprite name is {sprite.name}");
} }
```` ````
**场景异步加载范例** **场景异步加载范例**
````c# ````c#
void Start() IEnumerator Start()
{ {
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 = YooAssets.LoadSceneAsync("Scene/Login", sceneMode, activateOnLoad);
handle.Completed += Handle_Completed; yield return handle;
} Debug.Log($"Scene name is {handle.Scene.name}");
void Handle_Completed(SceneOperationHandle handle)
{
Debug.Log(handle.Scene.name);
} }
```` ````
@ -120,24 +118,14 @@ void Handle_Completed(SceneOperationHandle handle)
例如wwise的初始化文件 例如wwise的初始化文件
````c# ````c#
void Start() IEnumerator Start()
{ {
//获取资源包信息
string location = "wwise/init.bnk"; string location = "wwise/init.bnk";
BundleInfo bundleInfo = YooAssets.GetBundleInfo(location); string savePath = $"{Application.persistentDataPath}/Audio/init.bnk"
RawFileOperation operation = YooAssets.LoadRawFileAsync(location, savePath);
//文件路径 yield return operation;
string fileSourcePath = bundleInfo.LocalPath; byte[] fileData = operation.GetFileData();
string fileDestPath = $"{Application.persistentDataPath}/Audio/init.bnk"; string fileText = operation.GetFileText();
//拷贝文件
File.Copy(fileSourcePath, fileDestPath, true);
//注意在安卓平台下可以通过如下方法判断文件是否在APK内部。
if(bundleInfo.IsBuildinJarFile())
{
...
}
} }
```` ````