70 lines
1.9 KiB
C#
70 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Convention;
|
|
using UnityEngine;
|
|
|
|
namespace Demo.Game
|
|
{
|
|
public class LookAtAnchor : Updatement<string>
|
|
{
|
|
public static LookAtAnchor Make()
|
|
{
|
|
return new GameObject().AddComponent<LookAtAnchor>();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在指定时刻切换面向的物体,并尝试一次更新
|
|
/// </summary>
|
|
/// <param name="time"></param>
|
|
/// <param name="target">对象相对路径,不存在时将解除锁定</param>
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void Add(string time, string target)
|
|
{
|
|
ManualAddEntry(time, target, default);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启动自动更新,将持续锁定面向的物体并更新
|
|
/// </summary>
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void EnableUpdateEveryTick()
|
|
{
|
|
IsEnableUpdateEveryTick = true;
|
|
}
|
|
}
|
|
} |