Межинтерфейс
This commit is contained in:
1 parent
45fe19be24
commit
edf3821c0d
9 files changed
+74
-45
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
using Code.App.StateMachine;
|
using Code.App.StateMachine;
|
||||||
using Code.StateMachine;
|
using Code.StateMachine;
|
||||||
|
using Code.UI;
|
||||||
|
|
||||||
namespace Code.App.AppStates
|
namespace Code.App.AppStates
|
||||||
{
|
{
|
||||||
@@ -10,6 +11,9 @@ namespace Code.App.AppStates
|
|||||||
|
|
||||||
public override void EnterState()
|
public override void EnterState()
|
||||||
{
|
{
|
||||||
|
Context.UIService.LoadingScreen.Show();
|
||||||
|
Context.UIService.SwitchPanelTo(UIPanel.GameOver);
|
||||||
|
|
||||||
base.EnterState();
|
base.EnterState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ namespace Code.App.AppStates
|
|||||||
|
|
||||||
_playerMoney = Context.PlayerFactory.CreatePlayerMoney();
|
_playerMoney = Context.PlayerFactory.CreatePlayerMoney();
|
||||||
_playerHealth = Context.PlayerFactory.CreatePlayerHealth();
|
_playerHealth = Context.PlayerFactory.CreatePlayerHealth();
|
||||||
|
|
||||||
|
_playerHealth.OnDeath += EndGame;
|
||||||
|
|
||||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveHealth, GiveHealth);
|
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveHealth, GiveHealth);
|
||||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveMoney, GiveMoney);
|
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveMoney, GiveMoney);
|
||||||
@@ -46,6 +48,8 @@ namespace Code.App.AppStates
|
|||||||
base.EnterState();
|
base.EnterState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Debug
|
||||||
private void GiveHealth(InputAction.CallbackContext context)
|
private void GiveHealth(InputAction.CallbackContext context)
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.Log("Giving health");
|
UnityEngine.Debug.Log("Giving health");
|
||||||
@@ -74,6 +78,11 @@ namespace Code.App.AppStates
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EndGame()
|
||||||
|
{
|
||||||
|
Context.StateMachine.SwitchState(AppState.GameOver);
|
||||||
|
}
|
||||||
|
|
||||||
public override void ExitState()
|
public override void ExitState()
|
||||||
{
|
{
|
||||||
_playerHealth = null;
|
_playerHealth = null;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace Code.App
|
|||||||
containerBuilder.AddSingleton(typeof(PlayerFactory), typeof(IPlayerFactory));
|
containerBuilder.AddSingleton(typeof(PlayerFactory), typeof(IPlayerFactory));
|
||||||
|
|
||||||
InitializeCamera(containerBuilder, staticDataService);
|
InitializeCamera(containerBuilder, staticDataService);
|
||||||
|
containerBuilder.AddSingleton(typeof(UIFactory), typeof(IUIFactory));
|
||||||
containerBuilder.AddSingleton(typeof(UIService), typeof(IUIService));
|
containerBuilder.AddSingleton(typeof(UIService), typeof(IUIService));
|
||||||
containerBuilder.AddSingleton(typeof(SceneLoaderService), typeof(ISceneLoaderService));
|
containerBuilder.AddSingleton(typeof(SceneLoaderService), typeof(ISceneLoaderService));
|
||||||
|
|
||||||
|
|||||||
@@ -10,22 +10,28 @@ namespace Code.UI
|
|||||||
{
|
{
|
||||||
[SerializeField] private Image dispatcher;
|
[SerializeField] private Image dispatcher;
|
||||||
[SerializeField] private TMP_Text timer;
|
[SerializeField] private TMP_Text timer;
|
||||||
|
[SerializeField] private Image healthBar;
|
||||||
private HealthBar _healthBar;
|
[SerializeField] private TMP_Text moneyText;
|
||||||
private MoneyBar _moneyBar;
|
|
||||||
|
|
||||||
public void Initialize(PlayerMoney money, PlayerHealth health, HealthBar healthBar = null, MoneyBar moneyBar = null)
|
private void MoneyUpdate(int count, int money)
|
||||||
{
|
{
|
||||||
_healthBar = healthBar;
|
// TODO Анимация получения\потери
|
||||||
_moneyBar = moneyBar;
|
moneyText.text = money.ToString();
|
||||||
|
}
|
||||||
money.OnMoneyGet += _moneyBar.MoneyUpdate;
|
private void HealthUpdate(int count, PlayerHealth health)
|
||||||
money.OnMoneyLoose += _moneyBar.MoneyUpdate;
|
{
|
||||||
_moneyBar.MoneyUpdate(0,money.Money);
|
// TODO Анимация потери
|
||||||
|
float fillAmount = (float)health.HealthPoints / health.MaxHealthPoints;
|
||||||
health.OnDamage += _healthBar.HealthUpdate;
|
healthBar.fillAmount = fillAmount;
|
||||||
_healthBar.HealthUpdate(0,health);
|
}
|
||||||
|
public void Initialize(PlayerMoney money, PlayerHealth health)
|
||||||
|
{
|
||||||
|
money.OnMoneyGet += MoneyUpdate;
|
||||||
|
money.OnMoneyLoose += MoneyUpdate;
|
||||||
|
MoneyUpdate(0,money.Money);
|
||||||
|
|
||||||
|
health.OnDamage += HealthUpdate;
|
||||||
|
HealthUpdate(0,health);
|
||||||
}
|
}
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Code.UI
|
|||||||
{
|
{
|
||||||
public interface IUIFactory
|
public interface IUIFactory
|
||||||
{
|
{
|
||||||
MoneyBar CreateMoneybar(Canvas canvas);
|
Canvas CreateCanvas();
|
||||||
HealthBar CreateHealthbar(Canvas canvas);
|
UIElement CreatePanel(Canvas canvas, UIPanel uiPanel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
using Code.UI.GameplayElements;
|
|
||||||
using Reflex.Attributes;
|
using Reflex.Attributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -6,10 +5,20 @@ namespace Code.UI
|
|||||||
{
|
{
|
||||||
public class UIFactory : IUIFactory
|
public class UIFactory : IUIFactory
|
||||||
{
|
{
|
||||||
[Inject] private HealthBar healthbarPrefab;
|
[Inject] private UIElement[] _uiPanelsPrefabs;
|
||||||
[Inject] private MoneyBar moneybarPrefab;
|
[Inject] private Canvas _canvasPrefab;
|
||||||
|
|
||||||
public MoneyBar CreateMoneybar(Canvas canvas) => Object.Instantiate(moneybarPrefab, canvas.transform);
|
public Canvas CreateCanvas()
|
||||||
public HealthBar CreateHealthbar(Canvas canvas) => Object.Instantiate(healthbarPrefab, canvas.transform);
|
{
|
||||||
|
Canvas canvas = Object.Instantiate(_canvasPrefab);
|
||||||
|
Object.DontDestroyOnLoad(canvas);
|
||||||
|
|
||||||
|
return canvas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UIElement CreatePanel(Canvas canvas, UIPanel uiPanel)
|
||||||
|
{
|
||||||
|
return Object.Instantiate(_uiPanelsPrefabs[(int)uiPanel], canvas.transform);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace Code.UI
|
|||||||
{
|
{
|
||||||
Loading,
|
Loading,
|
||||||
MainMenu,
|
MainMenu,
|
||||||
Gameplay
|
Gameplay,
|
||||||
|
GameOver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,19 +4,18 @@ namespace Code.UI
|
|||||||
{
|
{
|
||||||
public class UIService : IUIService
|
public class UIService : IUIService
|
||||||
{
|
{
|
||||||
private UIElement[] _uiPanelsPrefabs;
|
|
||||||
private Canvas _canvas;
|
private Canvas _canvas;
|
||||||
|
private IUIFactory _factory;
|
||||||
|
|
||||||
public UIElement CurrentPanel { get; private set; }
|
public UIElement CurrentPanel { get; private set; }
|
||||||
public LoadingPanel LoadingScreen { get; private set; }
|
public LoadingPanel LoadingScreen { get; private set; }
|
||||||
|
|
||||||
public UIService(UIElement[] uiPanelsPrefabs, Canvas canvas)
|
public UIService(IUIFactory factory)
|
||||||
{
|
{
|
||||||
_canvas = Object.Instantiate(canvas);
|
_factory = factory;
|
||||||
Object.DontDestroyOnLoad(_canvas);
|
_canvas = _factory.CreateCanvas();
|
||||||
|
|
||||||
_uiPanelsPrefabs = uiPanelsPrefabs;
|
LoadingScreen = (LoadingPanel) _factory.CreatePanel(_canvas,UIPanel.Loading);
|
||||||
|
|
||||||
LoadingScreen = (LoadingPanel) Object.Instantiate(_uiPanelsPrefabs[(int)UIPanel.Loading], _canvas.transform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnablePanel() => CurrentPanel.gameObject.SetActive(true);
|
public void EnablePanel() => CurrentPanel.gameObject.SetActive(true);
|
||||||
@@ -26,7 +25,7 @@ namespace Code.UI
|
|||||||
{
|
{
|
||||||
if(CurrentPanel) Object.Destroy(CurrentPanel.gameObject);
|
if(CurrentPanel) Object.Destroy(CurrentPanel.gameObject);
|
||||||
|
|
||||||
CurrentPanel = Object.Instantiate(_uiPanelsPrefabs[(int)uiPanel], _canvas.transform);
|
CurrentPanel = _factory.CreatePanel(_canvas, uiPanel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,10 +231,10 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: d79893d2e9024719924dc5c15d582e33, type: 3}
|
m_Script: {fileID: 11500000, guid: d79893d2e9024719924dc5c15d582e33, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::Code.UI.GameplayPanel
|
m_EditorClassIdentifier: Assembly-CSharp::Code.UI.GameplayPanel
|
||||||
healthBar: {fileID: 2665776386830848828}
|
|
||||||
dispatcher: {fileID: 3222823750140455214}
|
dispatcher: {fileID: 3222823750140455214}
|
||||||
moneyText: {fileID: 6387758596913220167}
|
|
||||||
timer: {fileID: 1501140738844702411}
|
timer: {fileID: 1501140738844702411}
|
||||||
|
healthBar: {fileID: 2665776386830848828}
|
||||||
|
moneyText: {fileID: 6387758596913220167}
|
||||||
--- !u!1 &1919154497512289354
|
--- !u!1 &1919154497512289354
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -270,7 +270,7 @@ RectTransform:
|
|||||||
m_AnchorMin: {x: 1, y: 1}
|
m_AnchorMin: {x: 1, y: 1}
|
||||||
m_AnchorMax: {x: 1, y: 1}
|
m_AnchorMax: {x: 1, y: 1}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
m_SizeDelta: {x: 135.31158, y: 37.73999}
|
m_SizeDelta: {x: 319.71, y: 107.84}
|
||||||
m_Pivot: {x: 1, y: 1}
|
m_Pivot: {x: 1, y: 1}
|
||||||
--- !u!222 &9096664839021089168
|
--- !u!222 &9096664839021089168
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
@@ -327,14 +327,14 @@ MonoBehaviour:
|
|||||||
m_faceColor:
|
m_faceColor:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
rgba: 4294967295
|
rgba: 4294967295
|
||||||
m_fontSize: 36
|
m_fontSize: 105.6
|
||||||
m_fontSizeBase: 36
|
m_fontSizeBase: 105.6
|
||||||
m_fontWeight: 400
|
m_fontWeight: 400
|
||||||
m_enableAutoSizing: 0
|
m_enableAutoSizing: 0
|
||||||
m_fontSizeMin: 18
|
m_fontSizeMin: 18
|
||||||
m_fontSizeMax: 72
|
m_fontSizeMax: 72
|
||||||
m_fontStyle: 0
|
m_fontStyle: 0
|
||||||
m_HorizontalAlignment: 1
|
m_HorizontalAlignment: 2
|
||||||
m_VerticalAlignment: 512
|
m_VerticalAlignment: 512
|
||||||
m_textAlignment: 65535
|
m_textAlignment: 65535
|
||||||
m_characterSpacing: 0
|
m_characterSpacing: 0
|
||||||
@@ -406,7 +406,7 @@ RectTransform:
|
|||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
m_AnchorMax: {x: 0, y: 0}
|
m_AnchorMax: {x: 0, y: 0}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
m_SizeDelta: {x: 114.76929, y: 128.45679}
|
m_SizeDelta: {x: 291.7762, y: 376.2665}
|
||||||
m_Pivot: {x: 0, y: 0}
|
m_Pivot: {x: 0, y: 0}
|
||||||
--- !u!222 &5289021947733735622
|
--- !u!222 &5289021947733735622
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
@@ -481,7 +481,7 @@ RectTransform:
|
|||||||
m_AnchorMin: {x: 1, y: 1}
|
m_AnchorMin: {x: 1, y: 1}
|
||||||
m_AnchorMax: {x: 1, y: 1}
|
m_AnchorMax: {x: 1, y: 1}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
m_SizeDelta: {x: 139.10437, y: 37.73999}
|
m_SizeDelta: {x: 319.7096, y: 107.842}
|
||||||
m_Pivot: {x: 1, y: 1}
|
m_Pivot: {x: 1, y: 1}
|
||||||
--- !u!222 &84950586336650232
|
--- !u!222 &84950586336650232
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
@@ -555,8 +555,8 @@ RectTransform:
|
|||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 1, y: 1}
|
m_AnchorMin: {x: 1, y: 1}
|
||||||
m_AnchorMax: {x: 1, y: 1}
|
m_AnchorMax: {x: 1, y: 1}
|
||||||
m_AnchoredPosition: {x: 1, y: -35}
|
m_AnchoredPosition: {x: -2, y: -107}
|
||||||
m_SizeDelta: {x: 117.510925, y: 46.700012}
|
m_SizeDelta: {x: 269.7093, y: 80.867}
|
||||||
m_Pivot: {x: 1, y: 1}
|
m_Pivot: {x: 1, y: 1}
|
||||||
--- !u!222 &1088048040329591264
|
--- !u!222 &1088048040329591264
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
@@ -613,8 +613,8 @@ MonoBehaviour:
|
|||||||
m_faceColor:
|
m_faceColor:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
rgba: 4294967295
|
rgba: 4294967295
|
||||||
m_fontSize: 36
|
m_fontSize: 71
|
||||||
m_fontSizeBase: 36
|
m_fontSizeBase: 71
|
||||||
m_fontWeight: 400
|
m_fontWeight: 400
|
||||||
m_enableAutoSizing: 0
|
m_enableAutoSizing: 0
|
||||||
m_fontSizeMin: 18
|
m_fontSizeMin: 18
|
||||||
@@ -692,7 +692,7 @@ RectTransform:
|
|||||||
m_AnchorMin: {x: 0, y: 1}
|
m_AnchorMin: {x: 0, y: 1}
|
||||||
m_AnchorMax: {x: 0, y: 1}
|
m_AnchorMax: {x: 0, y: 1}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
m_SizeDelta: {x: 240.0957, y: 46.76001}
|
m_SizeDelta: {x: 494.098, y: 102.7266}
|
||||||
m_Pivot: {x: 0, y: 1}
|
m_Pivot: {x: 0, y: 1}
|
||||||
--- !u!222 &1154202756743218800
|
--- !u!222 &1154202756743218800
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
@@ -766,8 +766,8 @@ RectTransform:
|
|||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 1, y: 1}
|
m_AnchorMin: {x: 1, y: 1}
|
||||||
m_AnchorMax: {x: 1, y: 1}
|
m_AnchorMax: {x: 1, y: 1}
|
||||||
m_AnchoredPosition: {x: 1, y: -35}
|
m_AnchoredPosition: {x: -2, y: -107.004395}
|
||||||
m_SizeDelta: {x: 109.52362, y: 38.674713}
|
m_SizeDelta: {x: 269.71, y: 80.867}
|
||||||
m_Pivot: {x: 1, y: 1}
|
m_Pivot: {x: 1, y: 1}
|
||||||
--- !u!222 &8440000272582601589
|
--- !u!222 &8440000272582601589
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
|
|||||||
Reference in new issue
Block a user