Improve prize configurator navigation and settings input repeat

This commit is contained in:
Сергей Бондарь 2026-08-25 14:12:09 +03:00
parent 0cfd38da13
commit 2a526be85f
4 changed files with 114 additions and 12 deletions

View File

@ -1841,6 +1841,17 @@ RectTransform:
m_CorrespondingSourceObject: {fileID: 4098477273951441249, guid: dcef42dd0beb95f4e9b230192966f091, type: 3}
m_PrefabInstance: {fileID: 3117238291046753179}
m_PrefabAsset: {fileID: 0}
--- !u!114 &141381090 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7716801100805455212, guid: dcef42dd0beb95f4e9b230192966f091, type: 3}
m_PrefabInstance: {fileID: 3117238291046753179}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 141381088}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1bf3043857e54fd41b0d39086cd9c3be, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::CharacterPrizeConfigurator
--- !u!1 &143058077
GameObject:
m_ObjectHideFlags: 0
@ -18836,7 +18847,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1967587903
RectTransform:
m_ObjectHideFlags: 0
@ -18908,6 +18919,7 @@ MonoBehaviour:
switchAxis: 1
interactAxis: 0
intractButton: 4
_switchRepeatInterval: 0.2
_rootRect: {fileID: 1967587903}
Content: {fileID: 1843853773}
_scrollBar: {fileID: 1450075491}
@ -18926,6 +18938,7 @@ MonoBehaviour:
_textInputPrefab: {fileID: 5157268599116440676, guid: dc7d2a24b5df54040b311e8c0c43261e, type: 3}
_canvas: {fileID: 1967587903}
_settingsScreen: {fileID: 1967587905}
_prizesConfigurator: {fileID: 141381090}
--- !u!114 &1967587907
MonoBehaviour:
m_ObjectHideFlags: 0
@ -22504,7 +22517,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 5423109734219761443, guid: dcef42dd0beb95f4e9b230192966f091, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []

View File

@ -3,13 +3,17 @@ using PrizeSystem;
using System;
using UnityEngine;
public class CharacterPrizeConfigurator : MonoBehaviour
public class CharacterPrizeConfigurator : MonoBehaviour, IControlable
{
public event Action OnClosed;
[SerializeField] private CharacterSelectionPanel _characterSelection;
[SerializeField] private PrizesSelector _prizesSelector;
private IControlable _activePanel;
public bool ControlsEnabled { get; set; } = true;
private void Awake()
{
_characterSelection.OnCharacterSelected += OpenPrizeSelector;
@ -34,11 +38,29 @@ public class CharacterPrizeConfigurator : MonoBehaviour
_prizesSelector.OnConfirmed -= OpenCharacterSelection;
}
public void Open()
{
if (gameObject.activeSelf)
{
OpenCharacterSelection();
return;
}
gameObject.SetActive(true);
}
public void UpdateControls()
{
if (_activePanel != null && _activePanel.ControlsEnabled)
_activePanel.UpdateControls();
}
private void OpenPrizeSelector(Character character)
{
_characterSelection.gameObject.SetActive(false);
_prizesSelector.Open(character);
ControlsPerformer.Instance.SetControlable(_prizesSelector);
_activePanel = _prizesSelector;
SetSelfAsControlable();
}
private void OpenCharacterSelection()
@ -46,9 +68,8 @@ public class CharacterPrizeConfigurator : MonoBehaviour
_prizesSelector.gameObject.SetActive(false);
_characterSelection.gameObject.SetActive(true);
_characterSelection.Open();
if (ControlsPerformer.Instance != null)
ControlsPerformer.Instance.SetControlable(_characterSelection);
_activePanel = _characterSelection;
SetSelfAsControlable();
}
private void SaveAndClose()
@ -62,4 +83,10 @@ public class CharacterPrizeConfigurator : MonoBehaviour
gameObject.SetActive(false);
OnClosed?.Invoke();
}
private void SetSelfAsControlable()
{
if (ControlsPerformer.Instance != null)
ControlsPerformer.Instance.SetControlable(this);
}
}

View File

@ -6,7 +6,17 @@ public class SettingFunctions : MonoBehaviour
[SerializeField] private TextInput _textInputPrefab;
[SerializeField] private RectTransform _canvas;
[SerializeField] private SettingsScreen _settingsScreen;
[SerializeField] private CharacterPrizeConfigurator _prizesConfigurator;
private void Awake()
{
_prizesConfigurator.OnClosed += ReturnToSettings;
}
private void OnDestroy()
{
_prizesConfigurator.OnClosed -= ReturnToSettings;
}
public void ResetBalance() => PaymentSystem.ResetBalance();
@ -14,7 +24,8 @@ public class SettingFunctions : MonoBehaviour
public void ConfigurePrizes()
{
_prizesConfigurator.Open();
ControlsPerformer.Instance.SetControlable(_prizesConfigurator);
}
public void EnterNumberAdmin()
@ -98,4 +109,10 @@ public class SettingFunctions : MonoBehaviour
{
}
}
private void ReturnToSettings()
{
_settingsScreen.BlockControls();
ControlsPerformer.Instance.SetControlable(_settingsScreen);
}
}

View File

@ -22,6 +22,7 @@ public class SettingsScreen : MonoBehaviour, IControlable
[SerializeField] private Axis switchAxis = Axis.Vertical;
[SerializeField] private Axis interactAxis = Axis.Horizontal;
[SerializeField] private PlayerAction intractButton = PlayerAction.action;
[SerializeField] private float _switchRepeatInterval = 0.2f;
[SerializeField] private RectTransform _rootRect;
[SerializeField] private RectTransform Content;
@ -30,6 +31,8 @@ public class SettingsScreen : MonoBehaviour, IControlable
private HoldTimer _exitTimer;
public bool ControlsEnabled { get; set; } = false;
private bool controlsBlocked = false;
private int _heldSwitchDirection;
private float _nextSwitchTime;
private void Start()
{
@ -41,6 +44,7 @@ public class SettingsScreen : MonoBehaviour, IControlable
private void OnDisable()
{
_exitTimer.Reset();
ResetSwitchRepeat();
}
public void UpdateControls()
@ -49,10 +53,12 @@ public class SettingsScreen : MonoBehaviour, IControlable
controlsBlocked = false;
if (controlsBlocked)
{
ResetSwitchRepeat();
return;
}
Vector2Int switchAxes = In.GetAxis(JoystickSide.Both, InteractMode.Discrete);
int switchDirection = -GetAxisValue(switchAxes, switchAxis);
int switchDirection = GetSwitchDirection();
if (switchDirection != 0)
SwitchSetting(switchDirection);
@ -84,7 +90,11 @@ public class SettingsScreen : MonoBehaviour, IControlable
ControlsEnabled = true;
}
public void BlockControls() => controlsBlocked = true;
public void BlockControls()
{
controlsBlocked = true;
ResetSwitchRepeat();
}
private void SwitchSetting(int switchDirection)
{
@ -95,6 +105,41 @@ public class SettingsScreen : MonoBehaviour, IControlable
UpdatePointer();
}
private int GetSwitchDirection()
{
Vector2Int switchAxes = In.GetAxis(JoystickSide.Both, InteractMode.Continious);
int switchDirection = -GetAxisValue(switchAxes, switchAxis);
return UpdateSwitchRepeat(switchDirection, Time.unscaledTime);
}
private int UpdateSwitchRepeat(int switchDirection, float currentTime)
{
if (switchDirection == 0)
{
ResetSwitchRepeat();
return 0;
}
if (switchDirection != _heldSwitchDirection)
{
_heldSwitchDirection = switchDirection;
_nextSwitchTime = currentTime + _switchRepeatInterval;
return switchDirection;
}
if (currentTime < _nextSwitchTime)
return 0;
_nextSwitchTime = currentTime + _switchRepeatInterval;
return switchDirection;
}
private void ResetSwitchRepeat()
{
_heldSwitchDirection = 0;
_nextSwitchTime = 0f;
}
private void UpdatePointer()
{