Created
December 28, 2017 11:18
-
-
Save bibinba/ad9393df7877e382228e1ed6d39b76f2 to your computer and use it in GitHub Desktop.
MRTKでコントローラーのポジションをとって、VRコスプレのための手の位置にしたいけどできない
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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