namespace VRTK.Prefabs.Helpers.Tooltip
{
using UnityEngine;
using Malimbe.PropertySerializationAttribute;
using Malimbe.XmlDocumentationAttribute;
using Zinnia.Process;
using Zinnia.Data.Attribute;
///
/// Sets up the Tooltip prefab based on the provided settings and implements the logic to display the tooltip.
///
public class TooltipConfigurator : MonoBehaviour, IProcessable
{
#region Facade Settings
///
/// The public interface facade.
///
[Serialized]
[field: Header("Facade Settings"), DocumentedByXml, Restricted]
public TooltipFacade Facade { get; protected set; }
#endregion
#region Reference Settings
///
/// The to draw a line from tooltip to target.
///
[Serialized]
[field: Header("Reference Settings"), DocumentedByXml, Restricted]
public LineRenderer LineRenderer { get; protected set; }
///
/// The use as the origin point for the line.
///
[Serialized]
[field: DocumentedByXml, Restricted]
public GameObject LineOrigin { get; protected set; }
#endregion
///
/// Processes the visualization of the tooltip.
///
public virtual void Process()
{
if (Facade.FacingSource != null)
{
Facade.transform.LookAt(Facade.FacingSource.transform);
}
SetLine(Facade.LineTarget);
ToggleLineVisibility();
}
///
/// Sets the tooltip pointer line appearance.
///
/// The target to point the line towards.
public virtual void SetLine(GameObject target)
{
if (target == null)
{
return;
}
LineRenderer.SetPosition(0, LineOrigin.transform.position);
LineRenderer.SetPosition(1, target.transform.position);
}
protected virtual void OnEnable()
{
SetLine(Facade.LineTarget);
ToggleLineVisibility();
}
///
/// Toggles the visibility of the tooltip line depending on whether there is a valid target.
///
protected virtual void ToggleLineVisibility()
{
LineRenderer.gameObject.SetActive(Facade.LineTarget != null);
}
}
}