没什么可说的,直接上代码。不明白的可以 加群【VR/AR独立开发者】:579825973
using HoloToolkit.Unity.InputModule;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class ObjectRotation : MonoBehaviour,
IInputHandler,
INavigationHandler
{
private GameObject FocusedGameObject;
private bool IsNavigating = false;
public Vector3 NavigationPosition { get; private set; }
public float RotationSensitivity = 10.0f;
private float rotationFactorX;
private float rotationFactorY;
private float rotationFactorZ;
void Update()
{
PerformRotation();
}
private void PerformRotation()
{
if (FocusedGameObject != null && IsNavigating)
{
rotationFactorX = NavigationPosition.x * RotationSensitivity;
transform.Rotate(new Vector3(0, -1 * rotationFactorX, 0));
}
}
public void OnInputDown(InputEventData eventData)
{
FocusedGameObject = gameObject;
}
public void OnInputUp(InputEventData eventData)
{
FocusedGameObject = null;
}
public void OnNavigationStarted(NavigationEventData eventData)
{
IsNavigating = true;
NavigationPosition = eventData.CumulativeDelta;
}
public void OnNavigationUpdated(NavigationEventData eventData)
{
IsNavigating = true;
NavigationPosition = eventData.CumulativeDelta;
}
public void OnNavigationCompleted(NavigationEventData eventData)
{
IsNavigating = false;
}
public void OnNavigationCanceled(NavigationEventData eventData)
{
IsNavigating = false;
}
}