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 Packageand importNRSDKForUnityAndroid_1.8.0.unitypackage. - Check
Build Settings>Player Settingsby referring to Configure Build Settings - Press
BuildformBuild Settingspanel - 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 Packageand importNRSDKForUnityAndroid_1.8.0.unitypackage.
2. Setting for HandTracking to NRInput
- Select
NRInput, and changeInput Source TypetoHands - Put
NRHand_RfromAssets>NRSDK>Prefabs>HandstoNRInput>Righton the Scene. - Put
NRHand_LfromAssets>NRSDK>Prefabs>HandstoNRInput>Lefton the Scene.
3. Put a Canvas in the scene
- Put
CanvasfromCreate>UI - Set property on
Inspectorpanel-
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
Slideras a child ofCanvaswith the name "PinchStrengthBarRight”.- Set
Pos X: 100,Pos Y: 50,Pos Z: 0 - Change the
BackgroundColor of the child ofPinchStrengthBarRightto "#FF0000". - Change the
Fill Area>FillColor of the child ofPinchStrengthBarRightto "#00FF44". - Change the Rect Transform of
Fill Area, SetLeftofRect Transformto "0", and setRightto "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
Hierarchywith the nameBaseGameObject. - Create the following C# script named
PinchStrengthand attach it to the empty GameObject you just created.- Set
Pinch Strength Right HandonInspectorpanel toPinchStrengthBarRighton the scene. - Set
Pinch Strength Left HandonInspectorpanel toPinchStrengthBarLefton 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
BuildformBuild Settingspanel - Install *.apk on Android or DevKit.

Top comments (0)