// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using Microsoft.MixedReality.Toolkit.Physics; using System.Collections; using UnityEngine; namespace Microsoft.MixedReality.Toolkit.Input { /// /// Base Class for pointers that don't inherit from MonoBehaviour. /// public abstract class GenericPointer : IMixedRealityPointer { /// /// Constructor. /// protected GenericPointer(string pointerName, IMixedRealityInputSource inputSourceParent) { PointerId = (CoreServices.InputSystem?.FocusProvider != null) ? CoreServices.InputSystem.FocusProvider.GenerateNewPointerId() : 0; PointerName = pointerName; this.inputSourceParent = inputSourceParent; } /// public virtual IMixedRealityController Controller { get { return controller; } set { controller = value; if (controller != null) { inputSourceParent = controller.InputSource; } } } private IMixedRealityController controller; /// public uint PointerId { get; } /// public string PointerName { get; set; } /// public virtual IMixedRealityInputSource InputSourceParent { get { return inputSourceParent; } protected set { inputSourceParent = value; } } private IMixedRealityInputSource inputSourceParent; /// public IMixedRealityCursor BaseCursor { get; set; } /// public ICursorModifier CursorModifier { get; set; } private bool isInteractionEnabled = true; /// public bool IsInteractionEnabled { get { return isInteractionEnabled && IsActive; } set { if (isInteractionEnabled != value) { isInteractionEnabled = value; if (BaseCursor != null) { BaseCursor.SetVisibility(value); } } } } /// public bool IsActive { get; set; } /// public bool IsFocusLocked { get; set; } /// public bool IsTargetPositionLockedOnFocusLock { get; set; } /// /// The pointer's maximum extent when raycasting. /// public virtual float PointerExtent { get; set; } = 10f; /// public RayStep[] Rays { get; protected set; } = { new RayStep(Vector3.zero, Vector3.forward) }; /// public LayerMask[] PrioritizedLayerMasksOverride { get; set; } = null; /// public IMixedRealityFocusHandler FocusTarget { get; set; } /// public IPointerResult Result { get; set; } /// /// Ray stabilizer used when calculating position of pointer end point. /// public IBaseRayStabilizer RayStabilizer { get; set; } /// public SceneQueryType SceneQueryType { get; set; } = SceneQueryType.SimpleRaycast; /// public float SphereCastRadius { get; set; } /// public abstract Vector3 Position { get; } /// public abstract Quaternion Rotation { get; } /// public abstract void OnPreSceneQuery(); /// public abstract void OnPostSceneQuery(); /// public abstract void OnPreCurrentPointerTargetChange(); /// public abstract void Reset(); #region IEquality Implementation public static bool Equals(IMixedRealityPointer left, IMixedRealityPointer right) { return left.Equals(right); } /// bool IEqualityComparer.Equals(object left, object right) { return left.Equals(right); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } if (ReferenceEquals(this, obj)) { return true; } if (obj.GetType() != GetType()) { return false; } return Equals((IMixedRealityPointer)obj); } private bool Equals(IMixedRealityPointer other) { return other != null && PointerId == other.PointerId && string.Equals(PointerName, other.PointerName); } /// int IEqualityComparer.GetHashCode(object obj) { return obj.GetHashCode(); } public override int GetHashCode() { unchecked { int hashCode = 0; hashCode = (hashCode * 397) ^ (int)PointerId; hashCode = (hashCode * 397) ^ (PointerName != null ? PointerName.GetHashCode() : 0); return hashCode; } } #endregion IEquality Implementation } }