浏览代码

Various changes around health management

Fixed UIHealthBar reset hearts bug
Relocated UI event channels under the Health folder
Enemies no longer fire UpdateUI events
Fixed PigChef's missing sounds
/main
Ciro Continisio 3 年前
当前提交
5af375fa
共有 34 个文件被更改,包括 184 次插入204 次删除
  1. 4
      UOP1_Project/Assets/Prefabs/Characters/NPCs_BasePrefabs/Gluecose.prefab
  2. 6
      UOP1_Project/Assets/Prefabs/Characters/NPCs_BasePrefabs/Groen.prefab
  3. 4
      UOP1_Project/Assets/Prefabs/Characters/NPCs_BasePrefabs/Klipper.prefab
  4. 18
      UOP1_Project/Assets/Prefabs/Characters/PigChef.prefab
  5. 79
      UOP1_Project/Assets/Prefabs/UI/GameplayScene/Health System/UIHealthDisplay.prefab
  6. 2
      UOP1_Project/Assets/ScriptableObjects/Configs/Health/PigChef_Health.asset
  7. 3
      UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/DeathEvent.asset
  8. 7
      UOP1_Project/Assets/ScriptableObjects/Gameplay/GameState.asset
  9. 3
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/RespawnPlayer.asset
  10. 64
      UOP1_Project/Assets/Scripts/Characters/Damageable.cs
  11. 1
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/ChangeGameStateActionSO.cs
  12. 2
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/ResetHealthSO.cs
  13. 1
      UOP1_Project/Assets/Scripts/Events/ScriptableObjects/NPCMovementEventChannelSO.cs
  14. 8
      UOP1_Project/Assets/Scripts/Gameplay/GameStateSO.cs
  15. 2
      UOP1_Project/Assets/Scripts/SceneManagement/FallCatcher.cs
  16. 2
      UOP1_Project/Assets/Scripts/SceneManagement/LocationEntrance.cs
  17. 1
      UOP1_Project/Assets/Scripts/SceneManagement/LocationExit.cs
  18. 8
      UOP1_Project/Assets/Scripts/SceneManagement/SceneLoader.cs
  19. 59
      UOP1_Project/Assets/Scripts/SceneManagement/StartGame.cs
  20. 10
      UOP1_Project/Assets/Scripts/UI/Inventory/UIInventory.cs
  21. 30
      UOP1_Project/Assets/Scripts/UI/UIHealthBarManager.cs
  22. 9
      UOP1_Project/Assets/Scripts/UI/UIManager.cs
  23. 2
      UOP1_Project/Assets/Scripts/UI/UIPause.cs
  24. 17
      UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/Cure.asset
  25. 16
      UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/UpdateHealthUI.asset
  26. 15
      UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/RestoreHealthEvent.asset
  27. 15
      UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/UpdateHealthEvent.asset
  28. 0
      /UOP1_Project/Assets/ScriptableObjects/Configs/Health/PigChef_Health.asset.meta
  29. 0
      /UOP1_Project/Assets/ScriptableObjects/Configs/Health/PigChef_Health.asset
  30. 0
      /UOP1_Project/Assets/ScriptableObjects/EventChannels/Health.meta
  31. 0
      /UOP1_Project/Assets/ScriptableObjects/EventChannels/Health
  32. 0
      /UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/Cure.asset.meta
  33. 0
      /UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/UpdateHealthUI.asset.meta

4
UOP1_Project/Assets/Prefabs/Characters/NPCs_BasePrefabs/Gluecose.prefab


m_Name:
m_EditorClassIdentifier:
_healthConfigSO: {fileID: 11400000, guid: fd7717100e602c446847524419231170, type: 2}
_currentHealthSO: {fileID: 0}
_updateHealthUI: {fileID: 0}
_deathEvent: {fileID: 0}
_restoreHealth: {fileID: 0}
--- !u!114 &4729545407786248701
MonoBehaviour:
m_ObjectHideFlags: 0

6
UOP1_Project/Assets/Prefabs/Characters/NPCs_BasePrefabs/Groen.prefab


_getHitEffectSO: {fileID: 11400000, guid: b025ed16ca528cd4da2ec4afe52db2d4, type: 2}
_mainMeshRenderer: {fileID: 855856000742017355}
_droppableRewardSO: {fileID: 11400000, guid: 6158158d6ef9a3d47827f7851295bcef, type: 2}
_updateHealthEvent: {fileID: 11400000, guid: 2447a760b3f9f134f8730aa53c8d2ece, type: 2}
_deathEvent: {fileID: 11400000, guid: 0a29544909be226418bc1677ec369790, type: 2}
_restoreHealth: {fileID: 11400000, guid: de4a39f85969d44cba990125224ff7ef, type: 2}
_updateHealthUI: {fileID: 0}
_deathEvent: {fileID: 0}
_restoreHealth: {fileID: 0}
--- !u!114 &5617243883715629265
MonoBehaviour:
m_ObjectHideFlags: 0

4
UOP1_Project/Assets/Prefabs/Characters/NPCs_BasePrefabs/Klipper.prefab


m_Name:
m_EditorClassIdentifier:
_healthConfigSO: {fileID: 11400000, guid: fd7717100e602c446847524419231170, type: 2}
_currentHealthSO: {fileID: 0}
_updateHealthUI: {fileID: 0}
_deathEvent: {fileID: 0}
_restoreHealth: {fileID: 0}
--- !u!114 &1419279370
MonoBehaviour:
m_ObjectHideFlags: 0

18
UOP1_Project/Assets/Prefabs/Characters/PigChef.prefab


_getHitEffectSO: {fileID: 11400000, guid: 670b8ed8d060e674aa8c90b1187ea592, type: 2}
_mainMeshRenderer: {fileID: 2643181883930254223}
_droppableRewardSO: {fileID: 11400000, guid: f155590e3f62ce94ea050caa8fd5403e, type: 2}
_updateHealthEvent: {fileID: 11400000, guid: 2447a760b3f9f134f8730aa53c8d2ece, type: 2}
_updateHealthUI: {fileID: 11400000, guid: 2447a760b3f9f134f8730aa53c8d2ece, type: 2}
_deathEvent: {fileID: 11400000, guid: 0a29544909be226418bc1677ec369790, type: 2}
_restoreHealth: {fileID: 11400000, guid: de4a39f85969d44cba990125224ff7ef, type: 2}
--- !u!114 &3326384532942868502

_sfxEventChannel: {fileID: 11400000, guid: c3c796b7c31ad3647a3fbae42e74764e, type: 2}
_audioConfig: {fileID: 11400000, guid: 8d4217c8fabf9824490196f34baf326a, type: 2}
_gameState: {fileID: 11400000, guid: 159f9c22d98e249ceb08f2c5de2311a4, type: 2}
caneSwing: {fileID: 11400000, guid: ab9635318edf5da409588eec7deb39f2, type: 2}
liftoff: {fileID: 11400000, guid: 5977d168e99dd5443a497ed77990980f, type: 2}
land: {fileID: 11400000, guid: 9330bdadf131f5e4d9deee340edc1ba0, type: 2}
objectPickup: {fileID: 11400000, guid: 802be3a8bc6d3064e84c781cad59cb68, type: 2}
footstep: {fileID: 11400000, guid: 412141fe54999534a8d2800c2a567b55, type: 2}
getHit: {fileID: 11400000, guid: ff7bca3fec8a0d94f868719ec4d09492, type: 2}
die: {fileID: 11400000, guid: f6bff02f672df724b932fad0c85c18c5, type: 2}
talk: {fileID: 11400000, guid: 91724ce47d3ff5a4399664ebc35c1083, type: 2}
_caneSwing: {fileID: 11400000, guid: ab9635318edf5da409588eec7deb39f2, type: 2}
_liftoff: {fileID: 11400000, guid: 5977d168e99dd5443a497ed77990980f, type: 2}
_land: {fileID: 11400000, guid: 9330bdadf131f5e4d9deee340edc1ba0, type: 2}
_objectPickup: {fileID: 11400000, guid: 802be3a8bc6d3064e84c781cad59cb68, type: 2}
_footsteps: {fileID: 11400000, guid: ddb0fd735bd6f904eaae159c865eb35f, type: 2}
_getHit: {fileID: 11400000, guid: ff7bca3fec8a0d94f868719ec4d09492, type: 2}
_die: {fileID: 11400000, guid: f6bff02f672df724b932fad0c85c18c5, type: 2}
_talk: {fileID: 11400000, guid: 91724ce47d3ff5a4399664ebc35c1083, type: 2}
--- !u!114 &5557640735889932260
MonoBehaviour:
m_ObjectHideFlags: 0

79
UOP1_Project/Assets/Prefabs/UI/GameplayScene/Health System/UIHealthDisplay.prefab


serializedVersion: 6
m_Component:
- component: {fileID: 6352810064952983069}
- component: {fileID: 6395593152779691077}
- component: {fileID: 4731765889197187948}
- component: {fileID: 5798732883492657535}
- component: {fileID: 5382124729891650614}
- component: {fileID: 5382124729891650614}
m_Layer: 9
m_Name: UIHealthDisplay
m_TagString: Untagged

m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 20}
m_Pivot: {x: 0, y: 1}
--- !u!223 &6395593152779691077
Canvas:
--- !u!222 &5798732883492657535
CanvasRenderer:
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 2
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 25
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!114 &4731765889197187948
m_CullTransparentMesh: 1
--- !u!114 &5382124729891650614
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Script: {fileID: 11500000, guid: 30649d3a9faa99c48a7b1166b86bf2a0, type: 3}
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Padding:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 0
m_Spacing: 2
m_ChildForceExpandWidth: 1
m_ChildForceExpandHeight: 1
m_ChildControlWidth: 1
m_ChildControlHeight: 1
m_ChildScaleWidth: 0
m_ChildScaleHeight: 0
m_ReverseArrangement: 0
--- !u!114 &7057594148529581253
MonoBehaviour:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: f8dfad91156ef4bff806fff3c3f9eacd, type: 3}
m_Name:
m_EditorClassIdentifier:
_currentHealth: {fileID: 11400000, guid: 9f77d45699a310c4c893d07ae96f341a, type: 2}
_protagonistHealth: {fileID: 11400000, guid: 9f77d45699a310c4c893d07ae96f341a, type: 2}
_healthConfig: {fileID: 11400000, guid: e45145042f2750b448851311cae4a1ec, type: 2}
_heartImages:
- {fileID: 1496849399793334725}

- {fileID: 8717325367621303831}
_onPlayerInstantiated: {fileID: 11400000, guid: 2723b3f59f7ede3498fe7e385d2bb6ee,
type: 2}
_updateHealthEvent: {fileID: 11400000, guid: 2447a760b3f9f134f8730aa53c8d2ece, type: 2}
--- !u!114 &5382124729891650614
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2815881603653157998}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 30649d3a9faa99c48a7b1166b86bf2a0, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 0
m_Spacing: 2
m_ChildForceExpandWidth: 1
m_ChildForceExpandHeight: 1
m_ChildControlWidth: 1
m_ChildControlHeight: 1
m_ChildScaleWidth: 0
m_ChildScaleHeight: 0
m_ReverseArrangement: 0
_UIUpdateNeeded: {fileID: 11400000, guid: 2447a760b3f9f134f8730aa53c8d2ece, type: 2}
--- !u!1001 &1205441492839601400
PrefabInstance:
m_ObjectHideFlags: 0

2
UOP1_Project/Assets/ScriptableObjects/Configs/Health/PigChef_Health.asset


m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e005b717defd93a4c81276fd8caab626, type: 3}
m_Name: PlayerHealth
m_Name: PigChef_Health
m_EditorClassIdentifier:
_initialHealth: 50

3
UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/DeathEvent.asset


m_Script: {fileID: 11500000, guid: 7fafac715ff920c4383fed91a38a351e, type: 3}
m_Name: DeathEvent
m_EditorClassIdentifier:
description:
_guid: 0a29544909be226418bc1677ec369790
description: Player's Damageable broadcasts here when it dies

7
UOP1_Project/Assets/ScriptableObjects/Gameplay/GameState.asset


m_Script: {fileID: 11500000, guid: c332d1eba5f3e4a13955c85824ab978f, type: 3}
m_Name: GameState
m_EditorClassIdentifier:
_currentGameState: 0
_previousGameState: 6
_guid: 159f9c22d98e249ceb08f2c5de2311a4
description: Holds the current game state, and fires an event to notify when Combat
state is entered or left
_currentGameState: 6
_previousGameState: 0
_onCombatStateEvent: {fileID: 11400000, guid: 3c3f87199559eb0418616aedad568b71,
type: 2}

3
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/RespawnPlayer.asset


m_Script: {fileID: 11500000, guid: e8f810032e585a345baf668d3aff0bf5, type: 3}
m_Name: RespawnPlayer
m_EditorClassIdentifier:
description: Raises an OnSceneReady event to trigger the player instantiation
description: Raises an OnSceneReady event to trigger the player instantiation by
SpawnSystem
voidEvent: {fileID: 11400000, guid: b729e40fc41dd8b4ea7aaf5c857f7186, type: 2}

64
UOP1_Project/Assets/Scripts/Characters/Damageable.cs


public class Damageable : MonoBehaviour
{
[Header("Health")]
[Header("Combat")]
[SerializeField] private VoidEventChannelSO _updateHealthEvent = default;
[SerializeField] private VoidEventChannelSO _updateHealthUI = default;
[SerializeField] private IntEventChannelSO _restoreHealth = default;
[SerializeField] private IntEventChannelSO _restoreHealth = default; //Getting cured when eating food
//Flags that the StateMachine uses for Conditions to move between states
public Renderer MainMeshRenderer => _mainMeshRenderer;
public Renderer MainMeshRenderer => _mainMeshRenderer; //used to apply the hit flash effect
public event UnityAction OnDie;

//we create a new SO unique to this instance of the component. This is typical for NPCs.
//we create a new SO unique to this instance of the component. This is typical for enemies.
{
_currentHealthSO.SetMaxHealth(_healthConfigSO.InitialHealth);
_currentHealthSO.SetCurrentHealth(_healthConfigSO.InitialHealth);
_currentHealthSO.SetMaxHealth(_healthConfigSO.InitialHealth);
_currentHealthSO.SetCurrentHealth(_healthConfigSO.InitialHealth);
}
if (_updateHealthEvent != null)
_updateHealthEvent.RaiseEvent();
if (_updateHealthUI != null)
_updateHealthUI.RaiseEvent();
_restoreHealth.OnEventRaised += RestoreHealth;
if(_restoreHealth != null)
_restoreHealth.OnEventRaised += Cure;
_restoreHealth.OnEventRaised -= RestoreHealth;
}
public void Kill()
{
ReceiveAnAttack(_currentHealthSO.CurrentHealth);
if(_restoreHealth != null)
_restoreHealth.OnEventRaised -= Cure;
}
public void ReceiveAnAttack(int damage)

_currentHealthSO.InflictDamage(damage);
if (_updateHealthEvent != null)
_updateHealthEvent.RaiseEvent();
if (_updateHealthUI != null)
_updateHealthUI.RaiseEvent();
GetHit = true;

if (_deathEvent != null)
_deathEvent.RaiseEvent();
_currentHealthSO.SetCurrentHealth(_healthConfigSO.InitialHealth);
public void Kill()
{
ReceiveAnAttack(_currentHealthSO.CurrentHealth);
}
/// Called by the StateMachine action ResetHealth. Used to revive the stone critter.
/// Called by the StateMachine action ResetHealthSO. Used to revive the Rock critters.
public void ResetHealth()
public void Revive()
if (_updateHealthEvent != null)
_updateHealthEvent.RaiseEvent();
if (_updateHealthUI != null)
_updateHealthUI.RaiseEvent();
private void RestoreHealth(int healthToAdd)
/// <summary>
/// Used for cure events, like eating food. Triggered by an IntEventChannelSO.
/// </summary>
private void Cure(int healthToAdd)
{
if (IsDead)
return;

if (_updateHealthEvent != null)
_updateHealthEvent.RaiseEvent();
if (_updateHealthUI != null)
_updateHealthUI.RaiseEvent();
}
}

1
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/ChangeGameStateActionSO.cs


{
if (_whenToRun == Moment.OnStateEnter)
{
ChangeState();
}
}

2
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/ResetHealthSO.cs


public override void OnStateExit()
{
_damageableEntity.ResetHealth();
_damageableEntity.Revive();
}
}

1
UOP1_Project/Assets/Scripts/Events/ScriptableObjects/NPCMovementEventChannelSO.cs


/// <summary>
/// This class is used for Events that have one NPCMovementConfigSO argument.
/// </summary>
[CreateAssetMenu(menuName = "Events/NPC Movement Event Channel")]
public class NPCMovementEventChannelSO : DescriptionBaseSO
{

8
UOP1_Project/Assets/Scripts/Gameplay/GameStateSO.cs


public void ResetToPreviousGameState()
{
if (_previousGameState != CurrentGameState)
if (_previousGameState == _currentGameState)
return;
if (_previousGameState == GameState.Combat)

else if (CurrentGameState == GameState.Combat)
else if (_currentGameState == GameState.Combat)
_currentGameState = _previousGameState;
GameState stateToReturnTo = _previousGameState;
_previousGameState = _currentGameState;
_currentGameState = stateToReturnTo;
}
}

2
UOP1_Project/Assets/Scripts/SceneManagement/FallCatcher.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FallCatcher : MonoBehaviour

2
UOP1_Project/Assets/Scripts/SceneManagement/LocationEntrance.cs


using Cinemachine;
using System;
using System.Collections.Generic;
using UnityEngine;
public class LocationEntrance : MonoBehaviour

1
UOP1_Project/Assets/Scripts/SceneManagement/LocationExit.cs


/// <summary>
/// This class goes on a trigger which, when entered, sends the player to another Location
/// </summary>
public class LocationExit : MonoBehaviour
{
[SerializeField] private GameSceneSO _locationToLoad = default;

8
UOP1_Project/Assets/Scripts/SceneManagement/SceneLoader.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[SerializeField] private GameSceneSO _gameplayScene = default;
[SerializeField] private InputReader _inputReader = default;
[Header("Load Events")]
[Header("Listening to")]
[SerializeField] private LoadEventChannelSO _loadLocation = default;
[SerializeField] private LoadEventChannelSO _loadMenu = default;
[SerializeField] private LoadEventChannelSO _coldStartupLocation = default;

[SerializeField] private VoidEventChannelSO _onSceneReady = default;
[SerializeField] private VoidEventChannelSO _onSceneReady = default; //picked up by the SpawnSystem
[SerializeField] private FadeChannelSO _fadeRequestChannel = default;
private AsyncOperationHandle<SceneInstance> _loadingOperationHandle;

59
UOP1_Project/Assets/Scripts/SceneManagement/StartGame.cs


using System;
using System.Collections;
using System.Collections;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

/// </summary>
public class StartGame : MonoBehaviour
{
[SerializeField]
private GameSceneSO _locationsToLoad;
[SerializeField]
private bool _showLoadScreen = default;
[SerializeField]
private SaveSystem _saveSystem = default;
private bool _hasSaveData;
[Header("Broadcasting on ")]
[SerializeField]
private LoadEventChannelSO _startGameEvent = default;
[SerializeField] private GameSceneSO _locationsToLoad;
[SerializeField] private SaveSystem _saveSystem = default;
[SerializeField] private bool _showLoadScreen = default;
[Header("Broadcasting on")]
[SerializeField] private LoadEventChannelSO _loadLocation = default;
[SerializeField]
private VoidEventChannelSO _startNewGameEvent = default;
[SerializeField]
private VoidEventChannelSO _continueGameEvent = default;
[SerializeField] private VoidEventChannelSO _onNewGameButton = default;
[SerializeField] private VoidEventChannelSO _onContinueButton = default;
private bool _hasSaveData;
_startNewGameEvent.OnEventRaised += StartNewGame;
_continueGameEvent.OnEventRaised += ContinuePreviousGame;
_onNewGameButton.OnEventRaised += StartNewGame;
_onContinueButton.OnEventRaised += ContinuePreviousGame;
_startNewGameEvent.OnEventRaised -= StartNewGame;
_continueGameEvent.OnEventRaised -= ContinuePreviousGame;
_onNewGameButton.OnEventRaised -= StartNewGame;
_onContinueButton.OnEventRaised -= ContinuePreviousGame;
}
}
void StartNewGame()
private void StartNewGame()
//Start new game
_startGameEvent.RaiseEvent(_locationsToLoad, _showLoadScreen);
_loadLocation.RaiseEvent(_locationsToLoad, _showLoadScreen);
}
}
void ContinuePreviousGame()
private void ContinuePreviousGame()
void OnResetSaveDataPress()
private void OnResetSaveDataPress()
IEnumerator LoadSaveGame()
private IEnumerator LoadSaveGame()
_startGameEvent.RaiseEvent(locationSO, _showLoadScreen);
_loadLocation.RaiseEvent(locationSO, _showLoadScreen);
}
}
}

10
UOP1_Project/Assets/Scripts/UI/Inventory/UIInventory.cs


void OnActionButtonClicked()
{
//find the selected Item
if (_availableItemSlots.Count > selectedItemId && selectedItemId > -1)
if (_availableItemSlots.Count > selectedItemId
&& selectedItemId > -1)
//find the item
ItemSO itemToActOn = new ItemSO();
ItemSO itemToActOn = ScriptableObject.CreateInstance<ItemSO>();
itemToActOn = _availableItemSlots[selectedItemId].currentItem.Item;
//check the selected Item type

case ItemInventoryActionType.Cook:
CookRecipe(itemToActOn);
break;

default:
break;
}
void UseItem(ItemSO itemToUse)

_useItemEvent.RaiseEvent(itemToUse);
//update inventory
UpdateInventory();
}

30
UOP1_Project/Assets/Scripts/UI/UIHealthBarManager.cs


public class UIHealthBarManager : MonoBehaviour
{
[SerializeField] private HealthSO _currentHealth = default; //the HealthBar is watching this object, which is the health of the player
[SerializeField] private HealthSO _protagonistHealth = default; //the HealthBar is watching this object, which is the health of the player
[SerializeField] private TransformEventChannelSO _onPlayerInstantiated = default;
[SerializeField] private VoidEventChannelSO _updateHealthEvent = default;
[SerializeField] private VoidEventChannelSO _UIUpdateNeeded = default; //The player's Damageable issues this
_onPlayerInstantiated.OnEventRaised += ResetHealthOnSpawn;
_updateHealthEvent.OnEventRaised += UpdateHeartImages;
_UIUpdateNeeded.OnEventRaised += UpdateHeartImages;
InitializeHealthBar();
_onPlayerInstantiated.OnEventRaised -= ResetHealthOnSpawn;
_updateHealthEvent.OnEventRaised -= UpdateHeartImages;
}
private void ResetHealthOnSpawn(Transform t)
{
UpdateHeartImages();
_UIUpdateNeeded.OnEventRaised -= UpdateHeartImages;
private void SetHealthBar()
private void InitializeHealthBar()
_currentHealth.SetMaxHealth(_healthConfig.InitialHealth);
_currentHealth.SetCurrentHealth(_healthConfig.InitialHealth);
_protagonistHealth.SetMaxHealth(_healthConfig.InitialHealth);
_protagonistHealth.SetCurrentHealth(_healthConfig.InitialHealth);
UpdateHeartImages();
}

int heartValue = _currentHealth.MaxHealth / _heartImages.Length;
int filledHeartCount = Mathf.FloorToInt((float)_currentHealth.CurrentHealth / heartValue);
int heartValue = _protagonistHealth.MaxHealth / _heartImages.Length;
int filledHeartCount = Mathf.FloorToInt((float)_protagonistHealth.CurrentHealth / heartValue);
for (int i = 0; i < _heartImages.Length; i++)
{

}
else if (i == filledHeartCount)
{
heartPercent = ((float)_currentHealth.CurrentHealth - (float)filledHeartCount * (float)heartValue) / (float)heartValue;
heartPercent = ((float)_protagonistHealth.CurrentHealth - (float)filledHeartCount * (float)heartValue) / (float)heartValue;
}
else
{

9
UOP1_Project/Assets/Scripts/UI/UIManager.cs


_pauseScreen.gameObject.SetActive(false);
_gameStateManager.ResetToPreviousGameState();
if (_gameStateManager.CurrentGameState == GameState.Gameplay || _gameStateManager.CurrentGameState == GameState.Combat)
_inputReader.EnableGameplayInput();
if (_gameStateManager.CurrentGameState == GameState.Gameplay
|| _gameStateManager.CurrentGameState == GameState.Combat)
{
_inputReader.EnableGameplayInput();
}
_selectionHandler.Unselect();
}

2
UOP1_Project/Assets/Scripts/UI/UIPause.cs


private void OnEnable()
{
_onPauseOpened.RaiseEvent(true);
_resumeButton.SetButton(true);
_inputReader.MenuCloseEvent += Resume;
_resumeButton.Clicked += Resume;

private void OnDisable()
{
_onPauseOpened.RaiseEvent(false);
_inputReader.MenuCloseEvent -= Resume;
_resumeButton.Clicked -= Resume;
_settingsButton.Clicked -= OpenSettingsScreen;

17
UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/Cure.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 696142ab7e0adf0478f66a5c9e06a168, type: 3}
m_Name: Cure
m_EditorClassIdentifier:
_guid: de4a39f85969d44cba990125224ff7ef
description: Damageable listens to this to restore the health of the player when
eating food

16
UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/UpdateHealthUI.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7fafac715ff920c4383fed91a38a351e, type: 3}
m_Name: UpdateHealthUI
m_EditorClassIdentifier:
_guid: 2447a760b3f9f134f8730aa53c8d2ece
description: Invoked by the player's Damageable, listened to by the Health UI

15
UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/RestoreHealthEvent.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 696142ab7e0adf0478f66a5c9e06a168, type: 3}
m_Name: RestoreHealthEvent
m_EditorClassIdentifier:
description:

15
UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/UpdateHealthEvent.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7fafac715ff920c4383fed91a38a351e, type: 3}
m_Name: UpdateHealthEvent
m_EditorClassIdentifier:
description:

/UOP1_Project/Assets/ScriptableObjects/Configs/Health/PlayerHealth.asset.meta → /UOP1_Project/Assets/ScriptableObjects/Configs/Health/PigChef_Health.asset.meta

/UOP1_Project/Assets/ScriptableObjects/Configs/Health/PlayerHealth.asset → /UOP1_Project/Assets/ScriptableObjects/Configs/Health/PigChef_Health.asset

/UOP1_Project/Assets/ScriptableObjects/EventChannels/Healthbar.meta → /UOP1_Project/Assets/ScriptableObjects/EventChannels/Health.meta

/UOP1_Project/Assets/ScriptableObjects/EventChannels/Healthbar → /UOP1_Project/Assets/ScriptableObjects/EventChannels/Health

/UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/RestoreHealthEvent.asset.meta → /UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/Cure.asset.meta

/UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/UpdateHealthEvent.asset.meta → /UOP1_Project/Assets/ScriptableObjects/EventChannels/Health/UpdateHealthUI.asset.meta

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存