Платформер враги, инфраструктура, герой
This commit is contained in:
1 parent
28125eb382
commit
93819c1dd3
61 files changed
+1463
-423
No files matched your search
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
public class DamnEmptyPanel : UIPanel
|
||||
{
|
||||
public override void Open(Action callback = null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
}
|
||||
|
||||
public override void Close(Action callback = null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce4e618236c441ca857ad458fa13e09d
|
||||
timeCreated: 1769347387
|
||||
@@ -5,7 +5,7 @@ using UnityEngine.UI;
|
||||
|
||||
namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
public class LoadingPanel : UIPanel
|
||||
public partial class LoadingPanel : UIPanel
|
||||
{
|
||||
[SerializeField] private RawImage image;
|
||||
[SerializeField] private Color shownColor;
|
||||
|
||||
@@ -5,7 +5,7 @@ using UnityEngine.UI;
|
||||
|
||||
namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
public class LogoPanel : UIPanel
|
||||
public partial class LogoPanel : UIPanel
|
||||
{
|
||||
[SerializeField] private Image image;
|
||||
[SerializeField] private Color shownColor;
|
||||
|
||||
@@ -6,7 +6,7 @@ using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
public class MenuChoosePanel : UIPanel
|
||||
public partial class MenuChoosePanel : UIPanel
|
||||
{
|
||||
[Inject] IAudioService _audioService;
|
||||
[SerializeField] private SceneChooser sceneChooser;
|
||||
|
||||
@@ -12,14 +12,16 @@ namespace Code.Infrastructure.UI
|
||||
{
|
||||
public interface IUIFactory
|
||||
{
|
||||
UniTaskVoid LoadPanel(UIPanelType panelType);
|
||||
UniTaskVoid LoadPanel(UIPanelType panelType, Transform parent = null);
|
||||
void ReleasePanel(UIPanel panel);
|
||||
Canvas Canvas { get; }
|
||||
bool CheckIsMultiple(UIPanelType panelType);
|
||||
}
|
||||
|
||||
public class UIFactory : IDisposable, IUIFactory
|
||||
{
|
||||
private Dictionary<UIPanelType, UIPanelSettingsConfig> _configs;
|
||||
public bool CheckIsMultiple(UIPanelType panelType) => _configs[panelType].Multiple;
|
||||
private AssetReference _canvasConfigReference;
|
||||
private string _configsLabel;
|
||||
private EventBus.EventBus _eventBus;
|
||||
@@ -41,9 +43,9 @@ namespace Code.Infrastructure.UI
|
||||
LoadConfigs().Forget();
|
||||
}
|
||||
|
||||
public async UniTaskVoid LoadPanel(UIPanelType panelType)
|
||||
public async UniTaskVoid LoadPanel(UIPanelType panelType, Transform parent = null)
|
||||
{
|
||||
var panel = (await Addressables.InstantiateAsync(_configs[panelType].Prefab, _canvas.transform).ToUniTask())
|
||||
var panel = (await Addressables.InstantiateAsync(_configs[panelType].Prefab, parent ?? _canvas.transform).ToUniTask())
|
||||
.GetComponent<UIPanel>();
|
||||
|
||||
UnityEngine.Debug.LogWarning($"Panel loaded {panelType}");
|
||||
@@ -90,5 +92,6 @@ namespace Code.Infrastructure.UI
|
||||
public interface IUIPanelLoadedHandle : IGlobalSubscriber
|
||||
{
|
||||
void UIPanelLoaded(UIPanel panel, UIPanelType panelType);
|
||||
List<UIPanel> TryGetMultiplePanels(UIPanelType panelType);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8447b81247b24f1b869b0067aeeff0b8
|
||||
timeCreated: 1768979324
|
||||
guid: 8447b81247b24f1b869b0067aeeff0b8
|
||||
@@ -1,13 +1,21 @@
|
||||
using System;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.UI
|
||||
{
|
||||
public abstract class UIPanel : MonoBehaviour
|
||||
{
|
||||
public UIPanelType PanelType { get; set; }
|
||||
|
||||
[SerializeField] protected bool injectMeSenpai;
|
||||
public bool InjectMeSenpai => injectMeSenpai;
|
||||
[Inject] protected EventBus.EventBus _eventBus;
|
||||
public abstract void Open(Action callback = null);
|
||||
public abstract void Close(Action callback = null);
|
||||
|
||||
public virtual void FireCreatedEvent(){}
|
||||
public virtual void FireRemovedEvent(){}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace Code.Infrastructure.UI
|
||||
{
|
||||
[ToConfig] public AssetReference Prefab;
|
||||
[ToConfig] public UIPanelType UIPanelType;
|
||||
[ToConfig] public bool Multiple;
|
||||
}
|
||||
|
||||
[Config("Configs/UI/CanvasSettings")]
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
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
|
||||
@@ -12,15 +14,18 @@ namespace Code.Infrastructure.UI
|
||||
{
|
||||
void OpenPanel(UIPanelType uiPanelType);
|
||||
void ClosePanel(UIPanelType uiPanelType);
|
||||
void TryLoadPanel(UIPanelType uiPanelType);
|
||||
void TryLoadCreatePanel(UIPanelType uiPanelType, Transform parent = null);
|
||||
void TryRemovePanel(UIPanelType uiPanelType);
|
||||
void SetCanvasCamera(UnityEngine.Camera camera);
|
||||
UIPanel TryGetPanel(UIPanelType panelType);
|
||||
UIPanel TryGetSinglePanel(UIPanelType panelType);
|
||||
void TryRemovePanel(UIPanel panel);
|
||||
}
|
||||
|
||||
// Крайне неудобно пользоваться
|
||||
public class UIService : IUIPanelLoadedHandle, IUIService
|
||||
{
|
||||
private Dictionary<UIPanelType, UIPanel> _loadedPanels = new();
|
||||
private Dictionary<UIPanelType, UIPanel> _loadedSinglePanels = new();
|
||||
private Dictionary<UIPanelType, List<UIPanel>> _loadedMultiplePanels = new();
|
||||
|
||||
private EventBus.EventBus _eventBus;
|
||||
private IUIFactory _factory;
|
||||
@@ -40,49 +45,101 @@ namespace Code.Infrastructure.UI
|
||||
|
||||
public void OpenPanel(UIPanelType uiPanelType)
|
||||
{
|
||||
_loadedPanels[uiPanelType].gameObject.SetActive(true);
|
||||
_loadedPanels[uiPanelType].Open();
|
||||
_loadedSinglePanels[uiPanelType].gameObject.SetActive(true);
|
||||
_loadedSinglePanels[uiPanelType].Open();
|
||||
}
|
||||
|
||||
// TODO Close event
|
||||
public void ClosePanel(UIPanelType uiPanelType)
|
||||
{
|
||||
_loadedPanels[uiPanelType].Close(() => { _loadedPanels[uiPanelType].gameObject.SetActive(false); });
|
||||
_loadedSinglePanels[uiPanelType].Close(() =>
|
||||
{
|
||||
_loadedSinglePanels[uiPanelType].gameObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
|
||||
public void TryLoadPanel(UIPanelType uiPanelType) => _factory.LoadPanel(uiPanelType);
|
||||
public void TryLoadCreatePanel(UIPanelType uiPanelType, Transform parent = null) => _factory.LoadPanel(uiPanelType, parent);
|
||||
|
||||
public void UIPanelLoaded(UIPanel panel, UIPanelType panelType)
|
||||
{
|
||||
_loadedPanels.Add(panelType, panel);
|
||||
panel.PanelType = panelType;
|
||||
|
||||
if (!_factory.CheckIsMultiple(panelType))
|
||||
_loadedSinglePanels.Add(panelType, panel);
|
||||
else
|
||||
{
|
||||
if (!_loadedMultiplePanels.ContainsKey(panelType))
|
||||
_loadedMultiplePanels.Add(panelType, new List<UIPanel>());
|
||||
_loadedMultiplePanels[panelType].Add(panel);
|
||||
}
|
||||
|
||||
if (panel.InjectMeSenpai)
|
||||
GameObjectInjector.InjectRecursive(panel.gameObject, Container.RootContainer);
|
||||
else
|
||||
GameObjectInjector.InjectSingle(panel.gameObject, Container.RootContainer);
|
||||
// GameObjectInjector.InjectRecursive(panel.gameObject, SceneManager.GetActiveScene().GetSceneContainer()); // Скорее всего будут нужны компоненты текущей сцены
|
||||
|
||||
_eventBus.RaiseEvent<IUIPanelLoaded>(ui => ui.UILoaded(panelType));
|
||||
|
||||
panel.FireCreatedEvent();
|
||||
}
|
||||
|
||||
public void TryRemovePanel(UIPanelType uiPanelType)
|
||||
{
|
||||
_loadedPanels[uiPanelType].Close(() =>
|
||||
if (_factory.CheckIsMultiple(uiPanelType))
|
||||
{
|
||||
_loadedPanels[uiPanelType].gameObject.SetActive(false);
|
||||
UnityEngine.Debug.LogError("Это для единичных панелей олух");
|
||||
return;
|
||||
}
|
||||
_loadedSinglePanels[uiPanelType].Close(() =>
|
||||
{
|
||||
_loadedSinglePanels[uiPanelType].gameObject.SetActive(false);
|
||||
RemovePanel(uiPanelType);
|
||||
});
|
||||
}
|
||||
public void TryRemovePanel(UIPanel panel)
|
||||
{
|
||||
panel.Close(() =>
|
||||
{
|
||||
panel.gameObject.SetActive(false);
|
||||
RemovePanel(panel);
|
||||
// _eventBus.RaiseEvent<IUIMultiplePanelHandle>(x=> x.UIMultiplePanelRemoved(panel));
|
||||
});
|
||||
}
|
||||
|
||||
private void RemovePanel(UIPanelType panelType)
|
||||
{
|
||||
_factory.ReleasePanel(_loadedPanels[panelType]);
|
||||
_loadedPanels.Remove(panelType);
|
||||
if (!_factory.CheckIsMultiple(panelType))
|
||||
{
|
||||
var temp = _loadedSinglePanels[panelType];
|
||||
_loadedSinglePanels.Remove(panelType);
|
||||
|
||||
temp.FireRemovedEvent();
|
||||
|
||||
_factory.ReleasePanel(temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
var temp = _loadedMultiplePanels[panelType];
|
||||
_loadedMultiplePanels.Remove(panelType);
|
||||
|
||||
foreach (var panel in temp)
|
||||
{
|
||||
panel.FireRemovedEvent();
|
||||
_factory.ReleasePanel(panel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UIPanel TryGetPanel(UIPanelType panelType) => _loadedPanels.GetValueOrDefault(panelType);
|
||||
}
|
||||
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 interface IUIPanelLoaded : IGlobalSubscriber
|
||||
{
|
||||
void UILoaded(UIPanelType uiPanelType);
|
||||
public UIPanel TryGetSinglePanel(UIPanelType panelType) => _loadedSinglePanels.GetValueOrDefault(panelType);
|
||||
public List<UIPanel> TryGetMultiplePanels(UIPanelType panelType) => _loadedMultiplePanels.GetValueOrDefault(panelType);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user