67de857f8c
checkpoint: StreamingAsset Loader.
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
namespace OCES
|
|
{
|
|
public class AssetBundleAssetProvider : IAssetProvider
|
|
{
|
|
readonly AssetBundle m_assetBundle;
|
|
|
|
public AssetBundleAssetProvider(string bundleFilePath)
|
|
{
|
|
this.m_assetBundle = AssetBundle.LoadFromFile(bundleFilePath);
|
|
if (this.m_assetBundle is null)
|
|
{
|
|
Debug.LogError($"[OCES] 无法加载: {bundleFilePath}");
|
|
}
|
|
}
|
|
|
|
public T Load<T>(string path) where T : UnityEngine.Object
|
|
{
|
|
return this.m_assetBundle.LoadAsset<T>(path);
|
|
}
|
|
|
|
public void LoadAsync<T>(string path, MonoBehaviour coroutineHost, Action<T> onComplete) where T : UnityEngine.Object
|
|
{
|
|
coroutineHost.StartCoroutine(LoadAsyncCoroutine(path, onComplete));
|
|
}
|
|
|
|
IEnumerator LoadAsyncCoroutine<T>(string path, Action<T> onComplete) where T : UnityEngine.Object
|
|
{
|
|
AssetBundleRequest request = this.m_assetBundle.LoadAssetAsync<T>(path);
|
|
yield return request;
|
|
onComplete?.Invoke(request.asset as T);
|
|
}
|
|
}
|
|
}
|