/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.Demo.UI
{
using Opsive.Shared.Inventory;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities.Items;
using Opsive.UltimateCharacterController.Inventory;
using UnityEngine;
///
/// Manages the magic zone. Allows switching between magic items.
///
public class MagicZone : UIZone
{
[Tooltip("A mapping of the ItemDefinitions to the button.")]
[SerializeField] protected ItemDefinitionBase[] m_ItemDefinitions;
[Tooltip("The parent GameObject that should be enabled when the corresponding ItemDefinition is enabled.")]
[SerializeField] protected GameObject[] m_Objects;
[Tooltip("The Particle Stream Item Definition.")]
[SerializeField] protected ItemDefinitionBase m_ParticleStreamItemDefinition;
[Tooltip("A reference to the Attribute Monitor for the Particle Stream.")]
[SerializeField] protected GameObject m_ParticleStreamAttributeMonitor;
private UltimateCharacterLocomotion m_CharacterLocomotion;
private InventoryBase m_Inventory;
private EquipUnequip[] m_EquipUnequipAbilities;
private int[] m_ActiveItemSets;
private int m_Index;
///
/// Initializes the default values.
///
private void Start()
{
var character = GameObject.FindObjectOfType().Character;
m_CharacterLocomotion = character.GetComponent();
m_Inventory = character.GetComponent();
m_EquipUnequipAbilities = m_CharacterLocomotion.GetAbilities();
m_ActiveItemSets = new int[m_EquipUnequipAbilities.Length];
m_Index = -1;
for (int i = 0; i < m_Objects.Length; ++i) {
m_Objects[i].SetActive(false);
}
m_ParticleStreamAttributeMonitor.SetActive(false);
}
///
/// The character has entered from the zone.
///
/// The character that entered the zone.
protected override void CharacterEnter(UltimateCharacterLocomotion characterLocomotion)
{
for (int i = 0; i < m_ActiveItemSets.Length; ++i) {
m_ActiveItemSets[i] = m_EquipUnequipAbilities[i].ActiveItemSetIndex;
}
ChangeMagicItem(0); // Start with the first item.
}
///
/// Change the magic item to the specified item.
///
/// The item index to change the value to.
public void ChangeMagicItem(int itemIndex)
{
if (itemIndex < 0 || itemIndex >= m_ItemDefinitions.Length || itemIndex == m_Index) {
return;
}
if (m_CharacterLocomotion.IsAbilityTypeActive