Added HUD
This commit is contained in:
parent
3238777f3c
commit
167696cc3d
@ -382,6 +382,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 1350079066}
|
||||
- component: {fileID: 1350079067}
|
||||
- component: {fileID: 1350079068}
|
||||
m_Layer: 0
|
||||
m_Name: HUD
|
||||
m_TagString: Untagged
|
||||
@ -427,6 +428,19 @@ MonoBehaviour:
|
||||
m_PivotReferenceSize: 0
|
||||
m_Pivot: 0
|
||||
m_WorldSpaceCollider: {fileID: 0}
|
||||
--- !u!114 &1350079068
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1350079065}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2b9d906c9cda89d409b36b2d9dd22164, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::HUDService
|
||||
uiDocument: {fileID: 1350079067}
|
||||
--- !u!1 &1567913721
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -502,6 +516,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
playerJoiner: {fileID: 0}
|
||||
bgm: {fileID: 1072830981}
|
||||
hudService: {fileID: 1350079068}
|
||||
--- !u!4 &1695492504
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -7,6 +7,6 @@ namespace Data
|
||||
{
|
||||
public string UnitName;
|
||||
public float MoveSpeed;
|
||||
public float MaxHP;
|
||||
public int MaxHP;
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using State;
|
||||
using State.GameStateMachine;
|
||||
using State.PawnStateMachine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.UI;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
@ -34,13 +32,18 @@ namespace Managers
|
||||
{
|
||||
Debug.Log("Player joined!");
|
||||
_players.Add(playerInput);
|
||||
var player = playerInput.gameObject.GetComponent<Player.Player>();
|
||||
player.playerIndex = _players.Count - 1;
|
||||
|
||||
// TODO: Move all of this to a player spawner
|
||||
GameStateMachine.Instance.ChangeState(new PlayLevel());
|
||||
var character = Instantiate(characterPrefabs[_players.Count - 1]);
|
||||
var playerStateMachine = playerInput.gameObject.GetComponent<PawnStateMachine>();
|
||||
playerStateMachine.controlledPawn = character.GetComponent<Pawn>();
|
||||
playerInput.gameObject.GetComponent<Player.Player>().controlledPawn = character.GetComponent<Pawn>();
|
||||
player.controlledPawn = character.GetComponent<Pawn>();
|
||||
|
||||
var pawnStateMachine = playerInput.gameObject.GetComponent<PawnStateMachine>();
|
||||
pawnStateMachine.controlledPawn = player.controlledPawn;
|
||||
|
||||
Services.Instance.HUD.Register(player);
|
||||
playerInput.actions.Enable();
|
||||
}
|
||||
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
using UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
public class Services : MonoBehaviour
|
||||
{
|
||||
public static Services Instance { get; private set; }
|
||||
|
||||
public PlayerJoiner PlayerJoiner => playerJoiner;
|
||||
public BGM BGM => bgm;
|
||||
|
||||
[FormerlySerializedAs("inputCoordinator")] [FormerlySerializedAs("inputManager")] [FormerlySerializedAs("inputRouter")] [SerializeField] private PlayerJoiner playerJoiner;
|
||||
public HUDService HUD => hudService;
|
||||
|
||||
[SerializeField] private PlayerJoiner playerJoiner;
|
||||
[SerializeField] private BGM bgm;
|
||||
[SerializeField] private HUDService hudService;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
|
||||
@ -4,14 +4,15 @@ using UnityEngine;
|
||||
|
||||
public class Pawn : MonoBehaviour
|
||||
{
|
||||
public event Action<int> HPUpdated;
|
||||
public int MaxHP { get; protected set; }
|
||||
public int CurrentHP { get; protected set; }
|
||||
public Animator Animator => animator;
|
||||
|
||||
[SerializeField] private UnitData unitData;
|
||||
[SerializeField] private SpriteRenderer spriteRenderer;
|
||||
[SerializeField] private Animator animator;
|
||||
|
||||
protected float MaxHP;
|
||||
protected float CurrentHP;
|
||||
|
||||
protected bool IsDead;
|
||||
|
||||
private Vector2 _moveInput;
|
||||
@ -22,10 +23,12 @@ public class Pawn : MonoBehaviour
|
||||
CurrentHP = MaxHP;
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
public void TakeDamage(int damage)
|
||||
{
|
||||
//animator.Play("HURT");
|
||||
CurrentHP -= damage;
|
||||
CurrentHP = Mathf.Clamp(CurrentHP, 0, MaxHP);
|
||||
HPUpdated?.Invoke(CurrentHP);
|
||||
CheckDeath();
|
||||
}
|
||||
|
||||
|
||||
@ -20,10 +20,13 @@ namespace Player
|
||||
_map = _playerInput.actions.FindActionMap("Player", throwIfNotFound: true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
pawnStateMachine.SetMove(_map["Move"].ReadValue<Vector2>());
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_map["Move"].performed += OnMovePerformed;
|
||||
_map["Move"].canceled += OnMoveCanceled;
|
||||
_map["Attack"].performed += OnAttackPerformed;
|
||||
_map["Jump"].performed += OnJumpPerformed;
|
||||
_map["Pause"].performed += OnPausePerformed;
|
||||
@ -31,8 +34,6 @@ namespace Player
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_map["Move"].performed -= OnMovePerformed;
|
||||
_map["Move"].canceled -= OnMoveCanceled;
|
||||
_map["Attack"].performed -= OnAttackPerformed;
|
||||
_map["Jump"].performed -= OnJumpPerformed;
|
||||
_map["Pause"].performed -= OnPausePerformed;
|
||||
@ -52,15 +53,5 @@ namespace Player
|
||||
{
|
||||
pawnStateMachine.Issue(GameState.Command.Attack);
|
||||
}
|
||||
|
||||
private void OnMoveCanceled(InputAction.CallbackContext obj)
|
||||
{
|
||||
pawnStateMachine.SetMove(Vector2.zero);
|
||||
}
|
||||
|
||||
private void OnMovePerformed(InputAction.CallbackContext obj)
|
||||
{
|
||||
pawnStateMachine.SetMove(obj.ReadValue<Vector2>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
@ -6,11 +7,17 @@ namespace Player
|
||||
[RequireComponent(typeof(PlayerInput))]
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
public int playerIndex;
|
||||
public Pawn controlledPawn;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
public void Possess(Pawn pawn)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ namespace State.PawnStateMachine
|
||||
public override void OnEnter(StateMachine machine)
|
||||
{
|
||||
base.OnEnter(machine);
|
||||
((PawnStateMachine)StateMachine).controlledPawn.HandleMove(Vector2.zero);
|
||||
StateMachine.StartCoroutine(PlayAttackAnimation());
|
||||
}
|
||||
|
||||
|
||||
8
Assets/Scripts/UI.meta
Normal file
8
Assets/Scripts/UI.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c601ad143cafd042a99abe0068d953e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
37
Assets/Scripts/UI/HUDService.cs
Normal file
37
Assets/Scripts/UI/HUDService.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class HUDService : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private UIDocument uiDocument;
|
||||
private VisualElement player1Hp;
|
||||
private VisualElement player2Hp;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
player1Hp = uiDocument.rootVisualElement.Q<VisualElement>("player1HP");
|
||||
player2Hp = uiDocument.rootVisualElement.Q<VisualElement>("player2HP");
|
||||
}
|
||||
|
||||
public void Register(Player.Player player)
|
||||
{
|
||||
var progressBar = player.playerIndex == 0 ? player1Hp : player2Hp;
|
||||
progressBar.Q<Label>().text = player.playerIndex == 0 ? "BLOOD JOE" : "BONE JACK";
|
||||
progressBar.style.visibility = Visibility.Visible;
|
||||
progressBar.Q<ProgressBar>().highValue = player.controlledPawn.MaxHP;
|
||||
progressBar.Q<ProgressBar>().value = player.controlledPawn.CurrentHP;
|
||||
player.controlledPawn.HPUpdated += (newHp) =>
|
||||
{
|
||||
HandleUpdated(player.playerIndex, newHp);
|
||||
};
|
||||
}
|
||||
|
||||
private void HandleUpdated(int playerIndex, int newHP)
|
||||
{
|
||||
var progressBar = playerIndex == 0 ? player1Hp : player2Hp;
|
||||
progressBar.Q<ProgressBar>().value = newHP;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/HUDService.cs.meta
Normal file
2
Assets/Scripts/UI/HUDService.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b9d906c9cda89d409b36b2d9dd22164
|
||||
@ -1,6 +1,7 @@
|
||||
<ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||
<ui:Template name="LifeBar" src="project://database/Assets/UI/LifeBar.uxml?fileID=9197481963319205126&guid=eeea9c427ffdf0b4180407197f9ccbbd&type=3#LifeBar" />
|
||||
<ui:VisualElement style="flex-grow: 1; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px;">
|
||||
<ui:Instance template="LifeBar" name="LifeBar" style="width: 40%;" />
|
||||
<ui:Instance template="LifeBar" name="player1HP" style="width: 40%; visibility: hidden; display: flex; position: absolute; left: 20px; top: 20px;" />
|
||||
<ui:Instance template="LifeBar" name="player2HP" style="width: 40%; visibility: hidden; display: flex; right: 20px; top: 20px; position: absolute;" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<ui:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||
<ui:VisualElement name="Container" style="flex-grow: 1; flex-direction: row; align-items: center;">
|
||||
<ui:Label text="LIFE" style="font-size: 24px; color: rgb(255, 255, 255); -unity-text-outline-width: 1.5px; -unity-text-outline-color: rgb(0, 0, 0); -unity-font-style: bold; text-shadow: 6.9px 3.4px 0 rgb(0, 0, 0);" />
|
||||
<ui:VisualElement style="flex-grow: 1; flex-direction: row;">
|
||||
<ui:VisualElement name="Container" style="flex-grow: 1; flex-direction: column; align-items: flex-start;">
|
||||
<ui:Label text="LIFE" name="name" style="font-size: 18px; color: rgb(255, 255, 255); -unity-text-outline-width: 1.5px; -unity-text-outline-color: rgb(0, 0, 0); -unity-font-style: italic; text-shadow: 6.9px 3.4px 0 rgb(0, 0, 0); position: relative; top: 0; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; -unity-font-definition: url("project://database/Assets/UI/prstartk.ttf?fileID=12800000&guid=edb92055addc1b64ea4c0dde6ffaffe3&type=3#prstartk");" />
|
||||
<ui:VisualElement style="flex-grow: 1; flex-direction: row; width: 100%;">
|
||||
<ui:ProgressBar value="75" style="width: 95%;" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
|
||||
BIN
Assets/UI/prstartk.ttf
Normal file
BIN
Assets/UI/prstartk.ttf
Normal file
Binary file not shown.
21
Assets/UI/prstartk.ttf.meta
Normal file
21
Assets/UI/prstartk.ttf.meta
Normal file
@ -0,0 +1,21 @@
|
||||
fileFormatVersion: 2
|
||||
guid: edb92055addc1b64ea4c0dde6ffaffe3
|
||||
TrueTypeFontImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 4
|
||||
fontSize: 16
|
||||
forceTextureCase: -2
|
||||
characterSpacing: 0
|
||||
characterPadding: 1
|
||||
includeFontData: 1
|
||||
fontNames:
|
||||
- Press Start K
|
||||
fallbackFontReferences: []
|
||||
customCharacters:
|
||||
fontRenderingMode: 0
|
||||
ascentCalculationMode: 1
|
||||
useLegacyBoundsCalculation: 0
|
||||
shouldRoundAdvanceValue: 1
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user