Рефакторинг Scripts/Gameplay (частично)

This commit is contained in:
Сергей Бондарь 2026-07-15 16:54:56 +03:00
parent e88c88f4dd
commit b0cd7f54e2
22 changed files with 28 additions and 110 deletions

View File

@ -15627,7 +15627,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 27edee241c0fb934ebe299af31cf6c77, type: 3}
m_Name:
m_EditorClassIdentifier:
adminPasswordFallback: 1234
settingActions: []
--- !u!4 &592995719
Transform:
@ -49879,7 +49878,6 @@ MonoBehaviour:
balanceLabel: {fileID: 1473378075}
revengeLabel: {fileID: 2002530260}
revengePriceColor: {r: 1, g: 0.16, b: 0, a: 1}
maxParticles: 20
AddCoinsPS: {fileID: 2654461056344553289}
RemoveCoinsPS: {fileID: 3979991017915063070}
amplitude: 0
@ -80060,9 +80058,6 @@ MonoBehaviour:
NextPrizeView: {fileID: 1203032464936095846}
DisabledColor: {r: 0.16981131, g: 0.16981131, b: 0.16981131, a: 1}
HsvSpeed: 0.2
ScalingSpeed: 1
SelectedScale: 1.05
IdleScale: 0.95
StartAcceptingClip: {fileID: 8300000, guid: 7fb340d179cafc04cb2e4baa2ddde96f, type: 3}
--- !u!114 &7987471542231822866
MonoBehaviour:

View File

@ -15,11 +15,7 @@ public class Timer : MonoBehaviour
public UnityEvent OnTimerEnded;
private void Start()
{
lastSignalTime = Time.time;
}
private void Start() => lastSignalTime = Time.time;
void Update()
{
@ -74,10 +70,9 @@ public class Timer : MonoBehaviour
string seconds = ((int)(restTime % 60)).ToString();
if (minutes.Length < 2) minutes = "0" + minutes;
if (seconds.Length < 2) seconds = "0" + seconds;
if (seconds.Length < 2) seconds = "0" + seconds;
string result = minutes + ":" + seconds;
TimeLabel.text = result;
}
}
}

View File

@ -4,78 +4,32 @@ public class TimerManager : MonoBehaviour
{
[SerializeField] Timer player1Timer, player2Timer;
[SerializeField] float vsBotTime = 180;
[SerializeField] float pvpTime = 90; //время для каждого отдельного игрока
[SerializeField] float pvpTime = 90;
private void Start() => Init(); //todo: перенести вызов в место инициализации
private void Start()
private void Init()
{
player1Timer.OnTimerEnded.AddListener(ExitByTime);
player2Timer.OnTimerEnded.AddListener(ExitByTime);
player1Timer.OnTimerEnded.AddListener(EndOfTurnHandler.WinByTimerHandling);
player2Timer.OnTimerEnded.AddListener(EndOfTurnHandler.WinByTimerHandling);
}
public void SetupTimers(GameMode gameMode)
{
if (gameMode == GameMode.pve)
{
float timeToSet = vsBotTime;
player1Timer.SetupTimer(timeToSet);
}
player1Timer.SetupTimer(gameMode == GameMode.pve ? vsBotTime : pvpTime);
if (gameMode == GameMode.pvp)
{
player1Timer.SetupTimer(pvpTime);
player2Timer.SetupTimer(pvpTime);
}
SetTimersActivity(gameMode);
}
void ExitByTime()
{
//GameManager.instance.stateMachine.ChangeState(new CheckState(true));
EndOfTurnHandler.WinByTimerHandling();
}
public void SetTimersActivity(GameMode gameMode)
{
if (gameMode == GameMode.pve)
{
player1Timer.gameObject.SetActive(true);
player2Timer.gameObject.SetActive(false);
}
if (gameMode == GameMode.pvp)
{
player1Timer.gameObject.SetActive(true);
player2Timer.gameObject.SetActive(true);
}
bool activateSecondTimer = gameMode == GameMode.pvp;
player1Timer.gameObject.SetActive(true);
player2Timer.gameObject.SetActive(activateSecondTimer);
}
public void DisableAllTimers()
{
player1Timer.gameObject.SetActive(false);
player2Timer.gameObject.SetActive(false);
}
void StartTimer(CellState player)
{
if (player == CellState.Player1)
player1Timer.StartTimer();
if (player == CellState.Player2)
player2Timer.StartTimer();
}
void StopTimer(CellState player)
{
if (player == CellState.Player1)
player1Timer.StopTimer();
if (player == CellState.Player2)
player2Timer.StopTimer();
}
public void StopAllTimers()
{
player1Timer.StopTimer();
@ -84,16 +38,7 @@ public class TimerManager : MonoBehaviour
public void SetActiveTimer(CellState currentPlayer)
{
if (currentPlayer == CellState.Player1)
{
player1Timer.StartTimer();
player2Timer.StopTimer();
}
if (currentPlayer == CellState.Player2)
{
player2Timer.StartTimer();
player1Timer.StopTimer();
}
(currentPlayer == CellState.Player1 ? player1Timer : player2Timer).StartTimer();
(currentPlayer == CellState.Player1 ? player2Timer : player1Timer).StopTimer();
}
}
}

View File

@ -4,24 +4,21 @@ using UnityEngine;
public class VictoryScale : MonoBehaviour
{
public List<Transform> medals;
public List<Transform> rings;
public Transform Prize;
public ParticleSystem winParticles; // надо заприватить и почистить вызовы
public Vector3 nextMedalOffset;
public GameObject CollectEffect, RemoveEffect;
public ParticleSystem winParticles;
public int count = 0; //мб заприватить
[SerializeField] List<Transform> medals;
[SerializeField] List<Transform> rings;
[SerializeField] Transform Prize;
[SerializeField] Vector3 nextMedalOffset;
[SerializeField] GameObject CollectEffect, RemoveEffect;
[SerializeField] Animator CommonAnimator;
[SerializeField] Animator PrizeAnimator;
[SerializeField] private AudioClip plusMedal;
[SerializeField] private AudioClip minusMedal;
[SerializeField] AudioClip plusMedal;
[SerializeField] AudioClip minusMedal;
private int count = 0;
private void OnEnable()
{
@ -29,8 +26,7 @@ public class VictoryScale : MonoBehaviour
foreach (var medal in medals)
{
medal.gameObject.SetActive(false);
}
}
}
public void SetIdleState()
@ -38,13 +34,13 @@ public class VictoryScale : MonoBehaviour
CommonAnimator?.SetTrigger("Idle");
PrizeAnimator?.SetTrigger("Idle");
}
public void SetWinState()
{
CommonAnimator?.SetTrigger("Prize");
PrizeAnimator?.SetTrigger("Prize");
}
public void SetSlotsCount(int count)
{
foreach (var ring in rings)
@ -65,7 +61,6 @@ public class VictoryScale : MonoBehaviour
requiredCount < 0)
return;
if (requiredCount > count)//увеличиваем заполнение
{
for (int i = count; i < requiredCount; i++)
@ -80,7 +75,6 @@ public class VictoryScale : MonoBehaviour
DisableMedal(i-1);
}
}
count = requiredCount;
}
@ -100,8 +94,6 @@ public class VictoryScale : MonoBehaviour
medals[index].gameObject.SetActive(false);
}
public void ResetScale()
{
count = 0;
@ -125,7 +117,4 @@ public class VictoryScale : MonoBehaviour
}
ResetScale();
}
}
}

View File

@ -1,11 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WinPanel : MonoBehaviour
{
public GameObject win1, win2, winBot;
public AudioSource sound;
public void ShowWin(CellState winner)
{
@ -49,7 +47,6 @@ public class WinPanel : MonoBehaviour
IEnumerator ClosePanel()
{
float param = 1;
while (param > 0)
{
@ -61,7 +58,4 @@ public class WinPanel : MonoBehaviour
}
sound.Stop();
}
}
}