Проработка настроек

- Переходы из и в меню
- Триггер изменения настроек
- Сохранение настроек при выходе
This commit is contained in:
Сергей Бондарь 2026-08-21 10:35:04 +03:00
parent 07be95d901
commit d284694456
21 changed files with 222 additions and 6292 deletions

View File

@ -15,7 +15,8 @@ MonoBehaviour:
Type: 1
Id: MusicVolume
Alias: "\u0413\u0440\u043E\u043C\u043A\u043E\u0441\u0442\u044C \u043C\u0443\u0437\u044B\u043A\u0438"
Description:
Description: "\u0420\u0435\u0433\u0443\u043B\u0438\u0440\u0443\u0435\u0442 \u0433\u0440\u043E\u043C\u043A\u043E\u0441\u0442\u044C
\u043C\u0443\u0437\u044B\u043A\u0438 \u0432 \u0438\u0433\u0440\u0435"
BoolValue: 0
IntValue: 0
IntMin: 0

File diff suppressed because it is too large Load Diff

View File

@ -27,8 +27,8 @@ public class Bootstrap : MonoBehaviour
[SerializeField] private Menu menu;
[SerializeField] private SettingsScheme defaultSettings;
[SerializeField] private SettingViewSet _settingViews;
//[SerializeField] private SettingsScreen _settingsScreen;
private void Awake() => Initialize();
@ -40,6 +40,7 @@ public class Bootstrap : MonoBehaviour
SettingsManager.Initialize(defaultSettings);
SettingViewsProvider.Inject(_settingViews);
//_settingsScreen.Generate();
soundManager.Initialize();

View File

@ -62,26 +62,22 @@ public class SoundManager : MonoBehaviour
}
try//todo: переделать этот бред ебаный
{
switchEffectClip = switchEffectPrefab.GetComponent<AudioSource>().clip;
switchEffectDuration = switchEffectClip.length;
//switchEffectClip = switchEffectPrefab.GetComponent<AudioSource>().clip;
//switchEffectDuration = switchEffectClip.length;
player1LandClip = Player1Land.GetComponent<AudioSource>().clip;
player1LandDuration = player1LandClip.length;
//player1LandClip = Player1Land.GetComponent<AudioSource>().clip;
//player1LandDuration = player1LandClip.length;
player2LandClip = Player2Land.GetComponent<AudioSource>().clip;
player2LandDuration = player2LandClip.length;
//player2LandClip = Player2Land.GetComponent<AudioSource>().clip;
//player2LandDuration = player2LandClip.length;
PaymentSystem.onCoinAdded += playAddCoin;
PaymentSystem.onCoinRemoved += playRemoveCoin;
PaymentSystem.OnNotEnoughMoney += playNoMoney;
PaymentSystem.onCoinAdded += playAddCoin;
PaymentSystem.onCoinRemoved += playRemoveCoin;
PaymentSystem.OnNotEnoughMoney += playNoMoney;
ApplySettings();
SettingsManager.OnSettingsChanged += ApplySettings;
ApplySettings();
SettingsManager.OnSettingsChanged += ApplySettings;
}
catch { }
}
private void InitializeAudioPool()
@ -105,7 +101,7 @@ public class SoundManager : MonoBehaviour
public void ApplySettings()
{
//print("Применяем настройки звука");
print("Применяем настройки звука");
MusicVolume = SettingsManager.GetFloat(SettingKey.MUSIC_VOLUME);
PromoVolume = SettingsManager.GetFloat(SettingKey.PROMO_VOLUME);
@ -182,7 +178,7 @@ public class SoundManager : MonoBehaviour
}
public void playDropDown()
{
// Используем пул объектов вместо создания новых
GameObject effect = GetPooledAudioObject();
@ -197,7 +193,7 @@ public class SoundManager : MonoBehaviour
//audioSource.pitch = 1 + Random.Range(0, 2) * 0.6f;
audioSource.pitch = GameManager.Instance.currentPlayer == Team.Player1 ? 1 : 1.3f;
audioSource.volume = effectsVolume;
effect.SetActive(true);
audioSource.Play();

View File

@ -9,6 +9,7 @@ public class Menu : MonoBehaviour, IControlable
[SerializeField] private float _timeToPromo = 180f;
[SerializeField] private float _timeToSettings = 1f;
[SerializeField] private MenuPromoTransit _menuPromoTransit;
[SerializeField] private MenuSettingsTransit _menuSettingsTransit;
private HoldTimer _promoTimer;
private HoldTimer _settingsTimer;
@ -22,7 +23,7 @@ public class Menu : MonoBehaviour, IControlable
//переход настройки
if (_settingsTimer.Update(In.GetButton(InSignal.secret)))
{
print("ТУТ БУДЕТ ПЕРЕХОД В НАСТРОЙКИ");
_menuSettingsTransit.GotoSettings();
return;
}

View File

@ -17,6 +17,11 @@ public static class SettingsManager
LoadSettings(defaultSchemeAsset);
}
public static void TriggerSettingsChanged()
{
OnSettingsChanged?.Invoke();
}
#region Load/Save/Restore
private static void LoadSettings(SettingsScheme defaultSchemeAsset)
{

View File

@ -3,8 +3,9 @@ using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class SettingsScreen : MonoBehaviour
public class SettingsScreen : MonoBehaviour, IControlable
{
[SerializeField] private MenuSettingsTransit _menuSettingsTransit;
[Header("Ссылки")]
[SerializeField] private SettingGroup GroupPrefab;
@ -22,45 +23,42 @@ public class SettingsScreen : MonoBehaviour
[SerializeField] private Axis interactAxis = Axis.Horizontal;
[SerializeField] private PlayerAction intractButton = PlayerAction.action;
[SerializeField] private RectTransform _rootRect;
[SerializeField] private RectTransform Content;
[SerializeField] RectTransform _scrollBar;
private BaseSettingView SelectedSetting => settings[activeSettingIndex];
private HoldTimer _exitTimer;
public bool ControlsEnabled { get; set; } = false;
private void Start()
{
print("Start settings");
Generate();
UpdatePointer();
}
private void Update()
private void OnDisable()
{
_exitTimer.Reset();
}
public void UpdateControls()
{
int switchDirection = -In.GetAxis(switchAxis, JoystickSide.Both);
if (switchDirection != 0)
{
SelectedSetting.Deselect();
activeSettingIndex = (activeSettingIndex + switchDirection + settings.Count) % settings.Count;
SelectedSetting.Select();
_description.text = SelectedSetting.CachedSetting.Description;
UpdatePointer();
}
if (switchDirection != 0)
SwitchSetting(switchDirection);
int interactDirection = In.GetAxis(interactAxis, JoystickSide.Both, InteractMode.Continious);
bool action = In.GetButtonAnyPlayer(PlayerAction.action);
SelectedSetting.TakeInput(interactDirection, action);
if(_exitTimer.Update(In.GetButton(InSignal.secret)))
{
_menuSettingsTransit.GotoMenu();
}
}
private void UpdatePointer()
{
var activePivot = SelectedSetting.pivotPoint;
ScrollToElementVertical(activePivot);
_testPointer.position = activePivot.position;
_pointerCG.alpha = SelectedSetting is SignalView ? 0 : 1;
_scrollBar.anchoredPosition = new Vector2(0, -460f * activeSettingIndex / (settings.Count-1));
}
public void Generate()
{
ClearContent();
@ -69,7 +67,30 @@ public class SettingsScreen : MonoBehaviour
foreach (var group in SettingsManager.currentSchemeDTO.groups)
settings.AddRange(GenerateGroup(group).settings);
activeSettingIndex = 0;
_exitTimer = new HoldTimer(1);
ControlsEnabled = true;
}
private void SwitchSetting(int switchDirection)
{
SelectedSetting.Deselect();
activeSettingIndex = (activeSettingIndex + switchDirection + settings.Count) % settings.Count;
SelectedSetting.Select();
_description.text = SelectedSetting.CachedSetting.Description;
UpdatePointer();
}
private void UpdatePointer()
{
var activePivot = SelectedSetting.pivotPoint;
ScrollToElementVertical(activePivot);
_testPointer.position = activePivot.position;
_pointerCG.alpha = SelectedSetting is SignalView ? 0 : 1;
_scrollBar.anchoredPosition = new Vector2(0, -460f * activeSettingIndex / (settings.Count-1));
}
private SettingGroup GenerateGroup(SettingsGroupDTO groupData)
@ -85,25 +106,13 @@ public class SettingsScreen : MonoBehaviour
Destroy(Content.GetChild(i).gameObject);
}
public void ScrollToElementVertical(RectTransform targetRect)
private void ScrollToElementVertical(RectTransform targetRect)
{
if (scrollRect == null || targetRect == null)
{
Debug.LogWarning("ScrollRect или Target не назначены");
return;
}
LayoutRebuilder.ForceRebuildLayoutImmediate(scrollRect.content);
RectTransform viewport = scrollRect.viewport;
RectTransform content = scrollRect.content;
if (viewport == null || content == null)
{
Debug.LogWarning("Viewport или Content не назначены");
return;
}
Vector2 targetLocalPos = content.InverseTransformPoint(targetRect.position);
Vector2 viewportLocalPos = content.InverseTransformPoint(viewport.position);

View File

@ -26,7 +26,7 @@ public class BoolView : BaseSettingView
Value = newValue;
CachedSetting.BoolValue = Value;
_toggle.SetValue(Value);
SettingsManager.TriggerSettingsChanged();
}
}

View File

@ -30,11 +30,16 @@ public class FloatView : BaseSettingView
if (direction == 0)
return;
value += step * Mathf.Sign(direction) * _speed * Time.deltaTime;
value = Mathf.Clamp(value, minValue, maxValue);
CachedSetting.FloatValue = value;
var newValue = value + step * Mathf.Sign(direction) * _speed * Time.deltaTime;
newValue = Mathf.Clamp(newValue, minValue, maxValue);
_slider.SetValue(value);
if (newValue != value)
{
value = newValue;
_slider.SetValue(value);
CachedSetting.FloatValue = value;
SettingsManager.TriggerSettingsChanged();
}
}
private void Display()

View File

@ -31,5 +31,6 @@ public class IntView : BaseSettingView
{
CachedSetting.IntValue = newValue;
Source.PlayOneShot(SwitchClip);
SettingsManager.TriggerSettingsChanged();
}
}

View File

@ -21,5 +21,6 @@ public class StringView : BaseSettingView
{
CachedSetting.StringValue = newValue;
SoundManager.instance.playClip(SwitchClip);
SettingsManager.TriggerSettingsChanged();
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4f3a390463683e042972f497d0f6c863
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,20 @@
using UnityEngine;
public class MenuSettingsTransit : MonoBehaviour
{
[SerializeField] private Menu _menu;
[SerializeField] private SettingsScreen _settingsScreen;
public void GotoSettings()
{
_settingsScreen.gameObject.SetActive(true);
ControlsPerformer.Instance.SetControlable(_settingsScreen);
}
public void GotoMenu()
{
_settingsScreen.gameObject.SetActive(false);
SettingsManager.SaveSettings();
ControlsPerformer.Instance.SetControlable(_menu);
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 80bf6467a76a7c841b21f3469a26450b

View File

@ -76,8 +76,8 @@ MonoBehaviour:
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4278190080
m_fontColor: {r: 0, g: 0, b: 0, a: 1}
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
@ -199,7 +199,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Image
m_Material: {fileID: 0}
m_Color: {r: 0.690566, g: 0.690566, b: 0.690566, a: 1}
m_Color: {r: 0.40392157, g: 0.40392157, b: 0.40392157, a: 1}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 0