using System.Collections; using Convention; using UnityEngine; namespace Demo.Game { public class SkyUpdatement : Updatement, IAssetBundleLoader { public static SkyUpdatement Make() { return new GameObject().AddComponent(); } public string SkyAssetBundlePath; public AssetBundle SkyAssetBundle; protected override Material Lerp(Material begin, Material end, float t) { return begin; } [Content, SerializeField] private Material Cache; protected override void UpdateData(Material data) { if (string.IsNullOrEmpty(SkyAssetBundlePath)) return; if (Cache != data) { RenderSettings.skybox = data; Cache = data; } } public override IEnumerator UnloadScript() { Cache = null; if (string.IsNullOrEmpty(SkyAssetBundlePath) == false) yield return this.UnloadAssetBundle(SkyAssetBundlePath); SkyAssetBundlePath = ""; yield return base.UnloadScript(); } /// /// 对应ab包名称,自动匹配对应平台 /// /// [Convention.RScript.Variable.Attr.Method] public IEnumerator Load(string ab) { yield return this.LoadAssetBundle(ab, x => { SkyAssetBundlePath = ab; SkyAssetBundle = x; }); } /// /// 在指定时刻切换天空 /// /// /// [Convention.RScript.Variable.Attr.Method] public IEnumerator Add(float time, string sky) { var ir = SkyAssetBundle.LoadAssetAsync(sky); ir.completed += delegate { var mat = ir.asset as Material; ManualAddEntry(time, mat, default); }; yield return ir; } } }