using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cysharp.Threading.Tasks;
using ProjSG.Resource;
public class ShaderUtility
{
public static void InitGlobalParams()
{
Shader.SetGlobalColor("_Gbl_Lgt", new Color(0.8f, 0.8f, 0.8f, 1));
Shader.SetGlobalColor("_Gbl_Pnt", new Color(1, 1, 1, 1));
Shader.SetGlobalColor("_Gbl_Amb", new Color(1, 1, 1, 1));
Shader.SetGlobalColor("_Gbl_Spc", new Color(0.8f, 0.8f, 0.8f, 1));
Shader.SetGlobalColor("_Gbl_Rim", new Color(1, 1, 1, 1));
Shader.SetGlobalColor("_Gbl_Wat", new Color(1, 1, 1, 1));
}
[System.Obsolete("US2: Use WarmUpAllAsync. Sync loading removed. Final preload+cache pattern in T044.")]
public static void WarmUpAll()
{
// US2: Sync AB loading removed. Use WarmUpAllAsync instead.
#if !UNITY_EDITOR
Shader.WarmupAllShaders();
#endif
}
///
/// US2: Async shader warm up via YooAsset.
/// PackDirectory 规则下所有 shader 在同一个 bundle,
/// 通过 tag="shader" 拿到任意一个有效地址传给 LoadAllAssetsAsync 即可加载整包。
/// 前提:Collector 的 Asset Tags 填写 "shader" 并重新打 AB。
///
public static async UniTask WarmUpAllAsync()
{
if (AssetSource.isUseAssetBundle)
{
// 通过 tag 找到 shader bundle 内任意一个有效地址
var infos = YooAssetService.Instance.GetAssetInfosByTag("shader");
if (infos != null && infos.Length > 0)
{
// PackDirectory:所有 shader 在同一 bundle,传任意地址即可加载整包
await YooAssetService.Instance.LoadAllAssetsAsync(infos[0].Address);
}
else
{
Debug.LogWarning("[ShaderUtility] No asset infos found for tag 'shader'. " +
"Please set Asset Tags = 'shader' on the Shader collector in YooAsset and rebuild AB.");
}
}
#if !UNITY_EDITOR
Shader.WarmupAllShaders();
#endif
}
}