yyl
9 天以前 51b0f6ed9f4e1d3bb6f8144470b46908c7699a96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
    }
 
    /// <summary>
    /// US2: Async shader warm up via YooAsset.
    /// PackDirectory 规则下所有 shader 在同一个 bundle,
    /// 通过 tag="shader" 拿到任意一个有效地址传给 LoadAllAssetsAsync 即可加载整包。
    /// 前提:Collector 的 Asset Tags 填写 "shader" 并重新打 AB。
    /// </summary>
    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<Shader>(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
    }
 
 
}