54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class InputHandler : MonoBehaviour, IGameComponent
|
|
{
|
|
private Controls inputSystem;
|
|
private Transform cameraTransform;
|
|
|
|
void Awake()
|
|
{
|
|
inputSystem = new Controls();
|
|
cameraTransform = transform;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
GameSystem.Instance.AddGameComponent(this);
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
inputSystem.Enable();
|
|
InputSystem.EnableDevice(UnityEngine.InputSystem.AttitudeSensor.current);
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
InputSystem.DisableDevice(UnityEngine.InputSystem.AttitudeSensor.current);
|
|
inputSystem.Disable();
|
|
}
|
|
|
|
public void OnUpdate()
|
|
{
|
|
var phoneRotation = inputSystem
|
|
.Rotation
|
|
.Gyroscope
|
|
.ReadValue<Quaternion>();
|
|
|
|
cameraTransform.rotation = phoneRotation;
|
|
cameraTransform.Rotate(0, 0, 180, Space.Self);
|
|
cameraTransform.Rotate(90, 180, 0, Space.World);
|
|
}
|
|
|
|
public void OnFixedUpdate() { }
|
|
public void OnLateUpdate() { }
|
|
|
|
public void OnDestroy()
|
|
{
|
|
GameSystem.Instance.RemoveGameComponent(this);
|
|
}
|
|
} |