62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using Convention;
|
|
using Demo.Attr;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Demo.Game
|
|
{
|
|
[Scriptable]
|
|
public class LookAtAnchor : Updatement<int>
|
|
{
|
|
public static LookAtAnchor Make()
|
|
{
|
|
return new GameObject().AddComponent<LookAtAnchor>();
|
|
}
|
|
|
|
protected override int Lerp(int begin, int end, float t)
|
|
{
|
|
return begin;
|
|
}
|
|
|
|
private readonly List<ScriptableObject> 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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在指定时刻切换面向的物体,并尝试一次更新
|
|
/// </summary>
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void Add(float time, ScriptableObject target)
|
|
{
|
|
LookAtCache.Add(target);
|
|
ManualAddEntry(time, LookAtCache.Count - 1, default);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启动自动更新,将持续锁定面向的物体并更新
|
|
/// </summary>
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void EnableUpdateEveryTick()
|
|
{
|
|
IsEnableUpdateEveryTick = true;
|
|
}
|
|
}
|
|
} |