// Copyright (c) Pixel Crushers. All rights reserved.
using UnityEngine;
namespace PixelCrushers.DialogueSystem
{
///
/// Unity UI Quick Time Event (QTE) indicator controls.
///
[System.Serializable]
public class UnityUIQTEControls : AbstractUIQTEControls
{
///
/// QTE (Quick Time Event) indicators.
///
public UnityEngine.UI.Graphic[] qteIndicators;
private int numVisibleQTEIndicators = 0;
public UnityUIQTEControls(UnityEngine.UI.Graphic[] qteIndicators)
{
this.qteIndicators = qteIndicators;
}
///
/// Gets a value indicating whether any QTE indicators are visible.
///
///
/// true if visible; otherwise, false.
///
public override bool areVisible
{
get { return (numVisibleQTEIndicators > 0); }
}
///
/// Sets the QTE controls active/inactive.
///
///
/// true for active; false for inactive.
///
public override void SetActive(bool value)
{
if (value == false)
{
numVisibleQTEIndicators = 0;
foreach (var qteIndicator in qteIndicators)
{
Tools.SetGameObjectActive(qteIndicator, false);
}
}
}
///
/// Shows the QTE indicator specified by the index.
///
///
/// Zero-based index of the indicator.
///
public override void ShowIndicator(int index)
{
if (IsValidQTEIndex(index) && !IsQTEIndicatorVisible(index))
{
Tools.SetGameObjectActive(qteIndicators[index], true);
numVisibleQTEIndicators++;
}
}
///
/// Hides the QTE indicator specified by the index.
///
///
/// Zero-based index of the indicator.
///
public override void HideIndicator(int index)
{
if (IsValidQTEIndex(index) && IsQTEIndicatorVisible(index))
{
Tools.SetGameObjectActive(qteIndicators[index], false);
numVisibleQTEIndicators--;
}
}
private bool IsQTEIndicatorVisible(int index)
{
return IsValidQTEIndex(index) ? qteIndicators[index].gameObject.activeSelf : false;
}
private bool IsValidQTEIndex(int index)
{
return (0 <= index) && (index < qteIndicators.Length);
}
}
}