Нашёл причину утечки памяти
This commit is contained in:
1 parent
60c28f54f2
commit
320847af5b
229 files changed
+3094
-18282
No files matched your search
@@ -1,12 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Reflex.Core;
|
||||
using Reflex.Extensions;
|
||||
using Reflex.Injectors;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Code.Infrastructure.UI
|
||||
{
|
||||
@@ -22,7 +18,7 @@ namespace Code.Infrastructure.UI
|
||||
}
|
||||
|
||||
// Крайне неудобно пользоваться
|
||||
public class UIService : IUIPanelLoadedHandle, IUIService
|
||||
public class UIService : IUIPanelLoadedHandle, IUIService, IDisposable
|
||||
{
|
||||
private Dictionary<UIPanelType, UIPanel> _loadedSinglePanels = new();
|
||||
private Dictionary<UIPanelType, List<UIPanel>> _loadedMultiplePanels = new();
|
||||
@@ -49,10 +45,9 @@ namespace Code.Infrastructure.UI
|
||||
_loadedSinglePanels[uiPanelType].Open();
|
||||
}
|
||||
|
||||
// TODO Close event
|
||||
public void ClosePanel(UIPanelType uiPanelType)
|
||||
{
|
||||
_loadedSinglePanels[uiPanelType].Close();
|
||||
_loadedSinglePanels[uiPanelType].Close(() => _loadedSinglePanels[uiPanelType].gameObject.SetActive(false));
|
||||
}
|
||||
|
||||
public void TryLoadCreatePanel(UIPanelType uiPanelType, Transform parent = null) => _factory.LoadPanel(uiPanelType, parent);
|
||||
@@ -79,20 +74,31 @@ namespace Code.Infrastructure.UI
|
||||
panel.FireCreatedEvent();
|
||||
}
|
||||
|
||||
// Для единичных
|
||||
public void TryRemovePanel(UIPanelType uiPanelType)
|
||||
{
|
||||
if (_factory.CheckIsMultiple(uiPanelType))
|
||||
{
|
||||
UnityEngine.Debug.LogError("Это для единичных панелей олух");
|
||||
return;
|
||||
}
|
||||
_loadedSinglePanels[uiPanelType].Close();
|
||||
if (_factory.CheckIsMultiple(uiPanelType)) return;
|
||||
|
||||
_loadedSinglePanels[uiPanelType].Close(() => RemovePanel(uiPanelType));
|
||||
}
|
||||
// Для многочисленных
|
||||
public void TryRemovePanel(UIPanel panel)
|
||||
{
|
||||
panel.Close();
|
||||
panel.Close(() => RemovePanel(panel));
|
||||
}
|
||||
private void RemovePanel(UIPanel panel)
|
||||
{
|
||||
if (!_factory.CheckIsMultiple(panel.PanelType)) return;
|
||||
|
||||
_loadedMultiplePanels[panel.PanelType].Remove(panel);
|
||||
panel.FireRemovedEvent();
|
||||
|
||||
_factory.ReleasePanel(panel);
|
||||
|
||||
if(_loadedMultiplePanels[panel.PanelType].Count == 0) _loadedMultiplePanels.Remove(panel.PanelType);
|
||||
}
|
||||
|
||||
// Для всех
|
||||
private void RemovePanel(UIPanelType panelType)
|
||||
{
|
||||
if (!_factory.CheckIsMultiple(panelType))
|
||||
@@ -117,17 +123,13 @@ namespace Code.Infrastructure.UI
|
||||
}
|
||||
}
|
||||
|
||||
private void RemovePanel(UIPanel panel)
|
||||
{
|
||||
_loadedMultiplePanels[panel.PanelType].Remove(panel);
|
||||
panel.FireRemovedEvent();
|
||||
|
||||
_factory.ReleasePanel(panel);
|
||||
|
||||
if(_loadedMultiplePanels[panel.PanelType].Count == 0) _loadedMultiplePanels.Remove(panel.PanelType);
|
||||
}
|
||||
|
||||
public UIPanel TryGetSinglePanel(UIPanelType panelType) => _loadedSinglePanels.GetValueOrDefault(panelType);
|
||||
public List<UIPanel> TryGetMultiplePanels(UIPanelType panelType) => _loadedMultiplePanels.GetValueOrDefault(panelType);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// TODO Релизнуть всё
|
||||
_eventBus.Unsubscribe(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user