Skip to content

Instantly share code, notes, and snippets.

@bibinba
Created December 28, 2017 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bibinba/ad9393df7877e382228e1ed6d39b76f2 to your computer and use it in GitHub Desktop.
Save bibinba/ad9393df7877e382228e1ed6d39b76f2 to your computer and use it in GitHub Desktop.
MRTKでコントローラーのポジションをとって、VRコスプレのための手の位置にしたいけどできない
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
using System.Collections.Generic;
using UnityEngine.XR.WSA.Input;
#endif
namespace HoloToolkit.Unity
{
public class position : MonoBehaviour
{
public GameObject left;
public GameObject right;
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
private class ControllerState
{
public InteractionSourceHandedness Handedness;
public Vector3 GripPosition;
public Quaternion GripRotation;
}
private Dictionary<uint, ControllerState> controllers;
#endif
// Use this for initialization
private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
{
ControllerState controllerState;
var state = obj.state;
if (state.source.kind == InteractionSourceKind.Controller)
{
Vector3 GripPosition;
Quaternion GripRotation;
//コントローラ本体の情報を取得
state.sourcePose.TryGetPosition(out GripPosition, InteractionSourceNode.Grip);
state.sourcePose.TryGetRotation(out GripRotation, InteractionSourceNode.Grip);
if (controllerState.Handedness.Equals(InteractionSourceHandedness.Left))
{
left.transform.position = controllerState.GripPosition;
left.transform.rotation = controllerState.GripRotation;
}
else if (controllerState.Handedness.Equals(InteractionSourceHandedness.Right))
{
right.transform.position = controllerState.GripPosition;
right.transform.rotation = controllerState.GripRotation;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment