using System; using System.Collections.Generic; using System.Linq; using RosettaUI.Swatch; using UnityEngine.UIElements; namespace RosettaUI.UIToolkit { public abstract class SwatchSetFold : Foldout where TSwatch : SwatchBase, new() { // private const string PersistantKeyLayout = "Layout"; private const string PersistantKeyIsOpen = "IsOpen"; private readonly SwatchSetMenuAndTileView _swatchSetMenuAndTileView; public SwatchPersistentService PersistentService => _swatchSetMenuAndTileView.PersistentService; protected SwatchSetFold(string label, Action applyValueFunc, string dataKeyPrefix) { var toggle = this.Q(); _swatchSetMenuAndTileView = new SwatchSetMenuAndTileView(toggle, this, applyValueFunc, dataKeyPrefix); text = label; AddToClassList(SwatchSet.UssClassName); value = false; SetMenuVisible(false); this.RegisterValueChangedCallback(OnValueChanged); schedule.Execute(LoadStatus).ExecuteLater(32); } private void LoadStatus() { var isOpen = PersistentService.Get(PersistantKeyIsOpen); value = isOpen; _swatchSetMenuAndTileView.LoadStatus(); } public void SetValue(TValue currentValue) => _swatchSetMenuAndTileView.SetValue(currentValue); private void SetMenuVisible(bool v) => _swatchSetMenuAndTileView.SetMenuButtonVisible(v); private void OnValueChanged(ChangeEvent evt) { var isOpen = evt.newValue; SetMenuVisible(isOpen); PersistentService.Set(PersistantKeyIsOpen, isOpen); } } }