Skip to content

Commit

Permalink
Support hand tracking input in demo scene
Browse files Browse the repository at this point in the history
  • Loading branch information
bnco-dev committed Dec 3, 2024
1 parent 2f65f79 commit 1049c4d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 120 deletions.
8 changes: 6 additions & 2 deletions Unity/Assets/Ubiq/Runtime/Compatibility/XRI/MenuAdapterXRI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ namespace Ubiq.XRI
{
public class MenuAdapterXRI : MonoBehaviour
{
public bool grabbable = true;
#if XRI_3_0_7_OR_NEWER
private void Start()
{
var grab = gameObject.AddComponent<UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable>();
grab.throwOnDetach = false;
if (grabbable)
{
var grab = gameObject.AddComponent<UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable>();
grab.throwOnDetach = false;
}
var canvas = GetComponentInChildren<Canvas>();
canvas.gameObject.AddComponent<TrackedDeviceGraphicRaycaster>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_TransitionDuration: 0.125
m_InteractableSource: {fileID: 2865038132169618814}
m_InteractableSource: {fileID: 0}
m_IgnoreHoverEvents: 0
m_IgnoreHoverPriorityEvents: 1
m_IgnoreFocusEvents: 0
Expand Down Expand Up @@ -317,9 +317,8 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 8245267067570120123}
- component: {fileID: 1716084023271190560}
- component: {fileID: 8245267067570120127}
- component: {fileID: 2865038132169618814}
- component: {fileID: 6422948690798026994}
m_Layer: 0
m_Name: Fireworks Box
m_TagString: Untagged
Expand All @@ -335,42 +334,15 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8245267067570120064}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0.7071068, z: -0, w: 0.7071068}
m_LocalRotation: {x: 0, y: -0.7071068, z: 0, w: 0.7071068}
m_LocalPosition: {x: 1.463, y: 0.484, z: -1.358}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 8901737113673820539}
- {fileID: 3240370694413710573}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!54 &1716084023271190560
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8245267067570120064}
serializedVersion: 4
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_CenterOfMass: {x: 0, y: 0, z: 0}
m_InertiaTensor: {x: 1, y: 1, z: 1}
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_ImplicitCom: 1
m_ImplicitTensor: 1
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 1
m_Constraints: 0
m_CollisionDetection: 0
m_LocalEulerAnglesHint: {x: 0, y: -90, z: 0}
--- !u!114 &8245267067570120127
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -385,7 +357,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
fireworkPrefab: {fileID: 4511263541971767917, guid: 87221b841a51c2840bc5648fa3be6dfe,
type: 3}
--- !u!114 &2865038132169618814
--- !u!114 &6422948690798026994
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -394,7 +366,7 @@ MonoBehaviour:
m_GameObject: {fileID: 8245267067570120064}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0ad34abafad169848a38072baa96cdb2, type: 3}
m_Script: {fileID: 11500000, guid: 8a35f6cfbfba9b548aaa00d52cfe8a50, type: 3}
m_Name:
m_EditorClassIdentifier:
m_InteractionManager: {fileID: 0}
Expand Down Expand Up @@ -457,53 +429,3 @@ MonoBehaviour:
m_StartingHoverFilters: []
m_StartingSelectFilters: []
m_StartingInteractionStrengthFilters: []
m_AttachTransform: {fileID: 0}
m_SecondaryAttachTransform: {fileID: 0}
m_UseDynamicAttach: 0
m_MatchAttachPosition: 1
m_MatchAttachRotation: 1
m_SnapToColliderVolume: 1
m_ReinitializeDynamicAttachEverySingleGrab: 1
m_AttachEaseInTime: 0.15
m_MovementType: 0
m_VelocityDamping: 1
m_VelocityScale: 1
m_AngularVelocityDamping: 1
m_AngularVelocityScale: 1
m_TrackPosition: 1
m_SmoothPosition: 1
m_SmoothPositionAmount: 1.34
m_TightenPosition: 0.068
m_TrackRotation: 1
m_SmoothRotation: 1
m_SmoothRotationAmount: 1.57
m_TightenRotation: 0.077
m_TrackScale: 1
m_SmoothScale: 0
m_SmoothScaleAmount: 8
m_TightenScale: 0.1
m_ThrowOnDetach: 1
m_ThrowSmoothingDuration: 0.25
m_ThrowSmoothingCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 1
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
m_ThrowVelocityScale: 1.5
m_ThrowAngularVelocityScale: 1
m_ForceGravityOnDetach: 0
m_RetainTransformParent: 1
m_StartingSingleGrabTransformers: []
m_StartingMultipleGrabTransformers: []
m_AddDefaultGrabTransformers: 1
m_FarAttachMode: 0
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ PrefabInstance:
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_SizeDelta.x
value: 0
value: 30
objectReference: {fileID: 0}
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_SizeDelta.y
value: 0
value: 40
objectReference: {fileID: 0}
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
value: 53
objectReference: {fileID: 0}
- target: {fileID: 2111886246478503278, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
value: -22.5
objectReference: {fileID: 0}
- target: {fileID: 2642065777872049631, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
Expand Down Expand Up @@ -183,6 +183,41 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_SizeDelta.x
value: 30
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_SizeDelta.y
value: 40
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 21
objectReference: {fileID: 0}
- target: {fileID: 5293975139575421772, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -22.5
objectReference: {fileID: 0}
- target: {fileID: 7451063533619258403, guid: 46c1f5d5a11cf5042886aabd56e7b9d7,
type: 3}
propertyPath: grabbable
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
Expand Down
14 changes: 8 additions & 6 deletions Unity/Assets/Ubiq/Samples/Demo (XRI)/Assets/Scripts/Firework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ private void Start()
context = NetworkScene.Register(this);

var grab = GetComponent<XRGrabInteractable>();
grab.activated.AddListener(XRGrabInteractable_Activated);
grab.selectExited.AddListener(Interactable_SelectExited);
}

public void XRGrabInteractable_Activated(ActivateEventArgs eventArgs)
private void Interactable_SelectExited(SelectExitEventArgs eventArgs)
{
if (fired)
{
return;
}

fired = true;

flightForce = new Vector3(
Expand All @@ -53,12 +58,9 @@ public void XRGrabInteractable_Activated(ActivateEventArgs eventArgs)
z:(Random.value - 0.5f)*0.2f);
explodeTime = Time.time + 10.0f;

// Force the interactor(hand) to drop the firework
var interactor = (XRBaseInteractor)eventArgs.interactorObject;
interactor.allowSelect = false;
// No longer interactable
var interactable = (XRGrabInteractable)eventArgs.interactableObject;
interactable.enabled = false;
interactor.allowSelect = true;
}

private void Update()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,30 @@ namespace Ubiq.Samples
/// grasped and moved around, but note that the Box itself is *not* network
/// enabled. Each player has their own copy.
/// </summary>
[RequireComponent(typeof(Rigidbody))]
public class FireworksBox : MonoBehaviour
{
public GameObject fireworkPrefab;

#if XRI_3_0_7_OR_NEWER
private NetworkSpawnManager spawnManager;
private XRGrabInteractable interactable;
private XRSimpleInteractable interactable;
private XRInteractionManager interactionManager;

private void Start()
{
spawnManager = NetworkSpawnManager.Find(this);
interactable = GetComponent<XRGrabInteractable>();
interactable = GetComponent<XRSimpleInteractable>();
interactionManager = interactable.interactionManager;

interactable.activated.AddListener(XRGrabInteractable_Activated);
interactable.selectEntered.AddListener(XRGrabInteractable_SelectEntered);
}

private void OnDestroy()
{
interactable.activated.RemoveListener(XRGrabInteractable_Activated);
interactable.selectEntered.RemoveListener(XRGrabInteractable_SelectEntered);
}

public void XRGrabInteractable_Activated(ActivateEventArgs eventArgs)
private void XRGrabInteractable_SelectEntered(SelectEnterEventArgs eventArgs)
{
var go = spawnManager.SpawnWithPeerScope(fireworkPrefab);
var firework = go.GetComponent<Firework>();
Expand All @@ -53,8 +52,8 @@ public void XRGrabInteractable_Activated(ActivateEventArgs eventArgs)
return;
}

// Force the interactor(hand) to drop the box and grab the firework
var selectInteractor = eventArgs.interactorObject as IXRSelectInteractor;
// Force the interactor(hand) to stop selecting the box and select the firework
var selectInteractor = eventArgs.interactorObject;
if (selectInteractor != null)
{
interactionManager.SelectExit(
Expand Down
Loading

0 comments on commit 1049c4d

Please sign in to comment.