//使用async-await加载
private async void Initialize1()
{
ResourceAwaiter awaiter = ResourceManager.instance.LoadWithAwaiter("Assets/AssetBundle/UI/UIRoot.prefab");
await awaiter;
GameObject uiRoot = awaiter.GetResult().Instantiate();
uiRoot.name = awaiter.GetResult().GetAsset().name;
}
//使用协程加载
private IEnumerator Initialize2()
{
IResource resource = ResourceManager.instance.Load("Assets/AssetBundle/UI/UIRoot.prefab", true);
yield return resource;
resource.Instantiate();
}
//使用回调加载
private void Initialize3()
{
ResourceManager.instance.LoadWithCallback("Assets/AssetBundle/UI/UIRoot.prefab", true, resource =>
{
GameObject uiRoot = resource.Instantiate();
uiRoot.name = resource.GetAsset().name;
});
}
//使用同步加载
private void Initialize4()
{
IResource resource = ResourceManager.instance.Load("Assets/AssetBundle/UI/UIRoot.prefab", false);
GameObject uiRoot = resource.Instantiate();
uiRoot.name = resource.GetAsset().name;
}
//同步加载并释放资源
private void Initialize5()
{
IResource resource = ResourceManager.instance.Load("Assets/AssetBundle/UI/UIRoot.prefab", false);
ResourceManager.instance.Unload(resource);
}
//先异步加载资源,然后同步加载资源,最后释放
private void Initialize6()
{
IResource resource1 = ResourceManager.instance.Load("Assets/AssetBundle/UI/UIRoot.prefab", true);
IResource resource2 = ResourceManager.instance.Load("Assets/AssetBundle/UI/UIRoot.prefab", false);
ResourceManager.instance.Unload(resource1);
ResourceManager.instance.Unload(resource2);
}
//先同步加载资源,然后异步加载资源,最后释放
private void Initialize7()
{
IResource resource1 = ResourceManager.instance.Load("Assets/AssetBundle/UI/UIRoot.prefab", false);
IResource resource2 = ResourceManager.instance.Load("Assets/AssetBundle/UI/UIRoot.prefab", true);
ResourceManager.instance.Unload(resource1);
ResourceManager.instance.Unload(resource2);
}
-
Notifications
You must be signed in to change notification settings - Fork 10
liufujingwen/ResourceFramework
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Unity AssetBundle
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published