Skip to content

Commit

Permalink
Remove hardwired dependencies on HUD bars in HUD prefab
Browse files Browse the repository at this point in the history
  • Loading branch information
12joan committed Sep 18, 2024
1 parent 9f5c69d commit 8150477
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 35 deletions.
12 changes: 11 additions & 1 deletion Assets/Unity/Prefabs/HUD.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ PrefabInstance:
- target: {fileID: 8769710587028786407, guid: 819a71e4f3b664956b68bdccb2ec19ff,
type: 3}
propertyPath: m_fontSize
value: 39.2
value: 18
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
Expand Down Expand Up @@ -2088,6 +2088,11 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 9050843315106131602}
m_Modifications:
- target: {fileID: 894301866376661167, guid: 480c447e9005243ddab00b927f5dc0b2,
type: 3}
propertyPath: IsPlayerHitPoints
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1161413060644883872, guid: 480c447e9005243ddab00b927f5dc0b2,
type: 3}
propertyPath: m_Sprite
Expand Down Expand Up @@ -2622,6 +2627,11 @@ PrefabInstance:
propertyPath: Visible
value: 0
objectReference: {fileID: 0}
- target: {fileID: 894301866376661167, guid: 480c447e9005243ddab00b927f5dc0b2,
type: 3}
propertyPath: IsReload
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1161413060644883872, guid: 480c447e9005243ddab00b927f5dc0b2,
type: 3}
propertyPath: m_Sprite
Expand Down
21 changes: 6 additions & 15 deletions Assets/Unity/Prefabs/HUD/Weapon Info.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ RectTransform:
- {fileID: 3936300542763304633}
- {fileID: 2196209988136474760}
m_Father: {fileID: 6569192321037793972}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -119,7 +118,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4543986918124656905}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
Expand Down Expand Up @@ -200,7 +198,6 @@ RectTransform:
- {fileID: 3195269625368659169}
- {fileID: 509813257009828072}
m_Father: {fileID: 6569192321037793972}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -257,10 +254,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: da12b954f460e4413808eb78618261b5, type: 3}
m_Name:
m_EditorClassIdentifier:
IsPlayerHitPoints: 0
IsReload: 0
DefaultProgress: 1
DefaultVisible: 1
FilledImage: {fileID: 763044542153686257}
AllImages: []
Progress: 0
Visible: 1
--- !u!114 &4985608710205232365
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -312,7 +311,6 @@ RectTransform:
m_Children:
- {fileID: 2399802717935203539}
m_Father: {fileID: 8112719340478892494}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -369,7 +367,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8112719340478892494}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -427,7 +424,6 @@ RectTransform:
m_Children:
- {fileID: 6555339997570618429}
m_Father: {fileID: 4543986918124656905}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
Expand Down Expand Up @@ -486,7 +482,6 @@ RectTransform:
- {fileID: 4543986918124656905}
- {fileID: 8112719340478892494}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
Expand Down Expand Up @@ -620,7 +615,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 3936300542763304633}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
Expand Down Expand Up @@ -770,7 +764,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8112719340478892494}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -939,7 +932,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4543986918124656905}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
Expand Down Expand Up @@ -997,6 +989,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Image: {fileID: 6989871240212923606}
SpriteRenderer: {fileID: 0}
MinSpeed: 2
MaxSpeed: 2
--- !u!1 &7803813928590300274
Expand Down Expand Up @@ -1031,7 +1024,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8112719340478892494}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -1128,7 +1120,6 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 509813257009828072}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
Expand Down Expand Up @@ -1191,7 +1182,7 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 39.2
m_fontSize: 18
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 1
Expand Down
8 changes: 4 additions & 4 deletions Assets/Unity/Prefabs/Level Essentials.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ PrefabInstance:
- target: {fileID: 1280701673831173212, guid: 185784beef2224b11a285ffa14ebe05e,
type: 3}
propertyPath: m_SizeDelta.x
value: 104.07
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1280701673831173212, guid: 185784beef2224b11a285ffa14ebe05e,
type: 3}
Expand Down Expand Up @@ -1355,7 +1355,7 @@ PrefabInstance:
- target: {fileID: 4706342347603221291, guid: 185784beef2224b11a285ffa14ebe05e,
type: 3}
propertyPath: m_SizeDelta.x
value: 153.57
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4706342347603221291, guid: 185784beef2224b11a285ffa14ebe05e,
type: 3}
Expand Down Expand Up @@ -1495,7 +1495,7 @@ PrefabInstance:
- target: {fileID: 7913260233035610828, guid: 185784beef2224b11a285ffa14ebe05e,
type: 3}
propertyPath: m_SizeDelta.x
value: 189.57
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7913260233035610828, guid: 185784beef2224b11a285ffa14ebe05e,
type: 3}
Expand All @@ -1520,7 +1520,7 @@ PrefabInstance:
- target: {fileID: 8805420024808595057, guid: 185784beef2224b11a285ffa14ebe05e,
type: 3}
propertyPath: m_SizeDelta.x
value: 99.57
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8805420024808595057, guid: 185784beef2224b11a285ffa14ebe05e,
type: 3}
Expand Down
3 changes: 1 addition & 2 deletions Assets/src/DelayPhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public override void LocalBegin() {
public override void WhilePhaseRunning() {
float progress = Stopwatch.Progress(Delay);

if (HUDBar != null)
HUDBar.Progress = progress;
HUDBar?.SetProgress(progress);

if (progress >= 1f) {
if (PauseGameplay)
Expand Down
4 changes: 2 additions & 2 deletions Assets/src/EnemyHitPointEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void Awake() {
if (HealthBar != null) {
hitPoints.OnUpdate.AddListener(hp => {
float relativeHP = hp.Current / hp.Maximum;
HealthBar.Progress = relativeHP;
HealthBar.gameObject.SetActive(!HideHealthBarWhenFullOrEmpty || (relativeHP > 0 && relativeHP < 1));
HealthBar.SetProgress(relativeHP);
HealthBar.SetVisible(!HideHealthBarWhenFullOrEmpty || (relativeHP > 0 && relativeHP < 1));
});
}

Expand Down
33 changes: 30 additions & 3 deletions Assets/src/HUDBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,45 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Serialization;

public class HUDBar : MonoBehaviour {
public static HUDBar PlayerHitPoints, Reload;
public bool IsPlayerHitPoints, IsReload;

[FormerlySerializedAs("Progress")]
public float DefaultProgress = 1f;

[FormerlySerializedAs("Visible")]
public bool DefaultVisible = true;

public Image FilledImage;
public List<Image> AllImages;

public float Progress;
public bool Visible;
private float Progress;
private bool Visible;

void Awake() {
if (IsPlayerHitPoints)
PlayerHitPoints = this;

if (IsReload)
Reload = this;

Progress = DefaultProgress;
Visible = DefaultVisible;
}

void Update() {
AllImages.ForEach(img => img.enabled = Visible);
AllImages.ForEach(image => image.enabled = Visible);
FilledImage.fillAmount = Progress;
}

public void SetProgress(float progress) {
Progress = progress;
}

public void SetVisible(bool visible) {
Visible = visible;
}
}
2 changes: 1 addition & 1 deletion Assets/src/Level3Started.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class Level3Started : MonoBehaviour {
public HUDBar BossProgressBar;

void Update() {
BossProgressBar.Progress = PhaseScheduler.Progress();
BossProgressBar.SetProgress(PhaseScheduler.Progress());
}
}
3 changes: 1 addition & 2 deletions Assets/src/PlayerHitPointEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

public class PlayerHitPointEvents : MonoBehaviour {
public HitPoints OverrideHitPoints;
public HUDBar HealthBar;
public string GameOverScene = "Game Over";

void Awake() {
HitPoints hitPoints = OverrideHitPoints ?? GetComponent<HitPoints>();

hitPoints.OnUpdate.AddListener(hp => {
HealthBar.Progress = hp.Current / hp.Maximum;
HUDBar.PlayerHitPoints?.SetProgress(hp.Current / hp.Maximum);
});

hitPoints.OnDecrease.AddListener(hp => {
Expand Down
2 changes: 1 addition & 1 deletion Assets/src/SegmentedProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SegmentedProgressBar : MonoBehaviour {

void Update() {
Segments.ForEach(segment => {
segment.HUDBar.Progress = segment.ProgressMetric.Current() / segment.ProgressMetric.Total();
segment.HUDBar.SetProgress(segment.ProgressMetric.Current() / segment.ProgressMetric.Total());
});
}
}
2 changes: 1 addition & 1 deletion Assets/src/WeaponInfoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void SetWeaponName(string name) {
}

public void SetAmmunition(int current, int max) {
AmmunitionBar.Progress = (float)current / (float)max;
AmmunitionBar.SetProgress((float)current / (float)max);
ReloadIndicator.Visible = current == 0;
}
}
5 changes: 2 additions & 3 deletions Assets/src/WeaponReload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

public class WeaponReload : MonoBehaviour {
public PlaySound PlaySound;
public HUDBar ReloadBar;
public MovementManager MovementManager;

private Stopwatch ReloadStopwatch = null;
Expand Down Expand Up @@ -35,13 +34,13 @@ void Update() {

if (InProgress()) {
if (CanReload()) {
ReloadBar.Progress = progress;
HUDBar.Reload?.SetProgress(progress);
} else {
InterruptReloading();
}
}

ReloadBar.Visible = InProgress();
HUDBar.Reload?.SetVisible(InProgress());
}

private void BeginReload() {
Expand Down

0 comments on commit 8150477

Please sign in to comment.