51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
using Michsky.UI.Heat;
|
|
using Obvious.Soap;
|
|
using UnityEngine;
|
|
|
|
public class BindIntVariableToHorizontalSelector : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private IntVariable _IntToCheck;
|
|
|
|
[SerializeField]
|
|
private bool _CheckOnEnable;
|
|
|
|
[SerializeField]
|
|
private HorizontalSelector _HorizontalSelector;
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (_CheckOnEnable)
|
|
{
|
|
UpdateSelector();
|
|
}
|
|
_IntToCheck.OnValueChanged += CheckValue;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
_IntToCheck.OnValueChanged -= CheckValue;
|
|
}
|
|
|
|
private void CheckValue(int value)
|
|
{
|
|
UpdateSelector();
|
|
}
|
|
|
|
private void UpdateSelector()
|
|
{
|
|
if ((bool)_HorizontalSelector && _HorizontalSelector.index != _IntToCheck.Value)
|
|
{
|
|
if (_HorizontalSelector.saveSelected)
|
|
{
|
|
PlayerPrefs.DeleteKey("HorizontalSelector_" + _HorizontalSelector.saveKey);
|
|
}
|
|
_HorizontalSelector.defaultIndex = _IntToCheck.Value;
|
|
_HorizontalSelector.InitializeSelector();
|
|
_HorizontalSelector.UpdateContentLayout();
|
|
_HorizontalSelector.items[_HorizontalSelector.index].onItemSelect.Invoke();
|
|
_HorizontalSelector.onValueChanged.Invoke(_HorizontalSelector.index);
|
|
}
|
|
}
|
|
}
|