新增volume更新器

This commit is contained in:
2025-12-12 15:54:16 +08:00
parent ddf38a88b6
commit a3ea09c2a9
13 changed files with 158 additions and 5 deletions

View File

@@ -60,6 +60,14 @@ namespace Demo.Game
return false;
return ConventionUtility.PushValue(component, value, name, BindingFlags.Public | BindingFlags.Instance);
}
public bool TrySetOverrideField<FieldType>(string type, string name, FieldType value)
{
var component = GetOverride(type);
if (component == null)
return false;
return ConventionUtility.PushValue(component, value, name, BindingFlags.Public | BindingFlags.Instance);
}
}
public abstract class BaseForSingleVolume<T> : BaseVolume where T : VolumeComponent

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6817d5ed5f3f2ba46b718a0003027dee
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
using Convention;
using Demo.Attr;
using System.Collections;
using UnityEngine;
namespace Demo.Game
{
public abstract class BaseVolumeUpdatement<T> : Updatement<T> where T : unmanaged
{
[Content, SerializeField] private BaseVolume target;
[Content, SerializeField] private string updateOverride;
[Content, SerializeField] private string updateField;
protected override IEnumerator DoSomethingDuringApplyScript()
{
yield return base.DoSomethingDuringApplyScript();
if (target == null)
{
target = this.UpdateTarget.SeekComponent<BaseVolume>();
}
}
protected override void UpdateData(T data)
{
target.TrySetOverrideField<T>(updateOverride, updateField, data);
}
[Convention.RScript.Variable.Attr.Method]
public void SetUpdateOverrideAndField(string updateOverride, string updateField)
{
this.updateOverride = updateOverride;
this.updateField = updateField;
}
/// <summary>
/// 新增
/// </summary>
/// <param name="time">插值时间</param>
/// <param name="value">值</param>
/// <param name="curveType">缓动曲线</param>
[Convention.RScript.Variable.Attr.Method]
public void Add(float time, T value, MathExtension.EaseCurveType curveType)
{
ManualAddEntry(time, value, curveType);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3310713d1026b944facb4c172ad38bb1

View File

@@ -0,0 +1,21 @@
using Convention;
using Demo.Attr;
using System.Collections;
using UnityEngine;
namespace Demo.Game
{
[Scriptable]
public class VolumeFloatUpdatement : BaseVolumeUpdatement<float>
{
public static VolumeFloatUpdatement Make()
{
return new GameObject().AddComponent<VolumeFloatUpdatement>();
}
protected override float Lerp(float begin, float end, float t)
{
return Mathf.Lerp(begin, end, t);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6b3813d5ec8404345bcbd745281e2671

View File

@@ -0,0 +1,19 @@
using Demo.Attr;
using UnityEngine;
namespace Demo.Game
{
[Scriptable]
public class VolumeIntUpdatement : BaseVolumeUpdatement<int>
{
public static VolumeIntUpdatement Make()
{
return new GameObject().AddComponent<VolumeIntUpdatement>();
}
protected override int Lerp(int begin, int end, float t)
{
return Mathf.FloorToInt(Mathf.Lerp(begin, end, t));
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 600cb8d3ed5900d4baa30e5d8aafa66e

View File

@@ -0,0 +1,40 @@
using Convention;
using Demo.Attr;
using System.Collections;
using UnityEngine;
using UnityEngine.Rendering;
namespace Demo.Game
{
[Scriptable]
public class VolumeObject : BaseVolume, IAssetBundleLoader
{
public static VolumeObject Make()
{
return new GameObject().AddComponent<VolumeObject>();
}
[Content, SerializeField] private bool IsLoading = false;
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;
ConventionUtility.StartCoroutine(this.LoadAssetBundle(ab, x =>
{
MyVolume.profile = x.LoadAsset<VolumeProfile>(profile);
IsLoading = false;
}));
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6905b41c61f830c4fac86087660118e4