HololensNavigation手势旋转对象

***************************************使用的是holotoolkit 5.5



直接调用Navigation接口,太简单了,不多说,直接上代码:

  


using UnityEngine;
using UnityEngine.EventSystems;
using HoloToolkit.Unity.InputModule;
    //手势轨迹旋转
    public class NavigationHandler : MonoBehaviour ,INavigationHandler
{
    public Transform mover;//需要旋转的对象
    public Vector3 startposition;//获取点击的初始位置
    public Vector3 navigationposition;//手指移动后的位置
    private float value = 1;
    
    //用Update()每帧数判断
    void Update()
    {
        if (Mathf.Abs(navigationposition.x) >= Mathf.Abs(navigationposition.y) && Mathf.Abs(navigationposition.x) >= Mathf.Abs(navigationposition.z))
        {
            
            mover.Rotate(0, value * navigationposition.x * 100, 0);
        }
    }
    public void OnNavigationStarted(NavigationEventData eventData)
     {
        navigationposition = eventData.CumulativeDelta;
        startposition = navigationposition;
     }
    
    public void OnNavigationUpdated(NavigationEventData eventData)
     {
        navigationposition = eventData.CumulativeDelta;
    }
 
     public void OnNavigationCompleted(NavigationEventData eventData)
     {
    
     }
   
     public void OnNavigationCanceled(NavigationEventData eventData)
     {
       
    }
}

你可能感兴趣的:(Hololens)