Files
Convention-Unity-Demo/Assets/Scripts/LookAtAnchor.cs

55 lines
1.6 KiB
C#
Raw Normal View History

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