2025-12-12 15:19:10 +08:00
|
|
|
using Convention;
|
2025-12-15 17:20:55 +08:00
|
|
|
using Demo.Game.Attr;
|
2025-12-18 15:11:33 +08:00
|
|
|
using Demo.Game.ConfigType;
|
2025-12-19 17:33:20 +08:00
|
|
|
using System.IO;
|
2025-09-25 19:04:05 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Demo.Game
|
|
|
|
|
{
|
2025-12-19 17:33:20 +08:00
|
|
|
namespace ConfigType
|
|
|
|
|
{
|
|
|
|
|
public class LookAtAnchorConfig : UpdatementIntConfig
|
|
|
|
|
{
|
|
|
|
|
[Content] public bool IsEnableUpdateEveryTick = false;
|
|
|
|
|
public override void Deserialize(BinaryReader reader)
|
|
|
|
|
{
|
|
|
|
|
IsEnableUpdateEveryTick = BinarySerializeUtility.ReadBool(reader);
|
|
|
|
|
base.Deserialize(reader);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Serialize(BinaryWriter writer)
|
|
|
|
|
{
|
|
|
|
|
BinarySerializeUtility.WriteBool(writer, IsEnableUpdateEveryTick);
|
|
|
|
|
base.Serialize(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-12 15:19:10 +08:00
|
|
|
[Scriptable]
|
2025-12-02 15:26:41 +08:00
|
|
|
public class LookAtAnchor : Updatement<int>
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
2025-12-18 15:11:33 +08:00
|
|
|
protected override ScriptLoadableConfig MakeConfig()
|
|
|
|
|
{
|
|
|
|
|
return new UpdatementIntConfig();
|
|
|
|
|
}
|
2025-09-25 19:04:05 +08:00
|
|
|
public static LookAtAnchor Make()
|
|
|
|
|
{
|
|
|
|
|
return new GameObject().AddComponent<LookAtAnchor>();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-02 15:26:41 +08:00
|
|
|
protected override int Lerp(int begin, int end, float t)
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
|
|
|
|
return begin;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 17:33:20 +08:00
|
|
|
public int LookAtObjectCache;
|
|
|
|
|
public bool IsEnableUpdateEveryTick
|
|
|
|
|
{
|
|
|
|
|
get => GetConfig<LookAtAnchorConfig>().IsEnableUpdateEveryTick;
|
|
|
|
|
set => GetConfig<LookAtAnchorConfig>().IsEnableUpdateEveryTick = value;
|
|
|
|
|
}
|
2025-09-25 19:04:05 +08:00
|
|
|
|
2025-12-02 15:26:41 +08:00
|
|
|
protected override void UpdateData(int data)
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
2025-12-16 17:54:51 +08:00
|
|
|
ScriptableObject target = GetRoot().FindWithIndex(data);
|
2025-12-19 17:33:20 +08:00
|
|
|
if (data != LookAtObjectCache)
|
2025-09-25 19:04:05 +08:00
|
|
|
{
|
2025-12-19 17:33:20 +08:00
|
|
|
LookAtObjectCache = data;
|
2025-12-02 15:26:41 +08:00
|
|
|
if (target != null)
|
|
|
|
|
transform.LookAt(target.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
|
|
|
{
|
2025-12-02 15:26:41 +08:00
|
|
|
if (target != null)
|
|
|
|
|
transform.LookAt(target.transform);
|
2025-09-25 19:04:05 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 在指定时刻切换面向的物体,并尝试一次更新
|
|
|
|
|
/// </summary>
|
2025-10-27 20:24:15 +08:00
|
|
|
[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
|
|
|
{
|
2025-12-17 15:50:03 +08:00
|
|
|
ManualAddEntry(time, GetRoot().FindIndex(target), default);
|
2025-09-25 19:04:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启动自动更新,将持续锁定面向的物体并更新
|
|
|
|
|
/// </summary>
|
2025-10-27 20:24:15 +08:00
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
2025-09-25 19:04:05 +08:00
|
|
|
public void EnableUpdateEveryTick()
|
|
|
|
|
{
|
|
|
|
|
IsEnableUpdateEveryTick = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|