Ссылки на группы главного меню развязаны в UiManager;

DifficultyManager изменен способ инициализации синглтона
This commit is contained in:
se_ga 2026-03-20 13:32:26 +03:00
parent 298e6cb5c6
commit 16b02e828a
10 changed files with 189 additions and 76 deletions

View File

@ -11349,7 +11349,7 @@ Material:
- _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767}
- _EnvMatrixRotation: {r: 0, g: 0, b: 0, a: 0}
- _FaceColor: {r: 1, g: 1, b: 1, a: 1}
- _GlowColor: {r: 1, g: 0.77535063, b: 0, a: 1}
- _GlowColor: {r: 1, g: 0.0684407, b: 0, a: 1}
- _MaskCoord: {r: 0, g: 0, b: 32767, a: 32767}
- _OutlineColor: {r: 0.554717, g: 0.554717, b: 0.554717, a: 1}
- _ReflectFaceColor: {r: 0, g: 0, b: 0, a: 1}

View File

@ -3670,6 +3670,54 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 157258767}
m_CullTransparentMesh: 1
--- !u!1 &163302437
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 163302439}
- component: {fileID: 163302438}
m_Layer: 0
m_Name: UiManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &163302438
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 163302437}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7b4f42eaa95c3eb4f95825ea27e72fcb, type: 3}
m_Name:
m_EditorClassIdentifier:
UpperMenuGroup: {fileID: 382964715}
PveOption: {fileID: 2047831684}
PvpOption: {fileID: 95872202}
DownMenuGroup: {fileID: 109738548}
--- !u!4 &163302439
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 163302437}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 5.273878, y: -1.551749, z: -0.07899367}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &164597568
GameObject:
m_ObjectHideFlags: 0
@ -24822,9 +24870,9 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 382964715}
- {fileID: 2047831684}
- {fileID: 95872202}
- {fileID: 382964715}
- {fileID: 109738548}
m_Father: {fileID: 1122363135}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -72627,6 +72675,7 @@ SceneRoots:
m_ObjectHideFlags: 0
m_Roots:
- {fileID: 519420032}
- {fileID: 163302439}
- {fileID: 829871288}
- {fileID: 259182280}
- {fileID: 151433695}

View File

@ -1,5 +1,4 @@
using System;
using TMPro;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
@ -8,6 +7,9 @@ using PrizeSystem;
public enum GameMode { pve, pvp }
public class GameManager : MonoBehaviour
{
private const int DEFAULT_FRAME_RATE = 60;
public int Rows = 7, Cols = 7;
public PlayerStatsService StatsService;
public bool dummyBots = false;
@ -31,11 +33,7 @@ public class GameManager : MonoBehaviour
public bool menuOpened = true;
public GameMode gameMode;
public Transform
label,
buttonLeft,
buttonRight,
coinPanel,
label2,
board,
noPrizeLabel;
public GameObject mainMenu;
@ -130,7 +128,7 @@ public class GameManager : MonoBehaviour
if (instance == null)
{
Application.targetFrameRate = 60;
Application.targetFrameRate = DEFAULT_FRAME_RATE;
instance = this;
fieldModel = new FieldModel(Cols, Rows);
@ -138,19 +136,53 @@ public class GameManager : MonoBehaviour
}
ConfigManager.Initialize();
UnityMainThreadDispatcher.Initialize();
InitializePrefs();
SettingsManager.Initialize();
GetComponent<Logger>().Initialize();
//Тестируем пока что. Не прод(ну ладно прод.)
logger = GetComponent<Logger>();
InitializeDevices();
SingleWallet.Initialize();
ComWrapper.PaymentReceived += ProcessDifficultyCounter;
SettingsManager.OnSettingsChanged.AddListener(ProcessDifficultyCounter);
soundManager.Initialize();
GetComponent<NotificationSystem>().Initialize();
vitrinaCatcher.Initialize();
ProcessDifficultyCounter();
GetComponent<In>().Initialize();
GetComponent<PrizeSystemManager>().Initialize();
GetComponent<VideoUtility>().Initialize();
StatsService = new();
StatsService.Initialize();
#if !UNITY_EDITOR
Defender.Instance.StartCoroutine(Defender.Instance.CheckLicenseCoroutine());
dummyBots = false;
#endif
StartCoroutine(AddBotRecordEvery2Days());// добавлять каждые 2 дня запись
avatarController.GetComponent<AvatarEventBus>().Initialize();
avatarController.Initialize();
}
private void InitializeDevices()
{
//ИНИЦИАЛИЗАЦИЯ УСТРОЙСТВ
var devices = ComPortScanner.ScanPorts();
logger.Log($"Найдено устройств: {devices.Count}");
@ -199,39 +231,10 @@ public class GameManager : MonoBehaviour
else logger.Log("Не Открыл");
PrizeStandController.Initialize(h, 5, logger);
}
//рабочая(до витрины) версия
//ComWrapper.Initialize(ComNativeWrapper.ListPorts(), boardVersion);
SingleWallet.Initialize();
ComWrapper.PaymentReceived += ProcessDifficultyCounter;
SettingsManager.OnSettingsChanged.AddListener(ProcessDifficultyCounter);
soundManager.Initialize();
GetComponent<NotificationSystem>().Initialize();
vitrinaCatcher.Initialize();
ProcessDifficultyCounter();
GetComponent<In>().Initialize();
GetComponent<PrizeSystemManager>().Initialize();
GetComponent<VideoUtility>().Initialize();
StatsService = new();
StatsService.Initialize();
#if !UNITY_EDITOR
Defender.Instance.StartCoroutine(Defender.Instance.CheckLicenseCoroutine());
dummyBots = false;
#endif
StartCoroutine(AddBotRecordEvery2Days());// добавлять каждые 2 дня запись
avatarController.GetComponent<AvatarEventBus>().Initialize();
avatarController.Initialize();
}
private void OnApplicationQuit()
{
ComNativeWrapper.Serial_CloseAll();

View File

@ -0,0 +1,32 @@
using UnityEngine;
public class UiManager : MonoBehaviour
{
private static UiManager _instance;
public static UiManager Instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType<UiManager>();
if (_instance == null)
{
Debug.LogWarning($"Не найден {typeof(UiManager)}");
}
}
return _instance;
}
}
//Ссылки главно меню
public RectTransform UpperMenuGroup;
public RectTransform PveOption;
public RectTransform PvpOption;
public RectTransform DownMenuGroup;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7b4f42eaa95c3eb4f95825ea27e72fcb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3,20 +3,32 @@ using UnityEngine.Events;
public class DifficultyManager : MonoBehaviour
{
public static DifficultyManager instance;
public UnityEvent OnVictory = new UnityEvent();
public int currentOpponent = 0;
void Awake()
private static DifficultyManager instance;
public static DifficultyManager Instance
{
if (instance == null)
get
{
instance = this;
currentOpponent = 0;
if (instance == null)
{
instance = FindObjectOfType<DifficultyManager>();
if (instance == null)
{
Debug.LogWarning($"Не найден {typeof(DifficultyManager)}");
}
else
{
instance.currentOpponent = 0;
}
}
return instance;
}
}
public UnityEvent OnVictory = new UnityEvent();
public int currentOpponent = 0;
public DifficultyPreset DifficultyPreset => CharacterController.CurrentCharacter.CurrentDifficultyPreset;
public void IncreaseDifficulty()

View File

@ -48,7 +48,7 @@ public static class FieldCleaner
{
//Фишка ходит первой если ее не побеждали сегодня еще
bool goingToLastBot = DifficultyManager.instance.currentOpponent == GameManager.instance.botsAmount - 1;
bool goingToLastBot = DifficultyManager.Instance.currentOpponent == GameManager.instance.botsAmount - 1;
if (goingToLastBot)
{

View File

@ -5,6 +5,8 @@ enum MenuSubStates { OpeningMenu, Choosing, Payment, ClosingMenu, SwitchState }
public class MenuState : IState
{
GameManager gm;
UiManager ui;
float SecondsToPromo = 180;
float ElapsedPromoTimer;
@ -82,11 +84,15 @@ public class MenuState : IState
private void PullRefs()
{
gm = GameManager.instance;
label = gm.label;
buttonLeft = gm.buttonLeft;
buttonRight = gm.buttonRight;
ui = UiManager.Instance;
label = ui.UpperMenuGroup;
buttonLeft = ui.PveOption;
buttonRight = ui.PvpOption;
label2 = ui.DownMenuGroup;
coinPanel = gm.coinPanel;
label2 = gm.label2;
board = gm.board;
noPrizeLabel = gm.noPrizeLabel;
SmallPrizesOut = gm.smallPrizesOut;
@ -102,7 +108,7 @@ public class MenuState : IState
CharacterController.I.SetAllCharactersPrizeAvailable(true);
DualAvatarController.Instance.HideCharacters();
DifficultyManager.instance.ResetDifficulty();
DifficultyManager.Instance.ResetDifficulty();
gm.player1score = 0;
gm.player2score = 0;

View File

@ -20,7 +20,7 @@ public class StartRoundState : IState
if (gm.gameMode == GameMode.pve)
gm.timerManager.SetActiveTimer(CellState.Player1);//если деремся с ботом, держим таймер включенным
int difficultyIndex = DifficultyManager.instance.currentOpponent;
int difficultyIndex = DifficultyManager.Instance.currentOpponent;
if (gm.gameMode == GameMode.pve)
{
CharacterController.SwitchToCharacter(difficultyIndex);

View File

@ -1,4 +1,4 @@
using PrizeSystem;
using PrizeSystem;
using UnityEngine;
public static class EndOfTurnHandler
@ -13,7 +13,7 @@ public static class EndOfTurnHandler
bool wrapToPrizeState = false;
IState nextState = new ShowWinnerState(result);//временно
IState nextState = new ShowWinnerState(result);//временно
if (result.End)
{
@ -23,18 +23,18 @@ public static class EndOfTurnHandler
{
PvpEndroundHandler();
}
else if (gm.gameMode == GameMode.pve) //конец раунда с ботом
else if (gm.gameMode == GameMode.pve) //конец раунда с ботом
{
PveEndroundHandler();
if (gm.currentPlayer == CellState.Player1)
{//автопереход на некст бота.
{//автопереход на некст бота.
wrapToPrizeState = true;
nextState = CreateAutoTransitionState(result, 4);
}
}
if (TotalWin())
{//конец игры - призовое состояние
{//конец игры - призовое состояние
nextState = new VictoryState();
ClearAllScales();
}
@ -63,13 +63,13 @@ public static class EndOfTurnHandler
{
PlayerWinHandler();
}
else//Бот победил
else//Бот победил
{
BotWinHandler();
}
gm.botScale.SetMedalsCount(gm.vsBotScore);
//если фишку победили, то повышаем.
//если фишку победили, то повышаем.
if (gm.vsBotScore == gm.botsAmount) gm.upgradeFeeshkaDifficulty();
}
@ -87,7 +87,7 @@ public static class EndOfTurnHandler
{
LightUtility.Lose();
CharacterController.CurrentCharacter.GetComponent<Animator>().SetTrigger("Win");
DifficultyManager.instance.DecreaseDifficulty();
DifficultyManager.Instance.DecreaseDifficulty();
if (gm.vsBotScore != 0)
gm.vsBotScore -= 1;
@ -101,7 +101,7 @@ public static class EndOfTurnHandler
CharacterController.CurrentCharacter.HasPrize = false;
}
DifficultyManager.instance.IncreaseDifficulty();
DifficultyManager.Instance.IncreaseDifficulty();
gm.vsBotScore += 1;
CharacterEventBus.Instance.OnPlayerWin?.Invoke();
@ -128,9 +128,9 @@ public static class EndOfTurnHandler
public static void WinByTimerHandling()
{
//При победе по таймеру:
//PVP проиграл тот, кто не успел кинуть фишку
//PVE - прогрывает человек
//При победе по таймеру:
//PVP проиграл тот, кто не успел кинуть фишку
//PVE - прогрывает человек
result = new CheckResult(true, false, null);
@ -138,26 +138,26 @@ public static class EndOfTurnHandler
if (gm.gameMode == GameMode.pvp)
{
//p2 не успел
//p2 не успел
if (gm.currentPlayer == CellState.Player2)
{
gm.player1score += 1;
gm.Player1Scale.SetMedalsCount(gm.player1score);
}
else//p1 не успел
else//p1 не успел
{
gm.player2score += 1;
gm.Player2Scale.SetMedalsCount(gm.player2score);
}
}
else if (gm.gameMode == GameMode.pve)//время вышло при игре с ботом - бот победил
else if (gm.gameMode == GameMode.pve)//время вышло при игре с ботом - бот победил
{
LightUtility.Lose();
CharacterController.CurrentCharacter.GetComponent<Animator>().SetTrigger("Win");
//НЕ НИЧЬЯ
//НЕ НИЧЬЯ
VictoryScale vsBotScale = gm.botScale;
DifficultyManager.instance.DecreaseDifficulty();
DifficultyManager.Instance.DecreaseDifficulty();
CharacterEventBus.Instance.OnBotWin?.Invoke();
if (gm.vsBotScore != 0) gm.vsBotScore -= 1;
@ -166,7 +166,7 @@ public static class EndOfTurnHandler
nextState = new ShowWinnerState(result);
//конец игры - призовое состояние
//конец игры - призовое состояние
if (TotalWin())
{
nextState = new VictoryState();