using UnityEngine; using XGame.Framework.Asset; using XGame.Framework.Asyncs; namespace XGame.Framework.Shaders { /// /// shader变体预热 /// ShaderVariantCollection /// internal class ShaderCollectionAsync : Async { private IAssetLoadAsync _async; public ShaderCollectionAsync(string addressableName) { if (string.IsNullOrEmpty(addressableName)) { Log.Error("ShaderCollectionAsync Name is null."); Completed(); return; } Log.Info($"ShaderCollectionAsync start. Name:{addressableName}"); _async = AssetManager.LoadAsync(addressableName); _async.On(OnLoaded); } private void OnLoaded(IAsync async) { _async = null; var result = async as IAssetLoadAsync; var collection = result?.Result; Log.Info($"ShaderCollectionAsync result:{collection != null} isWarmedUp:{collection?.isWarmedUp ?? false}"); collection?.WarmUp(); Completed(); if (collection) { AssetManager.Recycle(collection); } Log.Info("ShaderCollectionAsync completed."); } protected override void OnRemoveAll() { _async?.RemoveOn(OnLoaded); _async = null; } } }