com.alicizax.unity.ui.exten.../Runtime/UXComponent/Controller/UXControllerStateRecorder.cs

48 lines
1.4 KiB
C#
Raw Normal View History

2025-12-01 16:44:19 +08:00
using System;
using System.Collections.Generic;
using UnityEngine;
2025-12-09 20:30:11 +08:00
namespace AlicizaX.UI
2025-12-01 16:44:19 +08:00
{
[DisallowMultipleComponent]
[AddComponentMenu("Controller/控制器状态")]
public class UXControllerStateRecorder : MonoBehaviour
{
[SerializeField] private int _id;
[SerializeField] private UXController _controller;
internal int ID => _id;
internal UXController Controller => _controller;
[Serializable]
public class StateEntry
{
[SerializeReference] public ControllerStateBase State = null;
public string ControllerName = string.Empty;
public int ControllerIndex = 0;
}
[SerializeField] private List<StateEntry> _stateEntries = new List<StateEntry>();
// private void Awake()
// {
// foreach (var entry in _stateEntries)
// {
// entry.State.Init(this);
// }
// }
internal void OnControllerIndexChanged(string controllerName, int selectedIndex)
{
var entrys = _stateEntries.FindAll(t => t.ControllerName.Equals(controllerName));
if (entrys != null)
{
foreach (var entry in entrys)
{
entry.State.Execute(this, entry.ControllerIndex, selectedIndex);
}
}
}
}
}