// ***********************************************************************
// Assembly : Unity
// Author : Kimch
// Created :
//
// Last Modified By : Kimch
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
//#if UNITY_EDITOR
//#define USE_ASSETDATABASE
//#endif
//#define USE_ASSETBUNDLE
//#define USE_RESOURCE
#define USE_ADDRESSABLES
namespace G
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using Object = UnityEngine.Object;
#region INTERFACE
public interface IAsyncR
{
/// Gets a value indicating whether this is done.
bool done
{
get;
}
/// Gets the error.
string error
{
get;
}
/// Gets or sets the progress.
float progress
{
get;
}
/// Gets or sets the data.
object asyncData
{
get;
}
/// Gets the asset bundle.
AssetBundle assetBundle
{
get;
}
}
#endregion
///
///
///
partial class AssetProxy : F.GameProxy
{
private const string GLOBAL_ASSET_POOL_NAME = "global";
private const string TEMPORARY_ASSET_POOL_NAME = "temporary";
private const string INSTANCES_POOL_NAME = "instances";
#region Model
private class AsyncR : IAsyncR
{
#region Field
///
///
///
private float _progress;
///
///
///
private string _error;
///
///
///
private object _data;
#endregion
#region Property
bool IAsyncR.done
{
get
{
return _progress > 1f;
}
}
string IAsyncR.error
{
get
{
return _error;
}
}
float IAsyncR.progress
{
get
{
return _progress;
}
}
object IAsyncR.asyncData
{
get
{
return _data;
}
}
AssetBundle IAsyncR.assetBundle
{
get
{
return _data as AssetBundle;
}
}
#endregion
#region Method
public void AsyncProcess(float progress)
{
_progress = progress;
_error = null;
_data = null;
}
public void AsyncSuccess(object data)
{
_progress = 1.0001f;
_error = null;
_data = data;
}
public void AsyncFailure(string error)
{
_progress = 1.0001f;
_error = error;
_data = null;
}
#endregion
}
#endregion
#region FIELD
///
/// 异步加载回调
///
private AsyncR _asyncR = new AsyncR();
///
///
///
private Dictionary _persistentAssets = new Dictionary(StringComparer.OrdinalIgnoreCase);
///
///
///
private Dictionary _temporaryAssets = new Dictionary(StringComparer.OrdinalIgnoreCase);
#endregion
#region Proxy
///
///
///
public override int priority
{
get { return int.MaxValue; }
}
///
/// 已经初始化
///
public bool initialized
{
get;
private set;
}
public override void Init()
{
#if USE_ADDRESSABLES
Addressables.InitializeAsync().Completed += (handle) =>
{
this.initialized = true;
KUIBind.Bind(null, this.UIAsyncInstantiater, this.UIReleaser);
};
#elif USE_ASSETBUNDLE
F.KFramework.ResourceManager.InitResources((errorMsg) =>
{
if (string.IsNullOrEmpty(errorMsg))
{
initialized = true;
}
});
#else
this.initialized = true;
#endif
CreateReleasePool(INSTANCES_POOL_NAME);
CreateReleasePool(GLOBAL_ASSET_POOL_NAME);
}
///
///
///
///
public override Task LoadAsync()
{
Preload();
return TryGetGlobalAssetsAsync