浏览代码

Restore health and Apply changes to MainMenuCanvas prefab

/main
uChema 3 年前
当前提交
94daf002
共有 11 个文件被更改,包括 387 次插入323 次删除
  1. 2
      UOP1_Project/Assets/Prefabs/Characters/PigChef.prefab
  2. 3
      UOP1_Project/Assets/Prefabs/UI/GameplayScene/Health System/UIHealthDisplay.prefab
  3. 1
      UOP1_Project/Assets/Prefabs/UI/GameplayScene/Inventory/InventoryScreen.prefab
  4. 1
      UOP1_Project/Assets/Prefabs/UI/MainMenu/Canvas-MainMenu.prefab
  5. 26
      UOP1_Project/Assets/Scripts/Characters/Config/HealthSO.cs
  6. 57
      UOP1_Project/Assets/Scripts/Characters/Damageable.cs
  7. 582
      UOP1_Project/Assets/Scripts/UI/Inventory/UIInventory.cs
  8. 15
      UOP1_Project/Assets/Scripts/UI/UIHealthBarManager.cs
  9. 15
      UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/UpdateHealthEvent.asset
  10. 8
      UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/UpdateHealthEvent.asset.meta

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


_mainMeshRenderer: {fileID: 2643181883930254223}
_droppableRewardSO: {fileID: 11400000, guid: f155590e3f62ce94ea050caa8fd5403e, type: 2}
_setHealthBar: {fileID: 11400000, guid: 22e3f27f002de44b4948988138dd9377, type: 2}
_inflictDamage: {fileID: 11400000, guid: be921b398c68d450e9e3c55dde697149, type: 2}
_updateHealthEvent: {fileID: 11400000, guid: 2447a760b3f9f134f8730aa53c8d2ece, type: 2}
_restoreHealth: {fileID: 11400000, guid: de4a39f85969d44cba990125224ff7ef, type: 2}
_deathEvent: {fileID: 11400000, guid: 0a29544909be226418bc1677ec369790, type: 2}
--- !u!114 &3326384532942868502

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


- {fileID: 8327551769276309930}
- {fileID: 8717325367621303831}
healthText: {fileID: 0}
_inflictDamage: {fileID: 11400000, guid: be921b398c68d450e9e3c55dde697149, type: 2}
_restoreHealth: {fileID: 11400000, guid: de4a39f85969d44cba990125224ff7ef, type: 2}
_updateHealthEvent: {fileID: 11400000, guid: 2447a760b3f9f134f8730aa53c8d2ece, type: 2}
--- !u!114 &5382124729891650614
MonoBehaviour:
m_ObjectHideFlags: 0

1
UOP1_Project/Assets/Prefabs/UI/GameplayScene/Inventory/InventoryScreen.prefab


_onInteractionEndedEvent: {fileID: 11400000, guid: c499d87f35465124f8fb2751b150430d,
type: 2}
_useItemEvent: {fileID: 11400000, guid: cbe9057614db5422a97c4c250c742f06, type: 2}
_restoreHealth: {fileID: 11400000, guid: de4a39f85969d44cba990125224ff7ef, type: 2}
_equipItemEvent: {fileID: 11400000, guid: 0cef922101fd44b25a2d96f2972d5f50, type: 2}
_cookRecipeEvent: {fileID: 11400000, guid: 1a56201d2b4714889a387c20fbd8f3e8, type: 2}
_inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}

1
UOP1_Project/Assets/Prefabs/UI/MainMenu/Canvas-MainMenu.prefab


_inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
_startNewGameEvent: {fileID: 11400000, guid: 2d8265bc91f6244e49560195fe2ca5e9, type: 2}
_continueGameEvent: {fileID: 11400000, guid: c6438460769bc46b7a96bd3c7233a68a, type: 2}
_onGameExitEvent: {fileID: 11400000, guid: d570e16f713770a4a94310999866e0e0, type: 2}
--- !u!114 &8312508109763636281
MonoBehaviour:
m_ObjectHideFlags: 0

26
UOP1_Project/Assets/Scripts/Characters/Config/HealthSO.cs


public class HealthSO : ScriptableObject
{
[Tooltip("Initial health")]
[SerializeField] private int _maxHealth;
[SerializeField] private int _maxHealth = default;
[SerializeField] private int _currentHealth;
[SerializeField] private int _currentHealth = default;
public int MaxHealth { get; set; }
public int CurrentHealth { get; set; }
public int MaxHealth => _maxHealth;
public int CurrentHealth => _currentHealth;
public void SetMaxHealth(int newValue)
{
_maxHealth = newValue;
Debug.Log("Max Health " + _maxHealth);
}
public void SetCurrentHealth(int newValue)
{
_currentHealth = newValue;
}
public void InflictDamage(int DamageValue)
{
_currentHealth -= DamageValue;
}
public void RestoreHealth(int HealthValue)
{
_currentHealth += HealthValue;
}
}

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


[Header("Broadcasting On")]
[SerializeField] private IntEventChannelSO _setHealthBar = default;
[SerializeField] private IntEventChannelSO _inflictDamage = default;
[SerializeField] private VoidEventChannelSO _updateHealthEvent = default;
[SerializeField] private VoidEventChannelSO _deathEvent = default;
[Header("Listening To")]
[SerializeField] private VoidEventChannelSO _deathEvent = default;
public DroppableRewardConfigSO DroppableRewardConfig => _droppableRewardSO;

if (_currentHealthSO == null)
{
_currentHealthSO = new HealthSO();
_currentHealthSO.MaxHealth = _healthConfigSO.MaxHealth;
_currentHealthSO.CurrentHealth = _healthConfigSO.MaxHealth;
_currentHealthSO.SetMaxHealth(_healthConfigSO.MaxHealth);
_currentHealthSO.SetCurrentHealth(_healthConfigSO.MaxHealth);
if (_updateHealthEvent != null)
{
_updateHealthEvent.RaiseEvent();
if (_setHealthBar != null)
_setHealthBar.RaiseEvent(_currentHealthSO.CurrentHealth);
}
}
private void OnEnable()
{
if (_restoreHealth != null)
{
_restoreHealth.OnEventRaised += restoreHealth;
}
private void OnDisable()
{
if (_restoreHealth != null)
{
_restoreHealth.OnEventRaised -= restoreHealth;
}
}
public void Kill()
{
ReceiveAnAttack(_currentHealthSO.CurrentHealth);

{
if (IsDead)
return;
if (_inflictDamage != null)
_inflictDamage.RaiseEvent(damage);
_currentHealthSO.CurrentHealth -= damage;
_currentHealthSO.InflictDamage(damage);
if (_updateHealthEvent != null)
{
_updateHealthEvent.RaiseEvent();
}
GetHit = true;
if (_currentHealthSO.CurrentHealth <= 0)
{

public void ResetHealth()
{
_currentHealthSO.CurrentHealth = _healthConfigSO.MaxHealth;
if (_setHealthBar != null)
_setHealthBar.RaiseEvent(_currentHealthSO.CurrentHealth);
_currentHealthSO.SetCurrentHealth(_healthConfigSO.MaxHealth);
if (_updateHealthEvent != null)
{
_updateHealthEvent.RaiseEvent();
}
IsDead = false;
}
public void restoreHealth(int healthToAdd)

_currentHealthSO.CurrentHealth += healthToAdd;
if (_restoreHealth != null)
_restoreHealth.RaiseEvent(healthToAdd);
_currentHealthSO.RestoreHealth(healthToAdd);
if (_updateHealthEvent != null)
{
_updateHealthEvent.RaiseEvent();
}
}
}

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


public class UIInventory : MonoBehaviour
{
[SerializeField]
private InventorySO _currentInventory = default;
[SerializeField]
private InventorySO _currentInventory = default;
[SerializeField]
private UIInventoryItem _itemPrefab = default;
[SerializeField]
private UIInventoryItem _itemPrefab = default;
[SerializeField]
private GameObject _contentParent = default;
[SerializeField]
private GameObject _contentParent = default;
[FormerlySerializedAs("_inspectorFiller")]
[SerializeField]
private UIInventoryInspector _inspectorPanel = default;
[FormerlySerializedAs("_inspectorFiller")]
[SerializeField]
private UIInventoryInspector _inspectorPanel = default;
[FormerlySerializedAs("_tabFiller")]
[SerializeField]
private UIInventoryTabs _tabsPanel = default;
[FormerlySerializedAs("_tabFiller")]
[SerializeField]
private UIInventoryTabs _tabsPanel = default;
[FormerlySerializedAs("_buttonFiller")]
[SerializeField]
private UIActionButton _actionButton = default;
[FormerlySerializedAs("_buttonFiller")]
[SerializeField]
private UIActionButton _actionButton = default;
InventoryTabSO _selectedTab = default;
InventoryTabSO _selectedTab = default;
[SerializeField]
List<InventoryTabSO> _tabTypesList = new List<InventoryTabSO>();
[SerializeField]
List<InventoryTabSO> _tabTypesList = new List<InventoryTabSO>();
private int selectedItemId = -1;
private int selectedItemId = -1;
[FormerlySerializedAs("_instanciatedItems")]
[SerializeField]
private List<UIInventoryItem> _availableItemSlots = default;
[FormerlySerializedAs("_instanciatedItems")]
[SerializeField]
private List<UIInventoryItem> _availableItemSlots = default;
[SerializeField]
private VoidEventChannelSO _onInteractionEndedEvent = default;
[SerializeField]
private VoidEventChannelSO _onInteractionEndedEvent = default;
[SerializeField]
private ItemEventChannelSO _useItemEvent = default;
[SerializeField]
private ItemEventChannelSO _equipItemEvent = default;
[SerializeField]
private ItemEventChannelSO _cookRecipeEvent = default;
[SerializeField]
private ItemEventChannelSO _useItemEvent = default;
[SerializeField]
private IntEventChannelSO _restoreHealth = default;
[SerializeField]
private ItemEventChannelSO _equipItemEvent = default;
[SerializeField]
private ItemEventChannelSO _cookRecipeEvent = default;
[SerializeField]
private InputReader _inputReader = default;
[SerializeField]
private InputReader _inputReader = default;
public UnityAction Closed;
bool _isNearPot = false;
public UnityAction Closed;
bool _isNearPot = false;
private void OnEnable()
{
//Check if the event exists to avoid errors
private void OnEnable()
{
//Check if the event exists to avoid errors
_actionButton.Clicked += OnActionButtonClicked;
_actionButton.Clicked += OnActionButtonClicked;
_tabsPanel.TabChanged += OnChangeTab;
_tabsPanel.TabChanged += OnChangeTab;
_onInteractionEndedEvent.OnEventRaised += InteractionEnded;
_onInteractionEndedEvent.OnEventRaised += InteractionEnded;
for (int i = 0; i < _availableItemSlots.Count; i++)
{
_availableItemSlots[i].ItemSelected += InspectItem;
}
for (int i = 0; i < _availableItemSlots.Count; i++)
{
_availableItemSlots[i].ItemSelected += InspectItem;
}
_inputReader.TabSwitched += OnSwitchTab;
}
_inputReader.TabSwitched += OnSwitchTab;
}
private void OnDisable()
{
_actionButton.Clicked -= OnActionButtonClicked;
private void OnDisable()
{
_actionButton.Clicked -= OnActionButtonClicked;
_tabsPanel.TabChanged -= OnChangeTab;
_tabsPanel.TabChanged -= OnChangeTab;
for (int i = 0; i < _availableItemSlots.Count; i++)
{
_availableItemSlots[i].ItemSelected -= InspectItem;
}
for (int i = 0; i < _availableItemSlots.Count; i++)
{
_availableItemSlots[i].ItemSelected -= InspectItem;
}
_inputReader.TabSwitched -= OnSwitchTab;
}
_inputReader.TabSwitched -= OnSwitchTab;
}
void OnSwitchTab(float orientation)
{
void OnSwitchTab(float orientation)
{
if (orientation != 0)
{
bool isLeft = orientation < 0;
int initialIndex = _tabTypesList.FindIndex(o => o == _selectedTab);
if (initialIndex != -1)
{
if (isLeft)
{
initialIndex--;
}
else
{
initialIndex++;
}
if (orientation != 0)
{
bool isLeft = orientation < 0;
int initialIndex = _tabTypesList.FindIndex(o => o == _selectedTab);
if (initialIndex != -1)
{
if (isLeft)
{
initialIndex--;
}
else
{
initialIndex++;
}
initialIndex = Mathf.Clamp(initialIndex, 0, _tabTypesList.Count - 1);
}
initialIndex = Mathf.Clamp(initialIndex, 0, _tabTypesList.Count - 1);
}
OnChangeTab(_tabTypesList[initialIndex]);
}
OnChangeTab(_tabTypesList[initialIndex]);
}
}
}
public void FillInventory(InventoryTabType _selectedTabType = InventoryTabType.CookingItem, bool isNearPot = false)
{
_isNearPot = isNearPot;
public void FillInventory(InventoryTabType _selectedTabType = InventoryTabType.CookingItem, bool isNearPot = false)
{
_isNearPot = isNearPot;
if ((_tabTypesList.Exists(o => o.TabType == _selectedTabType)))
{
_selectedTab = _tabTypesList.Find(o => o.TabType == _selectedTabType);
}
else
{
if (_tabTypesList != null)
{
if (_tabTypesList.Count > 0)
{
_selectedTab = _tabTypesList[0];
}
}
if ((_tabTypesList.Exists(o => o.TabType == _selectedTabType)))
{
_selectedTab = _tabTypesList.Find(o => o.TabType == _selectedTabType);
}
else
{
if (_tabTypesList != null)
{
if (_tabTypesList.Count > 0)
{
_selectedTab = _tabTypesList[0];
}
}
}
}
if (_selectedTab != null)
{
SetTabs(_tabTypesList, _selectedTab);
List<ItemStack> listItemsToShow = new List<ItemStack>();
listItemsToShow = _currentInventory.Items.FindAll(o => o.Item.ItemType.TabType == _selectedTab);
if (_selectedTab != null)
{
SetTabs(_tabTypesList, _selectedTab);
List<ItemStack> listItemsToShow = new List<ItemStack>();
listItemsToShow = _currentInventory.Items.FindAll(o => o.Item.ItemType.TabType == _selectedTab);
FillInvetoryItems(listItemsToShow);
}
else
{
FillInvetoryItems(listItemsToShow);
}
else
{
Debug.LogError("There's no selected tab ");
Debug.LogError("There's no selected tab ");
}
}
}
}
void InteractionEnded()
{
_isNearPot = false;
}
void InteractionEnded()
{
_isNearPot = false;
}
void SetTabs(List<InventoryTabSO> typesList, InventoryTabSO selectedType)
{
_tabsPanel.SetTabs(typesList, selectedType);
void SetTabs(List<InventoryTabSO> typesList, InventoryTabSO selectedType)
{
_tabsPanel.SetTabs(typesList, selectedType);
}
void FillInvetoryItems(List<ItemStack> listItemsToShow)
{
if (_availableItemSlots == null)
_availableItemSlots = new List<UIInventoryItem>();
}
void FillInvetoryItems(List<ItemStack> listItemsToShow)
{
int maxCount = Mathf.Max(listItemsToShow.Count, _availableItemSlots.Count);
if (_availableItemSlots == null)
_availableItemSlots = new List<UIInventoryItem>();
for (int i = 0; i < maxCount; i++)
{
if (i < listItemsToShow.Count)
{
int maxCount = Mathf.Max(listItemsToShow.Count, _availableItemSlots.Count);
//fill
bool isSelected = selectedItemId == i;
_availableItemSlots[i].SetItem(listItemsToShow[i], isSelected);
for (int i = 0; i < maxCount; i++)
{
if (i < listItemsToShow.Count)
{
}
else if (i < _availableItemSlots.Count)
{
//Desactive
_availableItemSlots[i].SetInactiveItem();
}
//fill
bool isSelected = selectedItemId == i;
_availableItemSlots[i].SetItem(listItemsToShow[i], isSelected);
}
HideItemInformation();
//unselect selected Item
if (selectedItemId >= 0)
{
UnselectItem(selectedItemId);
selectedItemId = -1;
}
//hover First Element
if (_availableItemSlots.Count > 0)
{
_availableItemSlots[0].SelectFirstElement();
}
}
else if (i < _availableItemSlots.Count)
{
//Desactive
_availableItemSlots[i].SetInactiveItem();
}
}
}
HideItemInformation();
//unselect selected Item
if (selectedItemId >= 0)
{
UnselectItem(selectedItemId);
selectedItemId = -1;
}
//hover First Element
if (_availableItemSlots.Count > 0)
{
_availableItemSlots[0].SelectFirstElement();
}
void UpdateItemInInventory(ItemStack itemToUpdate, bool removeItem)
{
if (_availableItemSlots == null)
_availableItemSlots = new List<UIInventoryItem>();
}
if (removeItem)
{
if (_availableItemSlots.Exists(o => o._currentItem == itemToUpdate))
{
void UpdateItemInInventory(ItemStack itemToUpdate, bool removeItem)
{
if (_availableItemSlots == null)
_availableItemSlots = new List<UIInventoryItem>();
int index = _availableItemSlots.FindIndex(o => o._currentItem == itemToUpdate);
_availableItemSlots[index].SetInactiveItem();
if (removeItem)
{
if (_availableItemSlots.Exists(o => o._currentItem == itemToUpdate))
{
}
int index = _availableItemSlots.FindIndex(o => o._currentItem == itemToUpdate);
_availableItemSlots[index].SetInactiveItem();
}
else
{
int index = 0;
//if the item has already been created
if (_availableItemSlots.Exists(o => o._currentItem == itemToUpdate))
{
}
index = _availableItemSlots.FindIndex(o => o._currentItem == itemToUpdate);
}
else
{
int index = 0;
//if the item has already been created
if (_availableItemSlots.Exists(o => o._currentItem == itemToUpdate))
{
index = _availableItemSlots.FindIndex(o => o._currentItem == itemToUpdate);
}
//if the item needs to be created
else
{
//if the new item needs to be instantiated
if (_currentInventory.Items.Count > _availableItemSlots.Count)
{
//instantiate
UIInventoryItem instantiatedPrefab = Instantiate(_itemPrefab, _contentParent.transform) as UIInventoryItem;
_availableItemSlots.Add(instantiatedPrefab);
}
//if the item needs to be created
else
{
//if the new item needs to be instantiated
if (_currentInventory.Items.Count > _availableItemSlots.Count)
{
//instantiate
UIInventoryItem instantiatedPrefab = Instantiate(_itemPrefab, _contentParent.transform) as UIInventoryItem;
_availableItemSlots.Add(instantiatedPrefab);
}
//find the last instantiated game object not used
index = _currentInventory.Items.Count;
}
//find the last instantiated game object not used
index = _currentInventory.Items.Count;
}
//set item
bool isSelected = selectedItemId == index;
_availableItemSlots[index].SetItem(itemToUpdate, isSelected);
}
//set item
bool isSelected = selectedItemId == index;
_availableItemSlots[index].SetItem(itemToUpdate, isSelected);
}
}
}
}
public void InspectItem(ItemSO itemToInspect)
{
if (_availableItemSlots.Exists(o => o._currentItem.Item == itemToInspect))
{
int itemIndex = _availableItemSlots.FindIndex(o => o._currentItem.Item == itemToInspect);
public void InspectItem(ItemSO itemToInspect)
{
if (_availableItemSlots.Exists(o => o._currentItem.Item == itemToInspect))
{
int itemIndex = _availableItemSlots.FindIndex(o => o._currentItem.Item == itemToInspect);
//unselect selected Item
if (selectedItemId >= 0 && selectedItemId != itemIndex)
UnselectItem(selectedItemId);
//change Selected ID
selectedItemId = itemIndex;
//unselect selected Item
if (selectedItemId >= 0 && selectedItemId != itemIndex)
UnselectItem(selectedItemId);
//show Information
ShowItemInformation(itemToInspect);
//change Selected ID
selectedItemId = itemIndex;
//check if interactable
bool isInteractable = true;
_actionButton.gameObject.SetActive(true);
if (itemToInspect.ItemType.ActionType == ItemInventoryActionType.Cook)
{
isInteractable = _currentInventory.hasIngredients(itemToInspect.IngredientsList) && _isNearPot;
//show Information
ShowItemInformation(itemToInspect);
}
else if (itemToInspect.ItemType.ActionType == ItemInventoryActionType.DoNothing)
{
isInteractable = false;
_actionButton.gameObject.SetActive(false);
}
//check if interactable
bool isInteractable = true;
_actionButton.gameObject.SetActive(true);
if (itemToInspect.ItemType.ActionType == ItemInventoryActionType.Cook)
{
isInteractable = _currentInventory.hasIngredients(itemToInspect.IngredientsList) && _isNearPot;
//set button
_actionButton.FillInventoryButton(itemToInspect.ItemType, isInteractable);
}
else if (itemToInspect.ItemType.ActionType == ItemInventoryActionType.DoNothing)
{
isInteractable = false;
_actionButton.gameObject.SetActive(false);
}
//set button
_actionButton.FillInventoryButton(itemToInspect.ItemType, isInteractable);
}
}
}
void ShowItemInformation(ItemSO item)
{
}
bool[] availabilityArray = _currentInventory.IngredientsAvailability(item.IngredientsList);
void ShowItemInformation(ItemSO item)
{
_inspectorPanel.FillInspector(item, availabilityArray);
_inspectorPanel.gameObject.SetActive(true);
bool[] availabilityArray = _currentInventory.IngredientsAvailability(item.IngredientsList);
}
void HideItemInformation()
{
_actionButton.gameObject.SetActive(false);
_inspectorPanel.gameObject.SetActive(false);
_inspectorPanel.FillInspector(item, availabilityArray);
_inspectorPanel.gameObject.SetActive(true);
}
}
void HideItemInformation()
{
_actionButton.gameObject.SetActive(false);
_inspectorPanel.gameObject.SetActive(false);
}
void UnselectItem(int itemIndex)
{
if (_availableItemSlots.Count > itemIndex)
{
_availableItemSlots[itemIndex].UnselectItem();
void UnselectItem(int itemIndex)
{
}
}
void UpdateInventory()
{
FillInventory(_selectedTab.TabType, _isNearPot);
}
if (_availableItemSlots.Count > itemIndex)
{
_availableItemSlots[itemIndex].UnselectItem();
void OnActionButtonClicked()
{
}
}
void UpdateInventory()
{
FillInventory(_selectedTab.TabType, _isNearPot);
}
//find the selected Item
if (_availableItemSlots.Count > selectedItemId && selectedItemId > -1)
{
//find the item
ItemSO itemToActOn = new ItemSO();
itemToActOn = _availableItemSlots[selectedItemId]._currentItem.Item;
void OnActionButtonClicked()
{
//check the selected Item type
//call action function depending on the itemType
switch (itemToActOn.ItemType.ActionType)
{
//find the selected Item
if (_availableItemSlots.Count > selectedItemId && selectedItemId > -1)
{
//find the item
ItemSO itemToActOn = new ItemSO();
itemToActOn = _availableItemSlots[selectedItemId]._currentItem.Item;
case ItemInventoryActionType.Cook:
CookRecipe(itemToActOn);
break;
case ItemInventoryActionType.Use:
UseItem(itemToActOn);
break;
case ItemInventoryActionType.Equip:
EquipItem(itemToActOn);
break;
default:
//check the selected Item type
//call action function depending on the itemType
switch (itemToActOn.ItemType.ActionType)
{
break;
case ItemInventoryActionType.Cook:
CookRecipe(itemToActOn);
break;
case ItemInventoryActionType.Use:
UseItem(itemToActOn);
break;
case ItemInventoryActionType.Equip:
EquipItem(itemToActOn);
break;
default:
}
}
break;
}
void UseItem(ItemSO itemToUse)
{
Debug.Log("USE ITEM " + itemToUse.name);
}
}
_useItemEvent.OnEventRaised(itemToUse);
//update inventory
UpdateInventory();
}
}
void UseItem(ItemSO itemToUse)
{
if (itemToUse.HealthResorationValue > 0)
{ _restoreHealth.RaiseEvent(itemToUse.HealthResorationValue); }
_useItemEvent.RaiseEvent(itemToUse);
//update inventory
UpdateInventory();
}
void EquipItem(ItemSO itemToUse)
{
Debug.Log("Equip ITEM " + itemToUse.name);
_equipItemEvent.OnEventRaised(itemToUse);
}
void EquipItem(ItemSO itemToUse)
{
Debug.Log("Equip ITEM " + itemToUse.name);
_equipItemEvent.RaiseEvent(itemToUse);
}
void CookRecipe(ItemSO recipeToCook)
{
void CookRecipe(ItemSO recipeToCook)
{
//get item
_cookRecipeEvent.OnEventRaised(recipeToCook);
//get item
_cookRecipeEvent.RaiseEvent(recipeToCook);
//update inspector
InspectItem(recipeToCook);
//update inspector
InspectItem(recipeToCook);
//update inventory
UpdateInventory();
//update inventory
UpdateInventory();
}
}
void OnChangeTab(InventoryTabSO tabType)
{
void OnChangeTab(InventoryTabSO tabType)
{
FillInventory(tabType.TabType, _isNearPot);
FillInventory(tabType.TabType, _isNearPot);
}
public void CloseInventory()
{
Closed.Invoke();
}
}
public void CloseInventory()
{
Closed.Invoke();
}
}

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


[SerializeField] private TextMeshProUGUI healthText = default;
[Header("Listening to")]
[SerializeField] private IntEventChannelSO _inflictDamage = default;
[SerializeField] private IntEventChannelSO _restoreHealth = default;
[SerializeField] private VoidEventChannelSO _updateHealthEvent = default;
_inflictDamage.OnEventRaised += InflictDamage;
_updateHealthEvent.OnEventRaised += SetHeartImages;
_restoreHealth.OnEventRaised += RestoreHealth;
_inflictDamage.OnEventRaised -= InflictDamage;
_updateHealthEvent.OnEventRaised -= SetHeartImages;
_restoreHealth.OnEventRaised -= RestoreHealth;
_deathEvent.OnEventRaised -= RegisterDeath;
}

private void OnLevelWasLoaded(int level)
{
_currentHealth.MaxHealth = _healthConfig.MaxHealth;
_currentHealth.CurrentHealth = _healthConfig.MaxHealth;
_currentHealth.SetMaxHealth(_healthConfig.MaxHealth);
_currentHealth.SetCurrentHealth(_healthConfig.MaxHealth);
SetHeartImages();

15
UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/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:

8
UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/UpdateHealthEvent.asset.meta


fileFormatVersion: 2
guid: 2447a760b3f9f134f8730aa53c8d2ece
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

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

正在加载...
取消
保存