Нашёл причину утечки памяти
This commit is contained in:
1 parent
60c28f54f2
commit
320847af5b
229 files changed
+3094
-18282
No files matched your search
@@ -24,6 +24,11 @@ namespace Code.Infrastructure.App.States
|
||||
|
||||
Context.UIService.TryLoadCreatePanel(UIPanelType.DebugSceneChooser);
|
||||
Context.AudioFactory.LoadAudioClips(AudioNames.UISounds);
|
||||
|
||||
Context.AudioService.ChangeGroupVolume(
|
||||
AudioGroupType.Music,
|
||||
1f,
|
||||
0.5f);
|
||||
}
|
||||
|
||||
protected override void OnExitState()
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
using System.Linq;
|
||||
using Code.Example.Race;
|
||||
using Code.Example.Race.Racer;
|
||||
using Code.Example.Race.Racer.AI;
|
||||
using Code.Example.Race.Racer.Player;
|
||||
using Code.Example.Race.Track;
|
||||
using Code.Example.Race.UI;
|
||||
using Code.Infrastructure.Audio;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Camera.CameraStates;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Code.Infrastructure.Input;
|
||||
using Code.Infrastructure.Loadings;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Code.Infrastructure.UI;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Core;
|
||||
using Reflex.Injectors;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine.SceneManagement;
|
||||
// Ивенты создания панелей сломаны TODO
|
||||
namespace Code.Infrastructure.App.States
|
||||
{
|
||||
[State(typeof(AppStates), typeof(AppStateMachineContext))]
|
||||
[StateRaisingEvent]
|
||||
public partial class GameplayState :
|
||||
IOnGameplaySceneLoadedHandler,
|
||||
IRaceGameHandle,
|
||||
IRacerFactoryInitializedHandle,
|
||||
ICinematicMachineHandle
|
||||
{
|
||||
public GameplayState(AppStateMachineContext context, EventBus.EventBus eventBus) : base(context, eventBus)
|
||||
{
|
||||
}
|
||||
|
||||
public override AppStates myState => AppStates.Gameplay;
|
||||
|
||||
private Loading _gameplayLoading;
|
||||
|
||||
protected override void OnEnterState()
|
||||
{
|
||||
EventBus.Subscribe(this);
|
||||
Context.UIService.OpenPanel(UIPanelType.Loading);
|
||||
|
||||
// Scene
|
||||
// RaceGame
|
||||
// Factory
|
||||
// PlayerCounter
|
||||
// WinScreen
|
||||
// ScoreScreen
|
||||
// CinemachineCamera
|
||||
_gameplayLoading = new Loading(7, GameplayLoadingCompleted);
|
||||
|
||||
Context.UIService.TryLoadCreatePanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.UIService.TryLoadCreatePanel(UIPanelType.WinScreen);
|
||||
Context.UIService.TryLoadCreatePanel(UIPanelType.PlayerScores);
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.Gameplay, LoadSceneMode.Single).Forget();
|
||||
Context.InputService.EnableMap(ActionMappings.Race);
|
||||
Context.CameraFactory.LoadCinemachineCamera(CameraMode.ThirdPerson).Forget();
|
||||
}
|
||||
|
||||
private void GameplayLoadingCompleted()
|
||||
{
|
||||
Context.AudioService.CancelMusic(AudioNames.UISounds, 0);
|
||||
|
||||
_raceGame.PlaceRacers();
|
||||
|
||||
Context.Camera.SwitchState(CameraMode.ThirdPerson).AllowStateTransition(CameraMode.None);
|
||||
// ((ThirdPersonState)Context.Camera.CurrentBaseState).SetFollowTarget(_raceGame.PlacedRacers[0].gameObject.transform, _raceGame.PlacedRacers[0].CarRigidbody);
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.ThirdPerson).transform.position = ((PlayerRacer)_raceGame.PlacedRacers[0]).CameraPosition.position;
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.ThirdPerson).transform.rotation = ((PlayerRacer)_raceGame.PlacedRacers[0]).CameraPosition.rotation;
|
||||
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.ThirdPerson).Follow =
|
||||
_raceGame.PlacedRacers[0].gameObject.transform;
|
||||
|
||||
Context.UIService.ClosePanel(UIPanelType.Loading);
|
||||
|
||||
_raceGame.StartRacers();
|
||||
}
|
||||
|
||||
protected override void OnExitState()
|
||||
{
|
||||
Context.UIService.TryRemovePanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.WinScreen);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.PlayerScores);
|
||||
Context.CameraFactory.ReleaseCinemachineCamera(CameraMode.ThirdPerson);
|
||||
Context.InputService.DisableMap(ActionMappings.Race);
|
||||
|
||||
_raceGame = null;
|
||||
|
||||
EventBus.Unsubscribe(this);
|
||||
}
|
||||
|
||||
public void OnGameplaySceneLoaded()
|
||||
{
|
||||
}
|
||||
|
||||
private RaceTrackData _raceTrackData;
|
||||
private RaceGame _raceGame;
|
||||
private Container UNTILTHEYFIXCONTAINERS;
|
||||
public void OnGameplaySceneInitialized(Container container)
|
||||
{
|
||||
UNTILTHEYFIXCONTAINERS = container;
|
||||
|
||||
_raceTrackData = container.Resolve<RaceTrackData>();
|
||||
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.None).transform.position = _raceTrackData.CameraPosition.transform.position;
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.None).transform.rotation = _raceTrackData.CameraPosition.transform.rotation;
|
||||
|
||||
_gameplayLoading.DoProgress();
|
||||
|
||||
container.Resolve<IRacerFactory>();
|
||||
}
|
||||
|
||||
public void RaceGameReady()
|
||||
{
|
||||
_gameplayLoading.DoProgress();
|
||||
}
|
||||
|
||||
public void RaceGameEnded(RaceScores scores)
|
||||
{
|
||||
var winScreen = (WinScreen)Context.UIService.TryGetSinglePanel(UIPanelType.WinScreen);
|
||||
|
||||
var id = 0;
|
||||
var cachedScores = scores.GetScores();
|
||||
|
||||
for (var i = 0; i < cachedScores.Count; i++)
|
||||
if (cachedScores[i].Key.Data.type == RacerType.Player) id = i + 1;
|
||||
|
||||
UNTILTHEYFIXCONTAINERS.Resolve<PlayerPrefsRacePoopshitter>().AddRace(new(_raceGame.RaceTime, id));
|
||||
|
||||
var winText = $@"{id} МЕСТО\n";
|
||||
winScreen.SetText(winText);
|
||||
|
||||
var getPanel = Context.UIService.TryGetSinglePanel(UIPanelType.PlayerScores);
|
||||
((PlayerScores)getPanel)
|
||||
.SetText(UNTILTHEYFIXCONTAINERS.Resolve<PlayerPrefsRacePoopshitter>().GetRaces());
|
||||
Context.UIService.ClosePanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.UIService.OpenPanel(UIPanelType.WinScreen);
|
||||
|
||||
EndTheGame().Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid EndTheGame()
|
||||
{
|
||||
await UniTask.WaitForSeconds(3f);
|
||||
Context.UIService.ClosePanel(UIPanelType.WinScreen);
|
||||
|
||||
Context.UIService.OpenPanel(UIPanelType.PlayerScores);
|
||||
await UniTask.WaitForSeconds(5f);
|
||||
|
||||
Context.UIService.OpenPanel(UIPanelType.Loading);
|
||||
Context.StateMachine.SwitchState(AppStates.MainMenu).AllowStateTransition(AppStates.Gameplay);
|
||||
}
|
||||
|
||||
public void RacerFactoryInitialized()
|
||||
{
|
||||
_raceGame = UNTILTHEYFIXCONTAINERS.Resolve<RaceGame>();
|
||||
|
||||
_gameplayLoading.DoProgress();
|
||||
}
|
||||
|
||||
public void UILoaded(UIPanelType uiPanelType)
|
||||
{
|
||||
if(uiPanelType is UIPanelType.WinScreen or UIPanelType.PlayerScores)
|
||||
{
|
||||
_gameplayLoading.DoProgress();
|
||||
return;
|
||||
}
|
||||
|
||||
if (uiPanelType != UIPanelType.PlayerScoreCounter) return;
|
||||
|
||||
Context.UIService.OpenPanel(UIPanelType.PlayerScoreCounter);
|
||||
_gameplayLoading.DoProgress();
|
||||
}
|
||||
|
||||
public void CinemachineLoaded(CinemachineCamera cinemachineCamera) => _gameplayLoading.DoProgress();
|
||||
public void UISinglePanelLoaded(UIPanelType uiPanelType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void UISinglePanelRemoved(UIPanelType uiPanelType)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e543193800134f7b858502743ab3a43d
|
||||
timeCreated: 1766436900
|
||||
@@ -30,13 +30,24 @@ namespace Code.Infrastructure.App.States
|
||||
// Context.AudioFactory.LoadAudioClips(AudioNames.UISounds);
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.MainMenu, LoadSceneMode.Single).Forget();
|
||||
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0, AudioGroupType.Music);
|
||||
|
||||
Context.AudioService.ChangeGroupVolume(
|
||||
AudioGroupType.Music,
|
||||
1f,
|
||||
0.5f);
|
||||
}
|
||||
|
||||
protected override void OnExitState()
|
||||
{
|
||||
// Context.AudioFactory.ReleaseAudios(AudioNames.UISounds);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.DebugSceneChooser);
|
||||
Context.AudioService.CancelMusic(AudioNames.UISounds,0);
|
||||
|
||||
Context.AudioService.ChangeGroupVolume(
|
||||
AudioGroupType.Music,
|
||||
0,
|
||||
0.5f,
|
||||
() => Context.AudioService.CancelMusic(AudioNames.UISounds,0));
|
||||
|
||||
EventBus.Unsubscribe(this);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user