Files
Convention-Unity-Demo/Assets/Scripts/Environment/SkyUpdatement.cs

76 lines
2.1 KiB
C#
Raw Normal View History

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