50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
// ReSharper disable MemberCanBePrivate.Global
|
|
|
|
namespace BITKit.UX
|
|
{
|
|
public class UXGroup : MonoBehaviour,IActivable
|
|
{
|
|
[SerializeField] private UIDocument document;
|
|
[SerializeField] private string[] groupNames;
|
|
[SerializeField] private string entryName;
|
|
|
|
private Dictionary<string, VisualElement> group;
|
|
private void Awake()
|
|
{
|
|
group = new Dictionary<string, VisualElement>(groupNames.Select(x => new KeyValuePair<string, VisualElement>(x, document.rootVisualElement.Q(x))));
|
|
Entry(entryName);
|
|
}
|
|
public void Entry(string visualElementName)
|
|
{
|
|
foreach (var x in group)
|
|
{
|
|
if (x.Value is null)
|
|
{
|
|
BIT4Log.Warning<UXGroup>($"{x.Key} is null");
|
|
}
|
|
else
|
|
{
|
|
x.Value.SetActive(false);
|
|
}
|
|
}
|
|
if (group.TryGetValue(visualElementName, out var value))
|
|
{
|
|
value.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void SetActive(bool active) => document.rootVisualElement.SetActive(active);
|
|
|
|
public bool Enabled
|
|
{
|
|
get => document.rootVisualElement.GetActive();
|
|
set=> document.rootVisualElement.SetActive(value);
|
|
}
|
|
}
|
|
}
|
|
|