using System.Collections; using System.Collections.Generic; using Convention; using UnityEngine; namespace Demo.Game { public class LookAtAnchor : Updatement { public static LookAtAnchor Make() { return new GameObject().AddComponent(); } protected override string Lerp(string begin, string end, float t) { return begin; } [Content, SerializeField] private string Cache; [Content] public ScriptableObject LookAtObject; [Content] public bool IsEnableUpdateEveryTick = false; protected override void UpdateData(string data) { if (Cache != data) { LookAtObject = FindWithPath(data, false); Cache = data; Foo(); } if (IsEnableUpdateEveryTick) { Foo(); } void Foo() { if (LookAtObject != null) transform.LookAt(LookAtObject.transform); } } public override IEnumerator UnloadScript() { Cache = null; yield return base.UnloadScript(); } /// /// 在指定时刻切换面向的物体,并尝试一次更新 /// /// /// 对象相对路径,不存在时将解除锁定 [Convention.RScript.Variable.Attr.Method] public void Add(string time, string target) { ManualAddEntry(time, target, default); } /// /// 启动自动更新,将持续锁定面向的物体并更新 /// [Convention.RScript.Variable.Attr.Method] public void EnableUpdateEveryTick() { IsEnableUpdateEveryTick = true; } } }