namespace Zinnia.Rule { using System.Collections.Generic; using UnityEngine; using UnityEngine.XR; using Zinnia.Extension; using Zinnia.Tracking.CameraRig; /// /// Determines whether the selected matches the current value set in the given . /// public class DominantControllerRule : Rule { /// /// The controller types. /// public enum Controller { /// /// The headset as a controller /// Head, /// /// The left controller. /// LeftController, /// /// The right controller. /// RightController } [Tooltip("A source collection to get the first active current dominant controller from.")] [SerializeField] private List sources = new List(); /// /// A source collection to get the first active current dominant controller from. /// public List Sources { get { return sources; } set { sources = value; } } [Tooltip("The controller to check to see if the source matches.")] [SerializeField] private Controller toMatch; /// /// The controller to check to see if the source matches. /// public Controller ToMatch { get { return toMatch; } set { toMatch = value; } } /// public override bool Accepts(object _) { if (ShouldAutoRejectDueToState()) { return false; } foreach (DominantControllerObserver Source in Sources) { if (!Source.gameObject.activeInHierarchy || !Source.enabled) { continue; } switch (ToMatch) { case Controller.Head: return Source.DominantController == XRNode.Head; case Controller.LeftController: return Source.DominantController == XRNode.LeftHand; case Controller.RightController: return Source.DominantController == XRNode.RightHand; } } return false; } /// /// Sets the . /// /// The index of the . public virtual void SetToMatch(int index) { ToMatch = EnumExtensions.GetByIndex(index); } } }