/// --------------------------------------------- /// Ultimate Character Controller /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.UltimateCharacterController.UI { using Opsive.Shared.Events; using Opsive.Shared.Game; using Opsive.Shared.Inventory; using Opsive.UltimateCharacterController.Items; using Opsive.UltimateCharacterController.Inventory; using UnityEngine; using UnityEngine.UI; /// /// The ItemMonitor will update the UI for the character's items. /// public abstract class ItemMonitor : CharacterMonitor { [Tooltip("A reference to the text used for primary ItemType count.")] [SerializeField] protected Text m_PrimaryCount; protected InventoryBase m_CharacterInventory; /// /// Attaches the monitor to the specified character. /// /// The character to attach the monitor to. protected override void OnAttachCharacter(GameObject character) { if (m_Character != null) { EventHandler.UnregisterEvent(m_Character, "OnInventoryPickupItemIdentifier", OnPickupItemIdentifier); EventHandler.UnregisterEvent(m_Character, "OnItemUpdateDominantItem", OnUpdateDominantItem); EventHandler.UnregisterEvent(m_Character, "OnItemUseConsumableItemIdentifier", OnUseConsumableItemIdentifier); EventHandler.UnregisterEvent(m_Character, "OnInventoryAdjustItemIdentifierAmount", OnAdjustItemIdentifierAmount); } base.OnAttachCharacter(character); if (m_Character == null) { return; } // The character must have an inventory. m_CharacterInventory = m_Character.GetCachedComponent(); if (m_CharacterInventory == null) { return; } EventHandler.RegisterEvent(m_Character, "OnInventoryPickupItemIdentifier", OnPickupItemIdentifier); EventHandler.RegisterEvent(m_Character, "OnItemUpdateDominantItem", OnUpdateDominantItem); EventHandler.RegisterEvent(m_Character, "OnItemUseConsumableItemIdentifier", OnUseConsumableItemIdentifier); EventHandler.RegisterEvent(m_Character, "OnInventoryAdjustItemIdentifierAmount", OnAdjustItemIdentifierAmount); } /// /// An ItemIdentifier has been picked up within the inventory. /// /// The ItemIdentifier that has been picked up. /// The amount of item picked up. /// Was the item be picked up immediately? /// Should the item be force equipped? protected virtual void OnPickupItemIdentifier(IItemIdentifier itemIdentifier, int amount, bool immediatePickup, bool forceEquip) { } /// /// The DominantItem field has been updated for the specified item. /// /// The Item whose DominantItem field was updated. /// True if the item is now a dominant item. protected virtual void OnUpdateDominantItem(Item item, bool dominantItem) { } /// /// The specified consumable ItemIdentifier has been used. /// /// The Item that has been used. /// The ItemIdentifier that has been used. /// The remaining amount of the specified IItemIdentifier. protected virtual void OnUseConsumableItemIdentifier(Item item, IItemIdentifier itemIdentifier, int amount) { } /// /// The specified ItemIdentifier amount has been adjusted. /// /// The ItemIdentifier to adjust. /// The amount of ItemIdentifier to adjust. protected virtual void OnAdjustItemIdentifierAmount(IItemIdentifier itemIdentifier, int amount) { } } }