Files
Convention-Unity/Convention/[Visual]/UIComponent/Variant/FocusWindowIndictaor.cs

59 lines
2.1 KiB
C#
Raw Normal View History

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;
[Resources, OnlyNotNullMode] public RectTransform TopParent;
2025-07-21 15:58:52 +08:00
[Resources] public List<RectTransform> Targets = new();
[Content] public int TargetIndex;
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)
{
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];
}
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
RectTransformInfo.UpdateAnimationPlane(TopParent, RectBox, Speed, 0, true);
2025-07-21 15:58:52 +08:00
}
}
}