Measure the strength of your left and right hand hand tracking.
Sample Repository
Run the sample
- Clone Sample Repository, Change current directory to
PinchStrength
. And Open with Unity. - (If you don't have NRSDK) Download NRSDK 1.8.0 from Download | Nreal
- Open
Build Setting
, change Platform toAndroid
- Open
Project
, selectAssets
>import package
>Custom Package
and importNRSDKForUnityAndroid_1.8.0.unitypackage
. - Check
Build Settings
>Player Settings
by referring to Configure Build Settings - Press
Build
formBuild Settings
panel - Install *.apk on Android or DevKit.
Tutorial
1. Setting up the project for Nreal development
- See Quickstart for Android - NRSDK Documentation and configure the build settings.
- (If you don't have NRSDK) Download NRSDK 1.8.0 from Download | Nreal
- Open
Project
, selectAssets
>import package
>Custom Package
and importNRSDKForUnityAndroid_1.8.0.unitypackage
.
2. Setting for HandTracking to NRInput
- Select
NRInput
, and changeInput Source Type
toHands
- Put
NRHand_R
fromAssets
>NRSDK
>Prefabs
>Hands
toNRInput
>Right
on the Scene. - Put
NRHand_L
fromAssets
>NRSDK
>Prefabs
>Hands
toNRInput
>Left
on the Scene.
3. Put a Canvas in the scene
- Put
Canvas
fromCreate
>UI
- Set property on
Inspector
panel-
Render Mode
: World Space -
Pos X
: 0 ,Pos Y
: -0.35Pos Z
: 3 -
Scale
-
X
: 0.005 ,Y
: 0.005 ,Z
: 0.005
-
-
4. Put Slider in Canvas
- Put
Slider
as a child ofCanvas
with the name "PinchStrengthBarRight”.- Set
Pos X
: 100,Pos Y
: 50,Pos Z
: 0 - Change the
Background
Color of the child ofPinchStrengthBarRight
to "#FF0000". - Change the
Fill Area
>Fill
Color of the child ofPinchStrengthBarRight
to "#00FF44". - Change the Rect Transform of
Fill Area
, SetLeft
ofRect Transform
to "0", and setRight
to "0" as well. - disable
Handle Slide Area
- Set
- Duplicate
PinchStrengthBarRight
- Change name to “PinchStrengthBarLeft”
- Set
Pos X
: -100,Pos Y
: 50,Pos Z
: 0
5. Create an empty GameObject and attach C# script to it.
- Create an empty GameObject on
Hierarchy
with the nameBaseGameObject
. - Create the following C# script named
PinchStrength
and attach it to the empty GameObject you just created.- Set
Pinch Strength Right Hand
onInspector
panel toPinchStrengthBarRight
on the scene. - Set
Pinch Strength Left Hand
onInspector
panel toPinchStrengthBarLeft
on the scene.
- Set
using NRKernal;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class PinchStrength : MonoBehaviour
{
/// <summary>
/// Pinch Strength Bar for Left Hand
/// </summary>
public Slider pinchStrengthLeftHand;
/// <summary>
/// Pinch Strength Bar for Right Hand
/// </summary>
public Slider pinchStrengthRightHand;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
HandState handStateRight = NRInput.Hands.GetHandState(HandEnum.RightHand);
float pinchStrengthRight = handStateRight.pinchStrength;
pinchStrengthRightHand.value = pinchStrengthRight;
HandState handStateLeft = NRInput.Hands.GetHandState(HandEnum.LeftHand);
float pinchStrengthLeft = handStateLeft.pinchStrength;
pinchStrengthLeftHand.value = pinchStrengthLeft;
}
}
6. Build
- Press
Build
formBuild Settings
panel - Install *.apk on Android or DevKit.
Top comments (0)