/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * Licensed under the Oculus SDK License Agreement (the "License"); * you may not use the Oculus SDK except in compliance with the License, * which is provided at the time of installation or download, or which * otherwise accompanies this software in either electronic or hard copy form. * * You may obtain a copy of the License at * * https://developer.oculus.com/licenses/oculussdk/ * * Unless required by applicable law or agreed to in writing, the Oculus SDK * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using UnityEngine; namespace Oculus.Interaction.Input { /// /// HandRef is a utility component that delegates all of its implementation /// to the provided object. /// /// /// HandRef can be thought of as a "redirect," which is useful for making Unity Component configurations /// flexible with limited setup. For example, if making a prefab containing multiple hand-referencing /// components which should be usable with either hand, it is more convenient to have a single HandRef /// at the root of the prefab (to which all the other Components connect) and connect only that to the /// desired hand versus having to connect every Component individually for every instance of the prefab. /// public class HandRef : MonoBehaviour, IHand, IActiveState { [SerializeField, Interface(typeof(IHand))] private UnityEngine.Object _hand; /// /// The underlying to which this HandRef is a shim. All IHand methods invoked on /// this HandRef will be passed along to this instance. /// public IHand Hand { get; private set; } /// /// Retrieves the of the underlying . /// /// /// This is a pure shim property equivalent to accessing the same property on the . /// public Handedness Handedness => Hand.Handedness; /// /// Retrieves the value of the underlying . /// /// /// This is a pure shim property equivalent to accessing the same property on the . /// public bool IsConnected => Hand.IsConnected; /// /// Retrieves the value of the underlying . /// /// /// This is a pure shim property equivalent to accessing the same property on the . /// public bool IsHighConfidence => Hand.IsHighConfidence; /// /// Retrieves the value of the underlying . /// /// /// This is a pure shim property equivalent to accessing the same property on the . /// public bool IsDominantHand => Hand.IsDominantHand; /// /// Retrieves the value of the underlying . /// /// /// This is a pure shim property equivalent to accessing the same property on the . /// public float Scale => Hand.Scale; /// /// Retrieves the value of the underlying . /// /// /// This is a pure shim property equivalent to accessing the same property on the . /// public bool IsPointerPoseValid => Hand.IsPointerPoseValid; /// /// Retrieves the value of the underlying . /// /// /// This is a pure shim property equivalent to accessing the same property on the . /// public bool IsTrackedDataValid => Hand.IsTrackedDataValid; /// /// Retrieves the value of the underlying . /// /// /// This is a pure shim property equivalent to accessing the same property on the . /// public int CurrentDataVersion => Hand.CurrentDataVersion; /// /// Retrieves the event of the underlying . /// /// /// This is a pure shim property equivalent to accessing the same property on the . /// public event Action WhenHandUpdated { add => Hand.WhenHandUpdated += value; remove => Hand.WhenHandUpdated -= value; } /// /// Implements , in this case indicating whether the underlying /// is connected. This is a remapping method which makes the /// value available to consumers treating the HandRef as an /// . /// public bool Active => IsConnected; protected virtual void Awake() { Hand = _hand as IHand; } protected virtual void Start() { this.AssertField(Hand, nameof(Hand)); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetFingerIsPinching(HandFinger finger) { return Hand.GetFingerIsPinching(finger); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetIndexFingerIsPinching() { return Hand.GetIndexFingerIsPinching(); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetPointerPose(out Pose pose) { return Hand.GetPointerPose(out pose); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetJointPose(HandJointId handJointId, out Pose pose) { return Hand.GetJointPose(handJointId, out pose); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetJointPoseLocal(HandJointId handJointId, out Pose pose) { return Hand.GetJointPoseLocal(handJointId, out pose); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetJointPosesLocal(out ReadOnlyHandJointPoses jointPosesLocal) { return Hand.GetJointPosesLocal(out jointPosesLocal); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetJointPoseFromWrist(HandJointId handJointId, out Pose pose) { return Hand.GetJointPoseFromWrist(handJointId, out pose); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetJointPosesFromWrist(out ReadOnlyHandJointPoses jointPosesFromWrist) { return Hand.GetJointPosesFromWrist(out jointPosesFromWrist); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetPalmPoseLocal(out Pose pose) { return Hand.GetPalmPoseLocal(out pose); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetFingerIsHighConfidence(HandFinger finger) { return Hand.GetFingerIsHighConfidence(finger); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public float GetFingerPinchStrength(HandFinger finger) { return Hand.GetFingerPinchStrength(finger); } /// /// Invokes on the underlying . /// /// /// This is a pure shim method equivalent to invoking the same method on the . /// public bool GetRootPose(out Pose pose) { return Hand.GetRootPose(out pose); } #region Inject /// /// Sets all required dependencies for a dynamically instantiated HandRef. This is a convenience method wrapping /// . This method exists to support Interaction SDK's dependency injection pattern /// and is not needed for typical Unity Editor-based usage. /// public void InjectAllHandRef(IHand hand) { InjectHand(hand); } /// /// Sets the an as the for a dynamically instantiated HandRef. This method /// exists to support Interaction SDK's dependency injection pattern and is not needed for typical Unity Editor-based /// usage. /// public void InjectHand(IHand hand) { _hand = hand as UnityEngine.Object; Hand = hand; } #endregion } }