Hololens手势控制物体旋转

自己做Demo有用到,简单记录一下

直接调用 INavigationHandler 接口,以下为完整代码,挂在要控制旋转的物体上即可

using HoloToolkit.Unity.InputModule;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjRotateController : MonoBehaviour, INavigationHandler
{
    public Transform mover;//需要旋转的对象
    public Vector3 startposition;//获取点击的初始位置
    public Vector3 navigationposition;//手指移动后的位置
    private float value = -1;

    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        
    }
    

    public void OnNavigationStarted(NavigationEventData eventData)
    {
        navigationposition = eventData.NormalizedOffset;
        startposition = navigationposition;        
    }

    public void OnNavigationUpdated(NavigationEventData eventData)
    {
        navigationposition = eventData.NormalizedOffset;
        if (Mathf.Abs(navigationposition.x) >= Mathf.Abs(navigationposition.y) && Mathf.Abs(navigationposition.x) >= Mathf.Abs(navigationposition.z))
        {
            mover.Rotate(0, value * navigationposition.x * 30, 0);
        }
    }

    public void OnNavigationCanceled(NavigationEventData eventData)
    {
        //Do Nothing
    }

    public void OnNavigationCompleted(NavigationEventData eventData)
    {
        //Do Nothing
    }
}

你可能感兴趣的:(Hololens相关)