Files
Convention-Unity-Demo/Assets/Scripts/Volume/VolumeObject.cs
2025-12-15 17:20:55 +08:00

68 lines
2.0 KiB
C#

using Convention;
using Demo.Game.Attr;
using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.Rendering;
namespace Demo.Game
{
namespace ConfigType
{
// VolumeObject 配置
public class VolumeObjectConfig : BaseVolumeConfig
{
public string MyAssetBundle, MyProfile;
public override void Deserialize(BinaryReader reader)
{
MyAssetBundle = BinarySerializeUtility.ReadString(reader);
MyProfile = BinarySerializeUtility.ReadString(reader);
base.Deserialize(reader);
}
public override void Serialize(BinaryWriter writer)
{
BinarySerializeUtility.WriteString(writer, MyAssetBundle);
BinarySerializeUtility.WriteString(writer, MyProfile);
base.Serialize(writer);
}
}
}
[Scriptable]
public class VolumeObject : BaseVolume, IAssetBundleLoader
{
public static VolumeObject Make()
{
return new GameObject().AddComponent<VolumeObject>();
}
private bool IsLoading = false;
[Content, SerializeField] private string MyAssetBundle, MyProfile;
protected override IEnumerator DoSomethingDuringApplyScript()
{
yield return base.DoSomethingDuringApplyScript();
yield return new WaitUntil(() => !IsLoading);
if (MyVolume.profile == null)
{
MyVolume.profile = Resources.Load<VolumeProfile>("Volume/Default");
}
}
[Convention.RScript.Variable.Attr.Method]
public void Load(string ab, string profile)
{
IsLoading = true;
MyAssetBundle = ab;
MyProfile = profile;
ConventionUtility.StartCoroutine(this.LoadAssetBundle(ab, x =>
{
MyVolume.profile = x.LoadAsset<VolumeProfile>(profile);
IsLoading = false;
}));
}
}
}