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