/// --------------------------------------------- /// Ultimate Character Controller /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.UltimateCharacterController.Character.Abilities.Items { using Opsive.Shared.Events; using UnityEngine; /// /// The EquipSwitcher is an abstract class implemented by the abilities which change the item set. /// public abstract class EquipSwitcher : ItemSetAbilityBase { /// /// Initialize the default values. /// public override void Awake() { base.Awake(); // The EquipUnequip must exist in order for the itemset to be able to be changed. if (m_EquipUnequipItemAbility == null) { Debug.LogError($"Error: The EquipUnequip ItemAbility with the category ID {m_ItemSetCategoryID} must be added to the character."); Enabled = false; return; } EventHandler.RegisterEvent(m_EquipUnequipItemAbility, "OnEquipUnequipItemSetIndexChange", OnItemSetIndexChange); EventHandler.RegisterEvent(m_GameObject, "OnItemSetIndexChange", OnItemSetIndexChange); EventHandler.RegisterEvent(m_GameObject, "OnDeath", OnDeath); } /// /// The ItemSetManager has changed the active ItemSet. /// /// The index of the category that changed. /// The updated active ItemSet index value. protected void OnItemSetIndexChange(int categoryIndex, int itemSetIndex) { if (m_ItemSetCategoryIndex != categoryIndex) { return; } OnItemSetIndexChange(itemSetIndex); } /// /// The EquipUnequip ability has changed the active ItemSet. /// /// The updated active ItemSet index value. protected virtual void OnItemSetIndexChange(int itemSetIndex) { } /// /// The character has died. /// /// The position of the force. /// The amount of force which killed the character. /// The GameObject that killed the character. protected virtual void OnDeath(Vector3 position, Vector3 force, GameObject attacker) { } /// /// Called when the character is destroyed. /// public override void OnDestroy() { base.OnDestroy(); if (m_EquipUnequipItemAbility != null) { EventHandler.UnregisterEvent(m_EquipUnequipItemAbility, "OnEquipUnequipItemSetIndexChange", OnItemSetIndexChange); EventHandler.UnregisterEvent(m_GameObject, "OnItemSetIndexChange", OnItemSetIndexChange); EventHandler.UnregisterEvent(m_GameObject, "OnDeath", OnDeath); } } } }