推进同化RScript

This commit is contained in:
2025-11-24 18:02:57 +08:00
parent fc8f48bc7e
commit 2e0d16db49
17 changed files with 400 additions and 864 deletions

View File

@@ -20,7 +20,7 @@ namespace Demo.Game
}
public int Content = 0;
public List<UpdatementEntry> Entries = new();
public readonly List<UpdatementEntry> Entries = new();
protected abstract void UpdateData(DataType data);
protected abstract DataType Lerp(DataType begin, DataType end, float t);
@@ -40,26 +40,15 @@ namespace Demo.Game
});
}
/// <summary>
/// 添加数据
/// </summary>
/// <param name="time"></param>
/// <param name="position"></param>
/// <param name="curveType"></param>
public void ManualAddEntry(string time, DataType position, MathExtension.EaseCurveType curveType)
{
ManualAddEntry(time, position, curveType);
}
private void UpdateEntry(int start, float percent)
{
UpdatementEntry head = Entries[start], tail = Entries[Mathf.Min(start + 1, Entries.Count - 1)];
UpdateData(Lerp(head.Position, tail.Position, MathExtension.Evaluate(Mathf.Clamp01(percent), head.easeCurveType)));
}
public override IEnumerator LoadScript(string script)
protected override IEnumerator DoSomethingDuringApplyScript()
{
yield return base.LoadScript(script);
yield return base.DoSomethingDuringApplyScript();
Entries.Sort((x, y) => x.TimePoint.CompareTo(y.TimePoint));
if (UpdateTarget == null)
{
@@ -76,9 +65,10 @@ namespace Demo.Game
public override IEnumerator UnloadScript()
{
Content = 0;
Entries = new();
Entries.Clear();
yield return base.UnloadScript();
}
protected override void UpdateTicks(float currentTime, float deltaTime, TickType tickType)
{
base.UpdateTicks(currentTime, deltaTime, tickType);
@@ -140,16 +130,12 @@ namespace Demo.Game
/// <summary>
/// 设置更新对象
/// </summary>
/// <param name="path">脚本的相对路径</param>
[Convention.RScript.Variable.Attr.Method]
public void SetUpdateTarget(string path)
public void SetUpdateTarget(ScriptableObject target)
{
var temp = FindWithPath(path);
if (temp != null)
UpdateTarget = temp.gameObject;
else
Debug.LogWarning($"{path}' is not found", this);
UpdateTarget = target.gameObject;
}
/// <summary>
///
/// </summary>
@@ -165,7 +151,6 @@ namespace Demo.Game
public interface ILocalUpdatement<DataType>: IScriptableObject
{
int Content { get; set; }
public List<ILocalUpdatementExtension.UpdatementEntry<DataType>> Entries { get; set; }
void UpdateData(DataType data);
@@ -182,11 +167,11 @@ namespace Demo.Game
public MathExtension.EaseCurveType easeCurveType = MathExtension.EaseCurveType.Linear;
}
public static void AddEntry<DataType>(this ILocalUpdatement<DataType> self, string time, DataType position, MathExtension.EaseCurveType curveType)
public static void AddEntry<DataType>(this ILocalUpdatement<DataType> self, float time, DataType position, MathExtension.EaseCurveType curveType)
{
self.Entries.Add(new()
{
TimePoint = self.SharedInterfaceScriptObject.Parse(time),
TimePoint = time,
Position = position,
easeCurveType = curveType
});