WIP: Live mixing support.

checkpoint: StreamingAsset Loader.
This commit is contained in:
2026-05-18 19:25:09 +08:00
parent 3f0ff8b59d
commit 67de857f8c
7 changed files with 237 additions and 22 deletions
@@ -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
}
}
}
}