Unity GestureRecognizer ManipulationStarted和-updated无法正常工作

时间:2018-10-12 17:51:55

标签: unity3d hololens

请查看下面的代码,如果我在Unity for Hololens中将此结构用于Tap,Hold和Navigation,它会按预期工作。但是操纵甚至没有被召唤。我看了看Holokit,但我不明白holoKit是如何解雇他们的。我也不想在我的简单轻量项目中导入此繁重的Holokit。我真的很感激,任何人都可以告诉我如何使用一个简单的手势识别器操纵委托。

using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.XR.WSA.Input;

 namespace Assets.Scripts
 {
     public class GestureRecognizerManager : MonoBehaviour
     {
         private GestureRecognizer _recognizer;

         private void Awake()
         {
             _recognizer = new GestureRecognizer();

             _recognizer.ManipulationStarted += RecognizerOnManipulationStarted;
             _recognizer.ManipulationUpdated += RecognizerOnManipulationUpdated;

             _recognizer.StartCapturingGestures();
         }

         private void RecognizerOnManipulationUpdated(ManipulationUpdatedEventArgs obj)
         {
             Debug.Log("D");
         }

         private void RecognizerOnManipulationStarted(ManipulationStartedEventArgs obj)
         {
             Debug.Log("K");
         }        

         private void OnApplicationQuit()
         {
             _recognizer.ManipulationStarted -= RecognizerOnManipulationStarted;
             _recognizer.ManipulationUpdated -= RecognizerOnManipulationUpdated;

             _recognizer.StopCapturingGestures();
             _recognizer.Dispose();            
         }
     }
 }

1 个答案:

答案 0 :(得分:2)

好的,它在初始化阶段通过以下代码工作:

 _recognizer.SetRecognizableGestures(GestureSettings.ManipulationTranslate);