-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardboardModeMgr.cs
38 lines (33 loc) · 1.22 KB
/
CardboardModeMgr.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using System.Collections.Generic;
using UnityEngine.UI;
public class CardboardModeMgr : MonoBehaviour {
/**
* Precisamos da referência da camera
* é como recuperamos os componentes do Cardboard
**/
public GameObject mainCamera;
public void Start()
{
// Salva a preferencia do jogador para inicializar em VR Mode.
int doVR = PlayerPrefs.GetInt("VREnabled");
Cardboard.SDK.VRModeEnabled = doVR == 1;
CardboardHead head = mainCamera.GetComponent<CardboardHead>();
head.enabled = Cardboard.SDK.VRModeEnabled;
}
// Captura o evento do clique do botão e modifica a camera para VR mode.
public void ChangeCardboardMode ()
{
CardboardHead head = mainCamera.GetComponent<CardboardHead>();
if (Cardboard.SDK.VRModeEnabled) {
// Desabilita.
head.transform.localRotation = Quaternion.identity;
}
Cardboard.SDK.VRModeEnabled = !Cardboard.SDK.VRModeEnabled;
head.enabled = Cardboard.SDK.VRModeEnabled;
PlayerPrefs.SetInt("VREnabled", Cardboard.SDK.VRModeEnabled?1:0);
PlayerPrefs.Save();
}
}