using System.Collections.Generic; using UnityEngine.Scripting.APIUpdating; using UnityEngine.XR.Interaction.Toolkit.Interactors; namespace UnityEngine.XR.Interaction.Toolkit.Interactables { /// /// An interface that represents an Interactable component which /// an Interactor component can persistently select. /// [MovedFrom("UnityEngine.XR.Interaction.Toolkit")] public interface IXRFocusInteractable : IXRInteractable { /// /// The event that is called only when the first Interaction Group gains focus on /// this Interactable as the sole focusing Interactor. Subsequent Interactors that /// gain focus will not cause this event to be invoked as long as any others are still focusing. /// /// /// The passed to each listener is only valid while the event is invoked, /// do not hold a reference to it. /// /// /// FocusEnterEvent firstFocusEntered { get; } /// /// The event that is called only when the last remaining focused Interaction group /// loses focus on this Interactable. /// /// /// The passed to each listener is only valid while the event is invoked, /// do not hold a reference to it. /// /// /// FocusExitEvent lastFocusExited { get; } /// /// The event that is called when an Interaction group gains focus on this Interactable. /// /// /// The passed to each listener is only valid while the event is invoked, /// do not hold a reference to it. /// /// FocusEnterEvent focusEntered { get; } /// /// The event that is called when an Interaction group loses focus on this Interactable. /// /// /// The passed to each listener is only valid while the event is invoked, /// do not hold a reference to it. /// /// FocusExitEvent focusExited { get; } /// /// (Read Only) The list of Interaction groups currently focusing on this Interactable (may by empty). /// /// /// You should treat this as a read only view of the list and should not modify it. /// It is exposed as a rather than an to avoid GC Allocations /// when enumerating the list. /// /// List interactionGroupsFocusing { get; } /// /// (Read Only) The first interaction group that is focused on this interactable since not being focused. /// The group may not currently be focusing this interactable, which would be the case /// when it released while multiple groups were focusing this interactable. /// IXRInteractionGroup firstInteractionGroupFocusing { get; } /// /// (Read Only) Indicates whether this interactable is currently being focused by any interaction group. /// /// /// In other words, returns whether contains any interaction groups. /// /// /// interactionGroupsFocusing.Count > 0 /// /// bool isFocused { get; } /// /// Indicates the focus policy of an Interactable. /// /// InteractableFocusMode focusMode { get; } /// /// Indicates whether this Interactable can be focused. /// bool canFocus { get; } /// /// The calls this method /// right before the Interaction group first gains focus of an Interactable /// in a first pass. /// /// Event data containing the Interaction group that is initiating the focus. /// /// is only valid during this method call, do not hold a reference to it. /// /// void OnFocusEntering(FocusEnterEventArgs args); /// /// The calls this method /// when the Interaction group first gains focus of an Interactable /// in a second pass. /// /// Event data containing the Interaction group that is initiating the focus. /// /// is only valid during this method call, do not hold a reference to it. /// /// void OnFocusEntered(FocusEnterEventArgs args); /// /// The calls this method /// right before the Interaction group loses focus of an Interactable /// in a first pass. /// /// Event data containing the Interaction group that is losing focus. /// /// is only valid during this method call, do not hold a reference to it. /// /// void OnFocusExiting(FocusExitEventArgs args); /// /// The calls this method /// when the Interaction group loses focus of an Interactable /// in a second pass. /// /// Event data containing the Interaction group that is losing focus. /// /// is only valid during this method call, do not hold a reference to it. /// /// void OnFocusExited(FocusExitEventArgs args); } /// /// Extension methods for . /// /// [MovedFrom("UnityEngine.XR.Interaction.Toolkit")] public static class XRFocusInteractableExtensions { /// /// Gets the oldest interaction group currently focusing on this interactable. /// This is a convenience method for when the interactable does not support being focused by multiple interaction groups at a time. /// /// The interactable to operate on. /// Returns the oldest interaction group currently focusing this interactable. /// /// Equivalent to interactionGroupsFocusing.Count > 0 ? interactionGroupsFocusing[0] : null /// public static IXRInteractionGroup GetOldestInteractorFocusing(this IXRFocusInteractable interactable) => interactable?.interactionGroupsFocusing.Count > 0 ? interactable.interactionGroupsFocusing[0] : null; } /// /// Options for the focus policy of an Interactable. /// /// [MovedFrom("UnityEngine.XR.Interaction.Toolkit")] public enum InteractableFocusMode { /// /// Focus not supported for this interactable. /// None, /// /// Allows the Interactable to only be focused by a single Interaction group at a time /// and allows other Interaction groups to take focus by automatically losing focus. /// Single, /// /// Allows for multiple Interaction groups at a time to focus the Interactable. /// /// /// This option can be disabled in the Inspector window by adding the /// with a value of to a derived class of . /// Multiple, } }