/// ---------------------------------------------
/// 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.UltimateCharacterController.Character;
using UnityEngine;
///
/// The FullScreenItemUIMonitor will show the full screen item UI when the OnItemShowFullScreenUI event is triggered.
///
public class FullScreenItemUIMonitor : CharacterMonitor
{
[Tooltip("Should the crosshairs be shown?")]
[SerializeField] protected int m_ID;
public int ID { get { return m_ID; } set { m_ID = value; } }
private UltimateCharacterLocomotion m_CharacterController;
private GameObject m_GameObject;
private bool m_FullScreenUIShown;
///
/// Initialize the default values.
///
protected override void Awake()
{
base.Awake();
m_GameObject = gameObject;
m_GameObject.SetActive(false);
}
///
/// 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, "OnItemShowFullScreenUI", OnShowItemUI);
}
base.OnAttachCharacter(character);
if (m_Character == null) {
return;
}
EventHandler.RegisterEvent(m_Character, "OnItemShowFullScreenUI", OnShowItemUI);
m_CharacterController = m_Character.GetCachedComponent();
}
///
/// Shows or hides the full screen item UI.
///
/// The ID of the UI that should be shown or hidden.
/// Should the UI be shown?
private void OnShowItemUI(int id, bool show)
{
if (id == -1 || id != m_ID) {
return;
}
m_FullScreenUIShown = show;
// Independent look movement types don't look in the direction of the camera so they shouldn't show the full screen UI.
if (m_CharacterController.ActiveMovementType.UseIndependentLook(false)) {
show = false;
}
m_GameObject.SetActive(m_ShowUI && show);
}
///
/// Can the UI be shown?
///
/// True if the UI can be shown.
protected override bool CanShowUI()
{
return base.CanShowUI() && m_FullScreenUIShown;
}
}
}