AxibugEmuOnline/AxibugEmuOnline.Client/Assets/Script/UI/Selector.cs

55 lines
1.6 KiB
C#
Raw Normal View History

using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using UnityEngine;
namespace AxibugEmuOnline.Client
{
public class Selector : MonoBehaviour
{
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;
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>α<EFBFBD><CEB1>Ķ<EFBFBD><C4B6><EFBFBD>
gameObject.SetActive(false);
gameObject.SetActive(true);
var itemUIRect = m_target.transform as RectTransform;
m_rect.pivot = itemUIRect.pivot;
m_rect.sizeDelta = itemUIRect.rect.size;
m_rect.SetAsLastSibling();
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 void LateUpdate()
{
if (m_trackTween != null)
{
m_trackTween.endValue = Target.position;
}
if (Target == null) return;
m_rect.position = Target.position;
}
}
}