Updatement数据优化, 性能优化

This commit is contained in:
2025-12-02 15:26:41 +08:00
parent 716a23fad2
commit f3f13f7051
4 changed files with 122 additions and 145 deletions

View File

@@ -5,32 +5,36 @@ using UnityEngine;
namespace Demo.Game
{
public class LookAtAnchor : Updatement<ScriptableObject>
public class LookAtAnchor : Updatement<int>
{
public static LookAtAnchor Make()
{
return new GameObject().AddComponent<LookAtAnchor>();
}
protected override ScriptableObject Lerp(ScriptableObject begin, ScriptableObject end, float t)
protected override int Lerp(int begin, int end, float t)
{
return begin;
}
[Content] public ScriptableObject LookAtObject;
private readonly List<ScriptableObject> LookAtCache = new();
[Content] public int LookAtObject;
[Content] public bool IsEnableUpdateEveryTick = false;
protected override void UpdateData(ScriptableObject data)
protected override void UpdateData(int data)
{
ScriptableObject target = LookAtCache[LookAtObject];
if (data != LookAtObject)
{
LookAtObject = data;
transform.LookAt(LookAtObject.transform);
if (target != null)
transform.LookAt(target.transform);
}
else if (IsEnableUpdateEveryTick)
{
if (LookAtObject != null)
transform.LookAt(LookAtObject.transform);
if (target != null)
transform.LookAt(target.transform);
}
}
@@ -40,7 +44,8 @@ namespace Demo.Game
[Convention.RScript.Variable.Attr.Method]
public void Add(float time, ScriptableObject target)
{
ManualAddEntry(time, target, default);
LookAtCache.Add(target);
ManualAddEntry(time, LookAtCache.Count - 1, default);
}
/// <summary>