WIP: Live mixing support.
checkpoint: StreamingAsset Loader.
This commit is contained in:
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using OCES.Audio;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -57,34 +56,40 @@ namespace OCES
|
||||
}
|
||||
|
||||
this.m_pendingCallbacks[path] = new List<Action<Object>> { obj => onComplete?.Invoke(obj as T) };
|
||||
ResourceRequest newRequest;
|
||||
|
||||
if (this.m_assetProvider is not null)
|
||||
{
|
||||
newRequest = this.m_assetProvider.LoadAsync<T>(path);
|
||||
this.m_assetProvider.LoadAsync<T>(path, this, asset =>
|
||||
{
|
||||
OnAsyncAssetLoaded(path, asset as Object);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
newRequest = Resources.LoadAsync<T>(path);
|
||||
Debug.LogWarning($"[ResourceLoader] No IAssetProvider set, falling back to Resources.Load for '{path}'");
|
||||
StartCoroutine(FallbackLoadAsyncCoroutine<T>(path));
|
||||
}
|
||||
|
||||
StartCoroutine(HandleAsyncLoadCompletion(path, newRequest));
|
||||
}
|
||||
|
||||
IEnumerator HandleAsyncLoadCompletion(string path, ResourceRequest request)
|
||||
IEnumerator FallbackLoadAsyncCoroutine<T>(string path) where T : Object
|
||||
{
|
||||
ResourceRequest request = Resources.LoadAsync<T>(path);
|
||||
yield return request;
|
||||
OnAsyncAssetLoaded(path, request.asset);
|
||||
}
|
||||
|
||||
if (request.asset)
|
||||
void OnAsyncAssetLoaded(string path, Object asset)
|
||||
{
|
||||
if (asset)
|
||||
{
|
||||
this.m_cachedObjects[path] = request.asset;
|
||||
this.m_cachedObjects[path] = asset;
|
||||
}
|
||||
|
||||
if (this.m_pendingCallbacks.Remove(path, out List<Action<Object>> callbacks))
|
||||
{
|
||||
foreach (Action<Object> callback in callbacks)
|
||||
{
|
||||
callback?.Invoke(request.asset);
|
||||
callback?.Invoke(asset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,4 +109,4 @@ namespace OCES
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user