Использовать полную иконку персонажа и крестик для пустого приза. Добавить звук переключения, указатели выбора и анимацию добавленных призов за 0,3 секунды. Скрывать экран настроек на время работы с конфигуратором призов. Восстановить ссылку на префаб добавленного приза и оформить контекстные окна по макетам. Устранить повторное подтверждение QR-приза и исправить направление вертикальной навигации витрины. Проверено в Unity в режиме игры: ввод и сохранение значений, добавление и удаление пяти типов призов, анимация выбора и защита от повторного добавления. Ошибок в консоли нет.
313 lines
9.9 KiB
C#
313 lines
9.9 KiB
C#
using PrizeSystem;
|
||
using UnityEngine;
|
||
|
||
public class SettingFunctions : MonoBehaviour
|
||
{
|
||
[SerializeField] private TextInput _textInputPrefab;
|
||
[SerializeField] private RectTransform _canvas;
|
||
[SerializeField] private SettingsScreen _settingsScreen;
|
||
[SerializeField] private GameObject[] _settingsVisualsToHide;
|
||
[SerializeField] private CharacterPrizeConfigurator _prizesConfigurator;
|
||
[SerializeField] private ScreenTestPanel _screenTestPanelPrefab;
|
||
[SerializeField] private InputTestPanel _inputTestPanelPrefab;
|
||
[SerializeField] private SettingsPasswordPanel _passwordPanelPrefab;
|
||
[SerializeField] private MachineCountersPanel _countersPanelPrefab;
|
||
[SerializeField] private PrizeStockPanel _prizeStockPanelPrefab;
|
||
[SerializeField] private QrTestPanel _qrTestPanelPrefab;
|
||
[SerializeField] private AudioClip _qrTestUnavailableClip;
|
||
[SerializeField] private AudioClip[] _soundTestReplicas;
|
||
|
||
private ScreenTestPanel _activeScreenTestPanel;
|
||
private InputTestPanel _activeInputTestPanel;
|
||
private SettingsPasswordPanel _activePasswordPanel;
|
||
private MachineCountersPanel _activeCountersPanel;
|
||
private PrizeStockPanel _activePrizeStockPanel;
|
||
private QrTestPanel _activeQrTestPanel;
|
||
private bool[] _settingsVisualStates;
|
||
|
||
private void Awake()
|
||
{
|
||
_prizesConfigurator.OnClosed += ReturnToSettings;
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
_prizesConfigurator.OnClosed -= ReturnToSettings;
|
||
|
||
if (_activeScreenTestPanel != null)
|
||
_activeScreenTestPanel.OnClosed -= CloseScreenTest;
|
||
|
||
if (_activeInputTestPanel != null)
|
||
_activeInputTestPanel.OnClosed -= CloseInputTest;
|
||
|
||
if (_activePasswordPanel != null)
|
||
{
|
||
_activePasswordPanel.OnAccepted -= ClosePasswordPanel;
|
||
_activePasswordPanel.OnCancelled -= ClosePasswordPanel;
|
||
}
|
||
|
||
if (_activeCountersPanel != null)
|
||
_activeCountersPanel.OnClosed -= CloseCountersPanel;
|
||
|
||
if (_activePrizeStockPanel != null)
|
||
_activePrizeStockPanel.OnClosed -= ClosePrizeStockPanel;
|
||
|
||
if (_activeQrTestPanel != null)
|
||
_activeQrTestPanel.OnClosed -= CloseQrTest;
|
||
}
|
||
|
||
public void ResetBalance() => PaymentSystem.ResetBalance();
|
||
|
||
public void ResetPrizeError() => PrizeSystemManager.SetPrizingError(false);
|
||
|
||
public void ConfigurePrizes()
|
||
{
|
||
HideSettingsVisuals();
|
||
_prizesConfigurator.Open();
|
||
ControlsPerformer.Instance.SetControlable(_prizesConfigurator);
|
||
}
|
||
|
||
public void EnterNumberAdmin()
|
||
{
|
||
string oldNumber = PlayerPrefs.GetString(PrefsKeyVault.NUMBER_ADMIN);
|
||
|
||
var textInput = Instantiate(_textInputPrefab, _canvas);
|
||
textInput.Initialize(11, Alphabets.DIGITS, oldNumber);
|
||
ControlsPerformer.Instance.SetControlable(textInput);
|
||
|
||
textInput.OnComplete += (result) =>
|
||
{
|
||
PlayerPrefs.SetString(PrefsKeyVault.NUMBER_ADMIN, result);
|
||
SettingsManager.TriggerSettingsChanged();
|
||
_settingsScreen.BlockControls();
|
||
ControlsPerformer.Instance.SetControlable(_settingsScreen);
|
||
Destroy(textInput.gameObject);
|
||
};
|
||
}
|
||
|
||
public void EnterNumberSupport()
|
||
{
|
||
string oldNumber = PlayerPrefs.GetString(PrefsKeyVault.NUMBER_SUPPORT);
|
||
|
||
var textInput = Instantiate(_textInputPrefab, _canvas);
|
||
textInput.Initialize(11, Alphabets.DIGITS, oldNumber);
|
||
ControlsPerformer.Instance.SetControlable(textInput);
|
||
|
||
textInput.OnComplete += (result) =>
|
||
{
|
||
PlayerPrefs.SetString(PrefsKeyVault.NUMBER_SUPPORT, result);
|
||
SettingsManager.TriggerSettingsChanged();
|
||
_settingsScreen.BlockControls();
|
||
ControlsPerformer.Instance.SetControlable(_settingsScreen);
|
||
Destroy(textInput.gameObject);
|
||
};
|
||
}
|
||
|
||
public void ScreenTest()
|
||
{
|
||
if (_activeScreenTestPanel != null)
|
||
return;
|
||
|
||
_activeScreenTestPanel = Instantiate(_screenTestPanelPrefab, _canvas);
|
||
_activeScreenTestPanel.OnClosed += CloseScreenTest;
|
||
_settingsScreen.BlockControls();
|
||
ControlsPerformer.Instance.SetControlable(_activeScreenTestPanel);
|
||
_activeScreenTestPanel.Open();
|
||
}
|
||
|
||
public void InputTest()
|
||
{
|
||
if (_activeInputTestPanel != null)
|
||
return;
|
||
|
||
_activeInputTestPanel = Instantiate(_inputTestPanelPrefab, _canvas);
|
||
_activeInputTestPanel.OnClosed += CloseInputTest;
|
||
_settingsScreen.BlockControls();
|
||
ControlsPerformer.Instance.SetControlable(_activeInputTestPanel);
|
||
_activeInputTestPanel.Open();
|
||
}
|
||
|
||
public void SoundTest()
|
||
{
|
||
if (SoundManager.instance == null)
|
||
{
|
||
Debug.LogWarning("SoundManager не инициализирован");
|
||
return;
|
||
}
|
||
|
||
if (_soundTestReplicas == null || _soundTestReplicas.Length == 0)
|
||
{
|
||
Debug.LogWarning("Не заданы реплики для теста звука");
|
||
return;
|
||
}
|
||
|
||
int firstReplicaIndex = Random.Range(0, _soundTestReplicas.Length);
|
||
|
||
for (int offset = 0; offset < _soundTestReplicas.Length; offset++)
|
||
{
|
||
AudioClip replica = _soundTestReplicas[(firstReplicaIndex + offset) % _soundTestReplicas.Length];
|
||
|
||
if (replica == null)
|
||
continue;
|
||
|
||
SoundManager.instance.PlaySfx(replica);
|
||
return;
|
||
}
|
||
|
||
Debug.LogWarning("В списке теста звука нет назначенных реплик");
|
||
}
|
||
|
||
public void HopperTest()
|
||
{
|
||
var prize = PrizeUtils.CreatePrize(CountablePrizeType.Hopper, 1);
|
||
PrizeSystemManager.GivePrize(prize);
|
||
}
|
||
|
||
public void QrTest()
|
||
{
|
||
if (_activeQrTestPanel != null)
|
||
return;
|
||
|
||
_activeQrTestPanel = Instantiate(_qrTestPanelPrefab, _canvas);
|
||
|
||
if (_activeQrTestPanel.Initialize() == false)
|
||
{
|
||
Destroy(_activeQrTestPanel.gameObject);
|
||
_activeQrTestPanel = null;
|
||
|
||
if (SoundManager.instance != null)
|
||
SoundManager.instance.PlaySfx(_qrTestUnavailableClip);
|
||
|
||
return;
|
||
}
|
||
|
||
_activeQrTestPanel.OnClosed += CloseQrTest;
|
||
_settingsScreen.BlockControls();
|
||
ControlsPerformer.Instance.SetControlable(_activeQrTestPanel);
|
||
}
|
||
|
||
public void SetPassword()
|
||
{
|
||
if (_activePasswordPanel != null)
|
||
return;
|
||
|
||
_activePasswordPanel = Instantiate(_passwordPanelPrefab, _canvas);
|
||
_activePasswordPanel.OnAccepted += ClosePasswordPanel;
|
||
_activePasswordPanel.OnCancelled += ClosePasswordPanel;
|
||
_settingsScreen.BlockControls();
|
||
ControlsPerformer.Instance.SetControlable(_activePasswordPanel);
|
||
_activePasswordPanel.OpenForPasswordChange();
|
||
}
|
||
|
||
public void ResetPassword()
|
||
{
|
||
SettingsPasswordStore.Reset();
|
||
_settingsScreen.BlockControls();
|
||
}
|
||
|
||
public void OpenCounters()
|
||
{
|
||
if (_activeCountersPanel != null)
|
||
return;
|
||
|
||
_activeCountersPanel = Instantiate(_countersPanelPrefab, _canvas);
|
||
_activeCountersPanel.OnClosed += CloseCountersPanel;
|
||
_settingsScreen.BlockControls();
|
||
ControlsPerformer.Instance.SetControlable(_activeCountersPanel);
|
||
_activeCountersPanel.Open();
|
||
}
|
||
|
||
public void OpenPrizesRest()
|
||
{
|
||
if (_activePrizeStockPanel != null)
|
||
return;
|
||
|
||
_activePrizeStockPanel = Instantiate(_prizeStockPanelPrefab, _canvas);
|
||
_activePrizeStockPanel.OnClosed += ClosePrizeStockPanel;
|
||
_settingsScreen.BlockControls();
|
||
ControlsPerformer.Instance.SetControlable(_activePrizeStockPanel);
|
||
_activePrizeStockPanel.Open();
|
||
}
|
||
|
||
private void HideSettingsVisuals()
|
||
{
|
||
if (_settingsVisualStates != null)
|
||
return;
|
||
|
||
_settingsVisualStates = new bool[_settingsVisualsToHide.Length];
|
||
for (int i = 0; i < _settingsVisualsToHide.Length; i++)
|
||
{
|
||
GameObject visual = _settingsVisualsToHide[i];
|
||
_settingsVisualStates[i] = visual.activeSelf;
|
||
visual.SetActive(false);
|
||
}
|
||
}
|
||
|
||
private void RestoreSettingsVisuals()
|
||
{
|
||
if (_settingsVisualStates == null)
|
||
return;
|
||
|
||
for (int i = 0; i < _settingsVisualsToHide.Length; i++)
|
||
_settingsVisualsToHide[i].SetActive(_settingsVisualStates[i]);
|
||
|
||
_settingsVisualStates = null;
|
||
}
|
||
|
||
private void ReturnToSettings()
|
||
{
|
||
RestoreSettingsVisuals();
|
||
_settingsScreen.BlockControls();
|
||
ControlsPerformer.Instance.SetControlable(_settingsScreen);
|
||
}
|
||
|
||
private void CloseScreenTest()
|
||
{
|
||
_activeScreenTestPanel.OnClosed -= CloseScreenTest;
|
||
Destroy(_activeScreenTestPanel.gameObject);
|
||
_activeScreenTestPanel = null;
|
||
ReturnToSettings();
|
||
}
|
||
|
||
private void CloseInputTest()
|
||
{
|
||
_activeInputTestPanel.OnClosed -= CloseInputTest;
|
||
Destroy(_activeInputTestPanel.gameObject);
|
||
_activeInputTestPanel = null;
|
||
ReturnToSettings();
|
||
}
|
||
|
||
private void ClosePasswordPanel()
|
||
{
|
||
_activePasswordPanel.OnAccepted -= ClosePasswordPanel;
|
||
_activePasswordPanel.OnCancelled -= ClosePasswordPanel;
|
||
Destroy(_activePasswordPanel.gameObject);
|
||
_activePasswordPanel = null;
|
||
ReturnToSettings();
|
||
}
|
||
|
||
private void CloseCountersPanel()
|
||
{
|
||
_activeCountersPanel.OnClosed -= CloseCountersPanel;
|
||
Destroy(_activeCountersPanel.gameObject);
|
||
_activeCountersPanel = null;
|
||
ReturnToSettings();
|
||
}
|
||
|
||
private void ClosePrizeStockPanel()
|
||
{
|
||
_activePrizeStockPanel.OnClosed -= ClosePrizeStockPanel;
|
||
Destroy(_activePrizeStockPanel.gameObject);
|
||
_activePrizeStockPanel = null;
|
||
ReturnToSettings();
|
||
}
|
||
|
||
private void CloseQrTest()
|
||
{
|
||
_activeQrTestPanel.OnClosed -= CloseQrTest;
|
||
Destroy(_activeQrTestPanel.gameObject);
|
||
_activeQrTestPanel = null;
|
||
ReturnToSettings();
|
||
}
|
||
}
|