using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Google.Maps.Examples.Shared { /// /// Class for showing an in-scene, aligned Label. /// [RequireComponent(typeof(CanvasGroup))] public class Label : MonoBehaviour { [Tooltip("Text element to show this Label's text in.")] public Text Text; [Tooltip( "Should this Label keep its starting x-rotation (i.e. should it stay at its current " + "up/down tilt amount, and just turn in y-axis to face Camera)?")] public bool TurnOnly; [Tooltip( "Should the Label which is the most closely aligned to the Camera be the most visible? " + "This helps reduce visual clutter by allowing all Labels not been directly looked at to " + "be faded out.")] public bool FadeWithView; [Tooltip("Total time this Label should take to fade in or out?")] public float FadeTime = 1f; [Tooltip("Should this Label start hidden?")] public bool StartFadedOut; [Tooltip("Should this Label automatically start fading in as soon as SetText is called?")] public bool AutoFadeIn; /// /// Is this currently tracking , i.e. is this /// continually making sure it is aligned to ? /// /// /// This flag is used to ensure that the coroutine for -tracking is not /// redundantly started when it is already running. /// private bool IsTrackingCamera; /// Is this currently fading in or out? /// /// This flag is used to ensure that the fading-facing coroutine is not redundantly started when /// when it is already running. /// private bool IsFading; /// Has a component been defined? /// /// This is set to null before this check is performed, allowing this check to only be performed /// once, with the result being stored for future re-use. /// private bool? HasText; /// Is this currently fading in (true) or out (false)? private bool FadingIn; /// Time into current fade. private float FadeTimer; /// /// Value to multiply alpha by to achieve desired alpha level? This is used when alpha is /// controlled by view angle, to allow manual changes in alpha or fading animations to be /// combined with this view-dependant alpha logic. /// /// /// This value starts at 1f to ensure no change in alpha until a new value is set. /// private float AlphaMultiplier = 1f; /// /// Required , used for optionally fading all parts of this /// in or out as looks towards or away from it. /// /// /// This variable is auto-found on first access, allowing this to be /// accessed at any time without having to check if it is null. /// private CanvasGroup CanvasGroup { get { if (_CanvasGroup == null) { _CanvasGroup = GetComponent(); } return _CanvasGroup; } } /// /// Actual stored . This is stored in this way to allow /// to be used at any time without having to check if it is /// null. /// private CanvasGroup _CanvasGroup; /// Has this been setup yet? /// Allows setup to be intelligently called when needed? private bool IsSetup; /// /// All s in the current scene. Used to perform group actions, like starting /// all s fading in or out together, or hiding the part of /// all s. /// private static readonly List