• QQ
  • nahooten@sina.com
  • 常州市九洲新世界花苑15-2

游戏开发

使用HoloToolKit实现导航手势旋转3D模型

原创内容,转载请注明原文网址:http://homeqin.cn/a/wenzhangboke/jishutiandi/youxikaifa/2018/1101/150.html

使用HoloToolKit实现导航手势旋转3D模型

我们常州手机App游戏开发培训专家幻天网络近来发现,Hololens官方教程 Holograms 211中的示例是,通过GestureManager.cs和HandsManager.cs来实现手势事件。但在最近的HTK中,这两个脚本被删除了。现在HoloToolKit使用的手势事件机制是通过接口来实现。
HoloToolKit提供的接口有:
  • IHoldHandler - 实现hold手势的接口
  • IInputClickHandler - 实现click手势的接口
  • IInputHandler - 实现pointer-like手势的接口
  • IManipulationHandler - 实现manipulation手势的接口
  • INavigationHandler - 实现navigation手势的接口
  • ISourceStateHandler - 实现检测输入源状态的接口,如手势检测或者丢失
  • ISpeechHandler - 实现语音识别的接口
通过接口的方式来定义对应手势的事件,要比原有的GestureManager.cs和HandsManager.cs方便许多。
以下是实现手势旋转的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Unity.InputModule;

public class GestureController : MonoBehaviour, INavigationHandler
{
    public float rotationSensitivity = 10.0f;

    private Vector3 manipulationPreviousPostion;
    private float rotationFactor;

    public void OnNavigationStarted(NavigationEventData eventData)
    {

    }
    //手势旋转物体。
    public void OnNavigationUpdated(NavigationEventData eventData)
    {
        //Calculate rotationFactor based on eventData.CumulativeDelta.x and multiply by rotationSensitivity.
        rotationFactor = eventData.CumulativeDelta.x * rotationSensitivity;

        //transform.Rotate along the Y axis using rotationFactor.
        transform.Rotate(new Vector3(0, -1 * rotationFactor, 0));
    }

    public void OnNavigationCompleted(NavigationEventData eventData)
    {

    }

    public void OnNavigationCanceled(NavigationEventData eventData)
    {

    }

}
以上代码通过实现INavigation接口,实现了通过手势旋转物体。
如果需要定制其他手势的事件,只需要实现响应的接口即可。
也可以参考HoloToolKit/Input/Tests/InputManagerTest场景中的示例。


上篇:上一篇:使用CanvasGroup实现渐隐渐显效果
下篇:下一篇:DontDestroyOnLoad的使用