Last active
July 21, 2020 02:34
-
-
Save yuujii/e878e1b0eb5bd7bb041b73eb4847712f to your computer and use it in GitHub Desktop.
Magic LeapのコントローラのTouchpadをスワイプするとTargetに設定したものを回転できるやつ #Unity #ML1
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; | |
using UnityEngine.XR.MagicLeap; | |
/// <summary> | |
/// Magic LeapのコントローラのTouchpadをスワイプするとTargetに設定したものを回転できるやつ | |
/// </summary> | |
public class MLTouchpadSwipeRotator : MonoBehaviour { | |
[SerializeField] | |
private Transform _target; | |
[SerializeField, Tooltip("ControllerConnectionHandler reference.")] | |
private ControllerConnectionHandler _controllerConnectionHandler; | |
[SerializeField] | |
private MLInputControllerFeedbackPatternVibe _vibePattern = | |
MLInputControllerFeedbackPatternVibe.ForceDown; | |
[SerializeField] | |
private MLInputControllerFeedbackIntensity _vibeIntensity = | |
MLInputControllerFeedbackIntensity.Medium; | |
float before_rotx = 0.0f; | |
void Start() | |
{ | |
if (_target == null) | |
_target = transform; | |
} | |
void Update() | |
{ | |
UpdatePaletteRotator(); | |
} | |
private void vibeFeedback() | |
{ | |
MLInputController controller = _controllerConnectionHandler.ConnectedController; | |
controller.StartFeedbackPatternVibe(_vibePattern, _vibeIntensity); | |
} | |
private void UpdatePaletteRotator() | |
{ | |
if (!_controllerConnectionHandler.IsControllerValid()) return; | |
if (_controllerConnectionHandler.ConnectedController !=MLInput.GetController(_controllerConnectionHandler.ConnectedController.Hand) ) | |
return; | |
MLInputController controller = _controllerConnectionHandler.ConnectedController; | |
if (controller.Touch1Active) | |
{ | |
float touchx = controller.Touch1PosAndForce.x; | |
if (Mathf.Approximately(before_rotx, 0.0f) || Mathf.Abs(before_rotx - touchx) <= 0.05f) | |
{ | |
before_rotx = touchx; | |
return; | |
} | |
transform.Rotate(Vector3.up, (before_rotx - touchx)*60f); | |
before_rotx = touchx; | |
vibeFeedback(); | |
} | |
else | |
{ | |
before_rotx = 0.0f; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment