2025-07-21 15:58:52 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace Convention.WindowsUI.Variant
|
|
|
|
{
|
|
|
|
public class FocusWindowIndictaor : MonoSingleton<FocusWindowIndictaor>
|
|
|
|
{
|
|
|
|
[Setting, Range(0, 1), Percentage(0, 1)] public float Speed = 0.36f;
|
|
|
|
[Resources, OnlyNotNullMode] public RectTransform RectBox;
|
2025-09-21 17:33:31 +08:00
|
|
|
[Resources, OnlyNotNullMode] public RectTransform TopParent;
|
2025-07-21 15:58:52 +08:00
|
|
|
[Resources] public List<RectTransform> Targets = new();
|
|
|
|
[Content] public int TargetIndex;
|
2025-09-21 17:33:31 +08:00
|
|
|
public RectTransform Target { get; private set; }
|
|
|
|
|
|
|
|
private Stack<ConventionUtility.ActionStepCoroutineWrapper> Tasks = new();
|
2025-07-21 15:58:52 +08:00
|
|
|
|
|
|
|
public void SetTargetRectTransform(RectTransform target)
|
|
|
|
{
|
2025-09-21 17:33:31 +08:00
|
|
|
if (target == null)
|
|
|
|
{
|
|
|
|
Target = null;
|
|
|
|
RectTransformInfo.UpdateAnimationPlane(TopParent, RectBox, Speed, 0, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConventionUtility.ActionStepCoroutineWrapper task = ConventionUtility.CreateSteps();
|
|
|
|
task.Next(() =>
|
|
|
|
{
|
|
|
|
if (gameObject.activeInHierarchy == false)
|
|
|
|
RectTransformInfo.UpdateAnimationPlane(TopParent, RectBox, 1, 0, true);
|
|
|
|
})
|
|
|
|
.Until(() => target.gameObject.activeInHierarchy == true && Tasks.Peek() == task, () => Target = target)
|
|
|
|
.Next(() => Tasks.TryPop(out var _))
|
|
|
|
.Invoke();
|
|
|
|
Tasks.Push(task);
|
|
|
|
}
|
2025-07-21 15:58:52 +08:00
|
|
|
}
|
|
|
|
public void SelectNextTarget()
|
|
|
|
{
|
|
|
|
Target = Targets[TargetIndex = (TargetIndex + 1) % Targets.Count];
|
|
|
|
}
|
|
|
|
|
2025-09-21 17:33:31 +08:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
if (TopParent == null)
|
|
|
|
TopParent = transform.parent as RectTransform;
|
|
|
|
}
|
|
|
|
|
2025-07-21 15:58:52 +08:00
|
|
|
private void LateUpdate()
|
|
|
|
{
|
|
|
|
if (Target != null)
|
|
|
|
RectTransformInfo.UpdateAnimationPlane(Target, RectBox, Speed, 0, true);
|
|
|
|
else
|
2025-09-21 17:33:31 +08:00
|
|
|
RectTransformInfo.UpdateAnimationPlane(TopParent, RectBox, Speed, 0, true);
|
2025-07-21 15:58:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|