Created
November 11, 2017 02:50
-
-
Save TakahiroMiyaura/cd001cbe6c31f4ac7b7a026f78a0e1fc to your computer and use it in GitHub Desktop.
WinMRで始めるMixed Reality Toolkit Unity - モーションコントローラの基本的な実装 ref: http://qiita.com/miyaura/items/12d00950fb42eb36ada5
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
#if UNITY_WSA && UNITY_2017_2_OR_NEWER | |
... | |
#endif |
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
InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected; | |
InteractionManager.InteractionSourceLost += InteractionManager_InteractionSourceLost; | |
InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated; |
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
// Copyright(c) 2017 Takahiro Miyaura | |
// Released under the MIT license | |
// http://opensource.org/licenses/mit-license.php | |
private void InteractionManager_InteractionSourceDetected(InteractionSourceDetectedEventArgs obj) | |
{ | |
//入力ソースの種類を取得 | |
InteractionSourceKind kind = obj.state.source.kind; | |
//検出時の入力ソースのID(消失するまで同じID) | |
var id = obj.state.source.id | |
} |
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
// Copyright(c) 2017 Takahiro Miyaura | |
// Released under the MIT license | |
// http://opensource.org/licenses/mit-license.php | |
private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj) | |
{ | |
var state = obj.state; | |
if (state.source.kind == InteractionSourceKind.Controller) | |
{ | |
Vector3 PointerPosition; | |
Quaternion PointerRotation; | |
Vector3 GripPosition; | |
Quaternion GripRotation; | |
//コントローラのポインタの情報を取得 | |
state.sourcePose.TryGetPosition(out PointerPosition, InteractionSourceNode.Pointer); | |
state.sourcePose.TryGetRotation(out PointerRotation, InteractionSourceNode.Pointer); | |
//コントローラ本体の情報を取得 | |
state.sourcePose.TryGetPosition(out GripPosition, InteractionSourceNode.Grip); | |
state.sourcePose.TryGetRotation(out GripRotation, InteractionSourceNode.Grip); | |
//グリップ上にあるボタンが押されているか | |
bool Grasped = state.grasped; | |
//メニューボタンが押下されているか | |
bool MenuPressed = state.menuPressed; | |
//Selectボタン(トリガー状のボタン)が押下されているか | |
bool SelectPressed = state.selectPressed; | |
//Selectボタンがどの程度押されているか(0~1) | |
float SelectPressedAmount = state.selectPressedAmount; | |
//親指スティックが押されているか | |
bool ThumbstickPressed = state.thumbstickPressed; | |
//親指スティックのXY座標(-1~1) | |
Vector3 ThumbstickPosition = state.thumbstickPosition; | |
//タッチパッドが押されているか | |
bool TouchpadPressed = state.touchpadPressed; | |
//タッチパッドに触れているか | |
bool TouchpadTouched = state.touchpadTouched; | |
//タッチパッドのXY座標(-1~1) | |
Vector3 TouchpadPosition = state.touchpadPosition; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment