//使用async-await加载
private async void Initialize1()
{
Task task = ResourceManager.instance.LoadTask("Assets/AssetBundle/UI/UIRoot.prefab");
await task;
GameObject uiRoot = task.Result.Instantiate();
uiRoot.name = task.Result.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);
}