Files

50 lines
1.3 KiB
C#
Raw Permalink Normal View History

using System.Collections.Generic;
using UnityEngine;
public class BaseTogglesGroup : MonoBehaviour
{
[SerializeField] private BaseToggle _initialActiveToggle = default;
[SerializeField] private List<BaseToggle> _toggles = default;
2023-08-05 23:39:25 +03:00
public BaseToggle ActiveToggle { get; set; }
public bool LockPage { get; set; }
private void Awake() => ActiveToggle = _initialActiveToggle;
public void CheckToggles()
{
2023-08-28 02:38:39 +03:00
if (_toggles.Count > 0)
for (int i = 0; i < _toggles.Count; i++)
_toggles[i].ResetToggle();
}
2023-09-25 16:24:19 +03:00
public void CheckHover(BaseToggle baseToggle)
{
if (_toggles.Count > 0)
for (int i = 0; i < _toggles.Count; i++)
if (_toggles[i] != baseToggle)
_toggles[i].ResetHover();
}
public void AddToggle(BaseToggle toggle) => _toggles.Add(toggle);
public void NextPage()
{
if (LockPage)
return;
int index = _toggles.FindIndex(a => a == ActiveToggle) + 1;
if (index > _toggles.Count - 1)
index = 0;
_toggles[index].Activate();
}
public void PreviousPage()
{
if (LockPage)
return;
int index = _toggles.FindIndex(a => a == ActiveToggle) - 1;
if (index < 0)
index = _toggles.Count - 1;
_toggles[index].Activate();
}
}