Initialer Upload neues Unity-Projekt

This commit is contained in:
Daniel Ocks
2025-07-21 09:11:14 +02:00
commit eeca72985b
14558 changed files with 1508140 additions and 0 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8d635c11ead8ed24ca89687fbcc31264
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,118 @@
/*
* 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 Oculus.Interaction.Input;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Serialization;
namespace Oculus.Interaction
{
public class ControllerOffset : MonoBehaviour
{
[SerializeField, Interface(typeof(IController))]
private UnityEngine.Object _controller;
public IController Controller { get; private set; }
[SerializeField]
private Vector3 _offset;
[SerializeField]
private Quaternion _rotation = Quaternion.identity;
protected bool _started = false;
protected virtual void Awake()
{
Controller = _controller as IController;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Controller, nameof(Controller));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Controller.WhenUpdated += HandleUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Controller.WhenUpdated -= HandleUpdated;
}
}
private void HandleUpdated()
{
if (Controller.TryGetPose(out Pose rootPose))
{
Pose pose = new Pose(Controller.Scale * _offset, _rotation);
pose.Postmultiply(rootPose);
transform.SetPose(pose);
}
}
public void GetOffset(ref Pose pose)
{
pose.position = Controller.Scale * _offset;
pose.rotation = _rotation;
}
public void GetWorldPose(ref Pose pose)
{
pose.position = this.transform.position;
pose.rotation = this.transform.rotation;
}
#region Inject
public void InjectController(IController controller)
{
_controller = controller as UnityEngine.Object;
Controller = controller;
}
public void InjectOffset(Vector3 offset)
{
_offset = offset;
}
public void InjectRotation(Quaternion rotation)
{
_rotation = rotation;
}
public void InjectAllControllerOffset(IController controller,
Vector3 offset, Quaternion rotation)
{
InjectController(controller);
InjectOffset(offset);
InjectRotation(rotation);
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 488896fe86105104a8453d9f173cf62a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,106 @@
/*
* 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 Oculus.Interaction.Input;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Serialization;
namespace Oculus.Interaction
{
public class ControllerPointerPose : MonoBehaviour, IActiveState
{
[SerializeField, Interface(typeof(IController))]
private UnityEngine.Object _controller;
public IController Controller { get; private set; }
[SerializeField]
private Vector3 _offset;
protected bool _started = false;
public bool Active { get; private set; }
protected virtual void Awake()
{
Controller = _controller as IController;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Controller, nameof(Controller));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Controller.WhenUpdated += HandleUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Controller.WhenUpdated -= HandleUpdated;
}
}
private void HandleUpdated()
{
IController controller = Controller;
if (controller.TryGetPointerPose(out Pose pose))
{
pose.position += pose.rotation * (Controller.Scale * _offset);
transform.SetPose(pose);
Active = true;
}
else
{
Active = false;
}
}
#region Inject
public void InjectController(IController controller)
{
_controller = controller as UnityEngine.Object;
Controller = controller;
}
public void InjectOffset(Vector3 offset)
{
_offset = offset;
}
public void InjectAllHandPointerPose(IController controller,
Vector3 offset)
{
InjectController(controller);
InjectOffset(offset);
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 438e12c9002f2c8489c81a2d3472b18d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,125 @@
/*
* 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 Oculus.Interaction.Input;
using System;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Serialization;
namespace Oculus.Interaction
{
public class ControllerSelector : MonoBehaviour, ISelector
{
public enum ControllerSelectorLogicOperator
{
Any = 0,
All = 1
}
[SerializeField, Interface(typeof(IController))]
private UnityEngine.Object _controller;
[SerializeField]
private ControllerButtonUsage _controllerButtonUsage;
[SerializeField]
private ControllerSelectorLogicOperator _requireButtonUsages =
ControllerSelectorLogicOperator.Any;
#region Properties
public ControllerButtonUsage ControllerButtonUsage
{
get
{
return _controllerButtonUsage;
}
set
{
_controllerButtonUsage = value;
}
}
public ControllerSelectorLogicOperator RequireButtonUsages
{
get
{
return _requireButtonUsages;
}
set
{
_requireButtonUsages = value;
}
}
#endregion
public IController Controller { get; private set; }
public event Action WhenSelected = delegate { };
public event Action WhenUnselected = delegate { };
private bool _selected;
protected virtual void Awake()
{
Controller = _controller as IController;
}
protected virtual void Start()
{
this.AssertField(Controller, nameof(Controller));
}
protected virtual void Update()
{
bool selected = _requireButtonUsages == ControllerSelectorLogicOperator.All
? Controller.IsButtonUsageAllActive(_controllerButtonUsage)
: Controller.IsButtonUsageAnyActive(_controllerButtonUsage);
if (selected)
{
if (_selected) return;
_selected = true;
WhenSelected();
}
else
{
if (!_selected) return;
_selected = false;
WhenUnselected();
}
}
#region Inject
public void InjectAllControllerSelector(IController controller)
{
InjectController(controller);
}
public void InjectController(IController controller)
{
_controller = controller as UnityEngine.Object;
Controller = controller;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6d2303af7d4c7114681742031c4a0ac6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dc4c3bb0ec13df74dbe8e912d33cadaf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,120 @@
/*
* 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 Oculus.Interaction.Input;
using UnityEngine;
namespace Oculus.Interaction
{
public class CenterEyeOffset : MonoBehaviour
{
[SerializeField, Interface(typeof(IHmd))]
private UnityEngine.Object _hmd;
public IHmd Hmd { get; private set; }
[SerializeField]
private Vector3 _offset;
[SerializeField]
private Quaternion _rotation = Quaternion.identity;
private Pose _cachedPose = Pose.identity;
protected bool _started = false;
protected virtual void Awake()
{
Hmd = _hmd as IHmd;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Hmd, nameof(Hmd));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Hmd.WhenUpdated += HandleUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hmd.WhenUpdated -= HandleUpdated;
}
}
private void HandleUpdated()
{
if (Hmd.TryGetRootPose(out Pose rootPose))
{
GetOffset(ref _cachedPose);
_cachedPose.Postmultiply(rootPose);
transform.SetPose(_cachedPose);
}
}
public void GetOffset(ref Pose pose)
{
pose.position = _offset;
pose.rotation = _rotation;
}
public void GetWorldPose(ref Pose pose)
{
pose.position = this.transform.position;
pose.rotation = this.transform.rotation;
}
#region Inject
public void InjectOffset(Vector3 offset)
{
_offset = offset;
}
public void InjectRotation(Quaternion rotation)
{
_rotation = rotation;
}
public void InjectAllCenterEyeOffset(IHmd hmd,
Vector3 offset, Quaternion rotation)
{
InjectHmd(hmd);
InjectOffset(offset);
InjectRotation(rotation);
}
public void InjectHmd(IHmd hmd)
{
Hmd = hmd;
_hmd = hmd as UnityEngine.Object;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8268085ebe170e64aa36672a45f0dd8d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,181 @@
/*
* 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 UnityEngine;
namespace Oculus.Interaction
{
public class ConicalFrustum : MonoBehaviour
{
[SerializeField]
[Min(0f)]
private float _minLength = 0f;
[SerializeField]
[Min(0f)]
private float _maxLength = 5f;
[SerializeField]
[Min(0f)]
private float _radiusStart = 0.03f;
[SerializeField]
[Range(0f, 90f)]
private float _apertureDegrees = 20f;
public Pose Pose => this.transform.GetPose();
#region public properties
public float MinLength
{
get
{
return _minLength;
}
set
{
_minLength = value;
}
}
public float MaxLength
{
get
{
return _maxLength;
}
set
{
_maxLength = value;
}
}
public float RadiusStart
{
get
{
return _radiusStart;
}
set
{
_radiusStart = value;
}
}
public float ApertureDegrees
{
get
{
return _apertureDegrees;
}
set
{
_apertureDegrees = value;
}
}
public Vector3 StartPoint
{
get
{
return this.transform.position + Direction * MinLength;
}
}
public Vector3 EndPoint
{
get
{
return this.transform.position + Direction * MaxLength;
}
}
public Vector3 Direction
{
get
{
return this.transform.forward;
}
}
#endregion
public bool IsPointInConeFrustum(Vector3 point)
{
Vector3 coneOriginToPoint = point - this.transform.position;
Vector3 pointProjection = Vector3.Project(coneOriginToPoint, Direction);
if(Vector3.Dot(pointProjection, Direction) < 0)
{
return false;
}
float pointLength = pointProjection.magnitude;
if (pointLength < _minLength
|| pointLength > _maxLength)
{
return false;
}
float pointRadius = Vector3.Distance(Pose.position + pointProjection, point);
return pointRadius <= ConeFrustumRadiusAtLength(pointLength);
}
public float ConeFrustumRadiusAtLength(float length)
{
float radiusEnd = _maxLength * Mathf.Tan(_apertureDegrees * Mathf.Deg2Rad);
float lengthRatio = length / _maxLength;
float radiusAtLength = Mathf.Lerp(_radiusStart, radiusEnd, lengthRatio);
return radiusAtLength;
}
public bool HitsCollider(Collider collider, out float score, out Vector3 point)
{
Vector3 centerPosition = collider.bounds.center;
Vector3 projectedCenter = Pose.position
+ Vector3.Project(centerPosition - Pose.position, Pose.forward);
point = collider.ClosestPointOnBounds(projectedCenter);
if (!IsPointInConeFrustum(point))
{
score = 0f;
return false;
}
Vector3 originToInteractable = point - Pose.position;
float angleToInteractable = Vector3.Angle(originToInteractable.normalized, Pose.forward);
score = 1f - Mathf.Clamp01(angleToInteractable / _apertureDegrees);
return true;
}
public Vector3 NearestColliderHit(Collider collider, out float score)
{
Vector3 centerPosition = collider.bounds.center;
Vector3 projectedCenter = Pose.position
+ Vector3.Project(centerPosition - Pose.position, Pose.forward);
Vector3 point = collider.ClosestPointOnBounds(projectedCenter);
Vector3 originToInteractable = point - Pose.position;
float vectorAngle = Vector3.Angle(originToInteractable.normalized, Pose.forward);
score = 1f - Mathf.Clamp01(vectorAngle / _apertureDegrees);
return point;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 546c836d3c95db04182543d3541aeb12
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,146 @@
/*
* 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 Oculus.Interaction.Input;
using System;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction
{
public class FingerPinchValue : MonoBehaviour, IAxis1D
{
[SerializeField, Interface(typeof(IHand))]
private UnityEngine.Object _hand;
public IHand Hand { get; private set; }
[SerializeField]
private HandFinger _finger = HandFinger.Index;
public HandFinger Finger
{
get
{
return _finger;
}
set
{
_finger = value;
}
}
[SerializeField, Range(0f, 1f)]
private float _changeRate = 1;
public float ChangeRate
{
get
{
return _changeRate;
}
private set
{
_changeRate = value;
}
}
[SerializeField]
private AnimationCurve _curve = AnimationCurve.Linear(0f, 0f, 1f, 1f);
public AnimationCurve Curve
{
get
{
return _curve;
}
set
{
_curve = value;
}
}
private float _value = 0;
protected bool _started = false;
private bool _firstCall;
protected virtual void Awake()
{
Hand = _hand as IHand;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
Assert.IsNotNull(Hand);
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
_firstCall = true;
Hand.WhenHandUpdated += HandleHandUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hand.WhenHandUpdated -= HandleHandUpdated;
}
}
public float Value()
{
return _value;
}
private void HandleHandUpdated()
{
float value = Hand.GetFingerPinchStrength(Finger);
value = Curve.Evaluate(value);
if (_firstCall)
{
_firstCall = false;
_value = value;
}
else
{
_value = Mathf.Lerp(_value, value, _changeRate);
}
}
#region Inject
public void InjectAllFingerPinchValue(IHand hand)
{
InjectHand(hand);
}
public void InjectHand(IHand hand)
{
_hand = hand as UnityEngine.Object;
Hand = hand;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4183772a7ccf28946be25cca333a4c42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,137 @@
/*
* 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 Oculus.Interaction.Input;
using UnityEngine;
namespace Oculus.Interaction
{
public class HandJoint : MonoBehaviour
{
[SerializeField, Interface(typeof(IHand))]
private UnityEngine.Object _hand;
public IHand Hand { get; private set; }
[SerializeField]
private HandJointId _handJointId;
[SerializeField]
private Vector3 _localPositionOffset;
[SerializeField]
private Quaternion _rotationOffset = Quaternion.identity;
#region Properties
public HandJointId HandJointId
{
get
{
return _handJointId;
}
set
{
_handJointId = value;
}
}
public Vector3 LocalPositionOffset
{
get
{
return _localPositionOffset;
}
set
{
_localPositionOffset = value;
}
}
public Quaternion RotationOffset
{
get
{
return _rotationOffset;
}
set
{
_rotationOffset = value;
}
}
#endregion
protected bool _started = false;
protected virtual void Awake()
{
Hand = _hand as IHand;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Hand, nameof(Hand));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Hand.WhenHandUpdated += HandleHandUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hand.WhenHandUpdated -= HandleHandUpdated;
}
}
private void HandleHandUpdated()
{
if (!Hand.GetJointPose(_handJointId, out Pose pose)) return;
Vector3 positionOffsetWithHandedness =
(Hand.Handedness == Handedness.Left ? -1f : 1f) * _localPositionOffset;
pose.position += _rotationOffset * pose.rotation *
positionOffsetWithHandedness * Hand.Scale;
transform.SetPose(pose);
}
#region Inject
public void InjectAllHandJoint(IHand hand)
{
InjectHand(hand);
}
public void InjectHand(IHand hand)
{
_hand = hand as UnityEngine.Object;
Hand = hand;
}
#endregion;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: abee63302fdc2bb4f80efe129df0a723
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,161 @@
/*
* 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 Oculus.Interaction.Input;
using System.Collections.Generic;
using UnityEngine;
namespace Oculus.Interaction
{
/// <summary>
/// Updates the transform to be the interpolated position
/// of a series of joints in the associated IHand.
/// </summary>
public class HandJointsPose : MonoBehaviour
{
[SerializeField, Interface(typeof(IHand))]
private UnityEngine.Object _hand;
public IHand Hand { get; private set; }
[System.Serializable]
public struct WeightedJoint
{
public HandJointId handJointId;
public float weight;
}
[SerializeField]
private List<WeightedJoint> _weightedJoints;
[SerializeField]
private Vector3 _localPositionOffset;
[SerializeField]
private Quaternion _rotationOffset = Quaternion.identity;
#region Properties
public List<WeightedJoint> WeightedJoints
{
get
{
return _weightedJoints;
}
set
{
_weightedJoints = value;
}
}
public Vector3 LocalPositionOffset
{
get
{
return _localPositionOffset;
}
set
{
_localPositionOffset = value;
}
}
public Quaternion RotationOffset
{
get
{
return _rotationOffset;
}
set
{
_rotationOffset = value;
}
}
#endregion
protected bool _started = false;
protected virtual void Awake()
{
Hand = _hand as IHand;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Hand, nameof(Hand));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Hand.WhenHandUpdated += HandleHandUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hand.WhenHandUpdated -= HandleHandUpdated;
}
}
private void HandleHandUpdated()
{
Pose pose = Pose.identity;
float accumulatedWeight = 0f;
foreach (WeightedJoint weightedJoint in _weightedJoints)
{
if (!Hand.GetJointPose(weightedJoint.handJointId, out Pose jointPose))
{
return;
}
float t = weightedJoint.weight / (accumulatedWeight + weightedJoint.weight);
accumulatedWeight += weightedJoint.weight;
pose.Lerp(jointPose, t);
}
Vector3 positionOffsetWithHandedness =
(Hand.Handedness == Handedness.Left ? -1f : 1f) * _localPositionOffset;
pose.position += _rotationOffset * pose.rotation *
positionOffsetWithHandedness * Hand.Scale;
transform.SetPose(pose);
}
#region Inject
public void InjectAllHandJoint(IHand hand)
{
InjectHand(hand);
}
public void InjectHand(IHand hand)
{
_hand = hand as UnityEngine.Object;
Hand = hand;
}
#endregion;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d92c1a7dc2e30b24da860439b4faf7b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,112 @@
/*
* 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 Oculus.Interaction.GrabAPI;
using Oculus.Interaction.Input;
using UnityEngine;
namespace Oculus.Interaction
{
public class HandPinchOffset : MonoBehaviour
{
[SerializeField, Interface(typeof(IHand))]
private UnityEngine.Object _hand;
public IHand Hand { get; private set; }
[SerializeField]
private HandGrabAPI _handGrabApi;
[SerializeField, Optional]
private Collider _collider = null;
protected bool _started = false;
protected virtual void Awake()
{
Hand = _hand as IHand;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Hand, nameof(Hand));
this.AssertField(_handGrabApi, nameof(_handGrabApi));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Hand.WhenHandUpdated += HandleHandUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hand.WhenHandUpdated -= HandleHandUpdated;
}
}
private void HandleHandUpdated()
{
Vector3 center = _handGrabApi.GetPinchCenter();
if (_collider != null)
{
center = _collider.ClosestPoint(center);
}
transform.position = center;
if (Hand.GetRootPose(out Pose pose))
{
transform.rotation = pose.rotation;
}
}
#region Inject
public void InjectAllHandPinchOffset(IHand hand,
HandGrabAPI handGrabApi)
{
InjectHand(hand);
InjectHandGrabAPI(handGrabApi);
}
public void InjectHand(IHand hand)
{
Hand = hand;
_hand = hand as UnityEngine.Object;
}
public void InjectHandGrabAPI(HandGrabAPI handGrabApi)
{
_handGrabApi = handGrabApi;
}
public void InjectOptionalCollider(Collider collider)
{
_collider = collider;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9c2beb69c900ccf4984646ad420b1e17
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,99 @@
/*
* 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 Oculus.Interaction.Input;
using UnityEngine;
using UnityEngine.Assertions;
namespace Oculus.Interaction
{
public class HandPointerPose : MonoBehaviour, IActiveState
{
[SerializeField, Interface(typeof(IHand))]
private UnityEngine.Object _hand;
public IHand Hand { get; private set; }
[SerializeField]
private Vector3 _offset;
public bool Active => Hand.IsPointerPoseValid;
protected bool _started = false;
protected virtual void Awake()
{
Hand = _hand as IHand;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Hand, nameof(Hand));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Hand.WhenHandUpdated += HandleHandUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hand.WhenHandUpdated -= HandleHandUpdated;
}
}
private void HandleHandUpdated()
{
if (Hand.GetPointerPose(out Pose pointerPose))
{
pointerPose.position += pointerPose.rotation * _offset;
transform.SetPose(pointerPose);
}
}
#region Inject
public void InjectAllHandPointerPose(IHand hand,
Vector3 offset)
{
InjectHand(hand);
InjectOffset(offset);
}
public void InjectHand(IHand hand)
{
_hand = hand as UnityEngine.Object;
Hand = hand;
}
public void InjectOffset(Vector3 offset)
{
_offset = offset;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 417817ee9b785e341b31ce731f028317
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,75 @@
/*
* 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 Oculus.Interaction.Input;
using UnityEngine;
namespace Oculus.Interaction
{
public class HandTransformScaler : MonoBehaviour
{
[SerializeField, Interface(typeof(IHand))]
private UnityEngine.Object _hand;
public IHand Hand { get; private set; }
protected bool _started = false;
private Vector3 _originalScale = Vector3.one;
protected virtual void Awake()
{
Hand = _hand as IHand;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Hand, nameof(Hand));
_originalScale = this.transform.localScale;
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Hand.WhenHandUpdated += HandleHandUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hand.WhenHandUpdated -= HandleHandUpdated;
}
}
private void HandleHandUpdated()
{
float parentScale = 1f;
if (this.transform.parent != null)
{
parentScale = this.transform.parent.lossyScale.x;
}
transform.localScale = _originalScale * Hand.Scale / parentScale;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5a52cc62b98662b4e9ac356027b2b070
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,181 @@
/*
* 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 Oculus.Interaction.Input;
using UnityEngine;
namespace Oculus.Interaction
{
/// <summary>
/// Specifies a position and rotation offset from the wrist of the given hand
/// </summary>
public class HandWristOffset : MonoBehaviour
{
[SerializeField, Interface(typeof(IHand))]
private UnityEngine.Object _hand;
public IHand Hand { get; private set; }
[SerializeField]
[HideInInspector]
private Vector3 _offset;
[SerializeField]
[HideInInspector]
private Quaternion _rotation = Quaternion.identity;
[SerializeField]
[Tooltip("Mirrors the rotation offset when the attached Hand is has Left Handedness")]
private bool _mirrorLeftRotation = true;
private Pose _cachedPose = Pose.identity;
public Vector3 Offset
{
get
{
return _offset;
}
set
{
_offset = value;
}
}
public Quaternion Rotation
{
get
{
return _rotation;
}
set
{
_rotation = value;
}
}
public bool MirrorLeftRotation
{
get
{
return _mirrorLeftRotation;
}
set
{
_mirrorLeftRotation = value;
}
}
private static readonly Quaternion LEFT_MIRROR_ROTATION = Quaternion.Euler(180f, 0f, 0f);
protected bool _started = false;
protected virtual void Awake()
{
Hand = _hand as IHand;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Hand, nameof(Hand));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Hand.WhenHandUpdated += HandleHandUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hand.WhenHandUpdated -= HandleHandUpdated;
}
}
private void HandleHandUpdated()
{
if (Hand.GetRootPose(out Pose rootPose))
{
GetOffset(ref _cachedPose);
_cachedPose.Postmultiply(rootPose);
transform.SetPose(_cachedPose);
}
}
public void GetOffset(ref Pose pose)
{
if (!_started)
{
return;
}
GetOffset(ref pose, Hand.Handedness, Hand.Scale);
}
public void GetOffset(ref Pose pose, Handedness handedness, float scale)
{
if (_mirrorLeftRotation && handedness == Handedness.Left)
{
pose.position = -_offset * scale;
pose.rotation = _rotation * LEFT_MIRROR_ROTATION;
}
else
{
pose.position = _offset * scale;
pose.rotation = _rotation;
}
}
public void GetWorldPose(ref Pose pose)
{
pose.position = this.transform.position;
pose.rotation = this.transform.rotation;
}
#region Inject
public void InjectHand(IHand hand)
{
_hand = hand as UnityEngine.Object;
Hand = hand;
}
public void InjectOffset(Vector3 offset)
{
_offset = offset;
}
public void InjectRotation(Quaternion rotation)
{
_rotation = rotation;
}
public void InjectAllHandWristOffset(IHand hand,
Vector3 offset, Quaternion rotation)
{
InjectHand(hand);
InjectOffset(offset);
InjectRotation(rotation);
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d61ea23b9fd13af40afe326bb23ac1cd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,184 @@
/*
* 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 Oculus.Interaction.Input;
using System;
using UnityEngine;
namespace Oculus.Interaction
{
/// <summary>
/// This Selector selects for a frame when the Pinch is released, as opposed to when it is pinching.
/// It uses the system pinch (index and thumb) but due to some false-positives with pinch detection,
/// to establish that a pinch has released the index must be not pinching and be extended.
/// </summary>
public class IndexPinchSafeReleaseSelector : MonoBehaviour,
ISelector, IActiveState
{
[SerializeField, Interface(typeof(IHand))]
private UnityEngine.Object _hand;
public IHand Hand { get; private set; }
[SerializeField]
private bool _selectOnRelease = true;
public bool Active => this.enabled && _isIndexFingerPinching && !_cancelled;
[SerializeField, Interface(typeof(IActiveState))]
private UnityEngine.Object _indexReleaseSafeguard;
private IActiveState IndexReleaseSafeguard;
private bool _isIndexFingerPinching;
private bool _cancelled;
private bool _pendingUnselect;
public event Action WhenSelected = delegate { };
public event Action WhenUnselected = delegate { };
protected bool _started = false;
protected virtual void Awake()
{
Hand = _hand as IHand;
IndexReleaseSafeguard = _indexReleaseSafeguard as IActiveState;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Hand, nameof(Hand));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Hand.WhenHandUpdated += HandleHandUpdated;
_isIndexFingerPinching = false;
_pendingUnselect = false;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hand.WhenHandUpdated -= HandleHandUpdated;
}
}
private void HandleHandUpdated()
{
bool isPinchDetected = Hand.GetIndexFingerIsPinching();
bool isReleaseDetected = !isPinchDetected && IndexReleaseSafeguard.Active;
if (_selectOnRelease)
{
ProcessSelectOnRelease(isPinchDetected, isReleaseDetected);
}
else
{
ProcessSelectOnPinch(isPinchDetected, isReleaseDetected);
}
}
private void ProcessSelectOnPinch(bool isPinchDetected, bool isReleaseDetected)
{
if (!_isIndexFingerPinching && isPinchDetected && !_cancelled)
{
_isIndexFingerPinching = true;
WhenSelected.Invoke();
}
else if (_isIndexFingerPinching && isReleaseDetected)
{
_isIndexFingerPinching = false;
WhenUnselected.Invoke();
}
if (!_isIndexFingerPinching && _cancelled)
{
_cancelled = false;
}
}
private void ProcessSelectOnRelease(bool isPinchDetected, bool isReleaseDetected)
{
if (!_isIndexFingerPinching && isPinchDetected)
{
_isIndexFingerPinching = true;
}
if (!_isIndexFingerPinching && _pendingUnselect)
{
_pendingUnselect = false;
WhenUnselected.Invoke();
}
if (_isIndexFingerPinching && isReleaseDetected)
{
_isIndexFingerPinching = false;
if (!_cancelled)
{
WhenSelected.Invoke();
_pendingUnselect = true;
}
_cancelled = false;
}
}
public void Cancel()
{
if (_isIndexFingerPinching)
{
_cancelled = true;
}
}
#region Inject
public void InjectAllIndexPinchSafeReleaseSelector(IHand hand,
bool selectOnRelease,
IActiveState indexReleaseSafeguard)
{
InjectHand(hand);
InjectSelectOnRelease(selectOnRelease);
InjectIndexReleaseSafeguard(indexReleaseSafeguard);
}
public void InjectHand(IHand hand)
{
_hand = hand as UnityEngine.Object;
Hand = hand;
}
public void InjectSelectOnRelease(bool selectOnRelease)
{
_selectOnRelease = selectOnRelease;
}
public void InjectIndexReleaseSafeguard(IActiveState indexReleaseSafeguard)
{
_indexReleaseSafeguard = indexReleaseSafeguard as UnityEngine.Object;
IndexReleaseSafeguard = indexReleaseSafeguard;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c9940d31c819e704889d891a6ce925b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,102 @@
/*
* 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 Oculus.Interaction.Input;
using System;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Serialization;
namespace Oculus.Interaction
{
public class IndexPinchSelector : MonoBehaviour, ISelector
{
[SerializeField, Interface(typeof(IHand))]
private UnityEngine.Object _hand;
public IHand Hand { get; private set; }
private bool _isIndexFingerPinching;
public event Action WhenSelected = delegate { };
public event Action WhenUnselected = delegate { };
protected bool _started = false;
protected virtual void Awake()
{
Hand = _hand as IHand;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Hand, nameof(Hand));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Hand.WhenHandUpdated += HandleHandUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hand.WhenHandUpdated -= HandleHandUpdated;
}
}
private void HandleHandUpdated()
{
var prevPinching = _isIndexFingerPinching;
_isIndexFingerPinching = Hand.GetIndexFingerIsPinching();
if (prevPinching != _isIndexFingerPinching)
{
if (_isIndexFingerPinching)
{
WhenSelected();
}
else
{
WhenUnselected();
}
}
}
#region Inject
public void InjectAllIndexPinchSelector(IHand hand)
{
InjectHand(hand);
}
public void InjectHand(IHand hand)
{
_hand = hand as UnityEngine.Object;
Hand = hand;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1b6b944de90aa9047929c54d143ff2da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,113 @@
/*
* 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 Oculus.Interaction.Input;
using UnityEngine;
namespace Oculus.Interaction
{
/// <summary>
/// Updates its transform to the estimated shoulder position and rotation.
/// Estimated pose is based on an offset from the head, taking in count
/// just the rotation Yaw. Hand is required to know not just the handedness
/// but also alter the scale of the offset.
/// </summary>
public class ShoulderEstimatePosition : MonoBehaviour
{
[SerializeField, Interface(typeof(IHmd))]
private UnityEngine.Object _hmd;
private IHmd Hmd { get; set; }
[SerializeField, Interface(typeof(IHand))]
private UnityEngine.Object _hand;
private IHand Hand { get; set; }
private static readonly Vector3 ShoulderOffset = new Vector3(0.13f, -0.25f, -0.13f);
protected bool _started;
protected virtual void Awake()
{
Hmd = _hmd as IHmd;
Hand = _hand as IHand;
}
protected virtual void Start()
{
this.BeginStart(ref _started);
this.AssertField(Hmd, nameof(_hmd));
this.AssertField(Hand, nameof(_hand));
this.EndStart(ref _started);
}
protected virtual void OnEnable()
{
if (_started)
{
Hmd.WhenUpdated += HandleHmdUpdated;
}
}
protected virtual void OnDisable()
{
if (_started)
{
Hmd.WhenUpdated -= HandleHmdUpdated;
}
}
protected virtual void HandleHmdUpdated()
{
Hmd.TryGetRootPose(out Pose headPose);
Quaternion shoulderYaw = Quaternion.Euler(0f, headPose.rotation.eulerAngles.y, 0f);
Vector3 offset = ShoulderOffset * Hand.Scale;
if (Hand.Handedness == Handedness.Left)
{
offset.x = -offset.x;
}
Vector3 projectionOrigin = headPose.position + shoulderYaw * offset;
this.transform.SetPositionAndRotation(projectionOrigin, shoulderYaw);
}
#region Inject
public void InjectAllShoulderPosition(IHmd hmd,
IHand hand)
{
InjectHmd(hmd);
InjectHand(hand);
}
public void InjectHmd(IHmd hmd)
{
_hmd = hmd as UnityEngine.Object;
Hmd = hmd;
}
public void InjectHand(IHand hand)
{
_hand = hand as UnityEngine.Object;
Hand = hand;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a63ea968be5c2084588e377a5dc05473
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3993c66e74c321e4db0acd218a71008a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,72 @@
/*
* 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
{
/// <summary>
/// This Virtual Selector can provide interactions with a sample selector
/// that can be toggled from within the Unity insepctor using the HandleSelected Flag
/// </summary>
public class VirtualSelector : MonoBehaviour, ISelector
{
[SerializeField]
private bool _selectFlag;
public event Action WhenSelected = delegate { };
public event Action WhenUnselected = delegate { };
private bool _currentlySelected;
public void Select()
{
_selectFlag = true;
UpdateSelection();
}
public void Unselect()
{
_selectFlag = false;
UpdateSelection();
}
protected virtual void OnValidate()
{
UpdateSelection();
}
protected void UpdateSelection()
{
if (_currentlySelected != _selectFlag)
{
_currentlySelected = _selectFlag;
if (_currentlySelected)
{
WhenSelected();
}
else
{
WhenUnselected();
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 42bba106679662e4b925dca314de22c2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: