forked from sin365/AxibugEmuOnline
74 lines
2.0 KiB
C#
74 lines
2.0 KiB
C#
using DG.Tweening;
|
|
using DG.Tweening.Core;
|
|
using DG.Tweening.Plugins.Options;
|
|
using UnityEngine;
|
|
|
|
namespace AxibugEmuOnline.Client
|
|
{
|
|
public class Selector : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Animator animator;
|
|
private RectTransform m_rect => transform as RectTransform;
|
|
|
|
private RectTransform m_target;
|
|
private TweenerCore<Vector3, Vector3, VectorOptions> m_trackTween;
|
|
|
|
public RectTransform Target
|
|
{
|
|
get => m_target;
|
|
set
|
|
{
|
|
if (m_target == value) return;
|
|
|
|
m_target = value;
|
|
|
|
var itemUIRect = m_target.transform as RectTransform;
|
|
m_rect.pivot = itemUIRect.pivot;
|
|
m_rect.sizeDelta = itemUIRect.rect.size;
|
|
m_rect.SetAsLastSibling();
|
|
|
|
animator.SetTrigger("reactive");
|
|
|
|
if (m_trackTween != null)
|
|
{
|
|
m_trackTween.Kill();
|
|
m_trackTween = null;
|
|
}
|
|
m_trackTween = DOTween.To(() => m_rect.position, (value) => m_rect.position = value, itemUIRect.position, 0.125f);
|
|
m_trackTween.onComplete = () => m_trackTween = null;
|
|
}
|
|
}
|
|
|
|
private bool m_active;
|
|
public bool Active
|
|
{
|
|
get => m_active;
|
|
set
|
|
{
|
|
if (m_active == value) return;
|
|
m_active = value;
|
|
|
|
animator.SetBool("active", value);
|
|
}
|
|
}
|
|
|
|
public void RefreshPosition()
|
|
{
|
|
if (Target != null)
|
|
{
|
|
m_rect.position = Target.position;
|
|
}
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (m_trackTween != null && m_trackTween.endValue != Target.position)
|
|
{
|
|
m_trackTween.ChangeEndValue(Target.position, true);
|
|
}
|
|
if (Target == null) return;
|
|
}
|
|
}
|
|
}
|