using Convention; using Demo.Attr; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Demo.Game { [Scriptable] public class LookAtAnchor : Updatement { public static LookAtAnchor Make() { return new GameObject().AddComponent(); } protected override int Lerp(int begin, int end, float t) { return begin; } private readonly List LookAtCache = new(); [Content] public int LookAtObject; [Content] public bool IsEnableUpdateEveryTick = false; protected override void UpdateData(int data) { ScriptableObject target = LookAtCache[LookAtObject]; if (data != LookAtObject) { LookAtObject = data; if (target != null) transform.LookAt(target.transform); } else if (IsEnableUpdateEveryTick) { if (target != null) transform.LookAt(target.transform); } } /// /// 在指定时刻切换面向的物体,并尝试一次更新 /// [Convention.RScript.Variable.Attr.Method] public void Add(float time, ScriptableObject target) { LookAtCache.Add(target); ManualAddEntry(time, LookAtCache.Count - 1, default); } /// /// 启动自动更新,将持续锁定面向的物体并更新 /// [Convention.RScript.Variable.Attr.Method] public void EnableUpdateEveryTick() { IsEnableUpdateEveryTick = true; } } }