-
Notifications
You must be signed in to change notification settings - Fork 0
/
XRInitializer.cs
63 lines (54 loc) · 1.57 KB
/
XRInitializer.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.XR;
public class XRInitializer : MonoBehaviour
{
enum AA
{
None,
MSAA2x = 2,
MSAA4x = 4,
MSAA8x = 8
}
[SerializeField, Header("Common")] AA antiAliasing = AA.MSAA4x;
[SerializeField, Header("For PC based VR")] TrackingSpaceType trackingSpace = TrackingSpaceType.RoomScale;
[SerializeField, Range(1f, 1.5f)] float resolutionScale = 1.2f;
[SerializeField, Header("For Oculus Go / Gear VR")] bool nativeResolutionScale = true;
[SerializeField] bool setFramerateTo72 = true;
void Reset()
{
#if UNITY_EDITOR
PlayerSettings.virtualRealitySupported = true;
PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.HiddenByDefault;
PlayerSettings.forceSingleInstance = true;
PlayerSettings.stereoRenderingPath = StereoRenderingPath.SinglePass;
PlayerSettings.SetVirtualRealitySDKs(BuildTargetGroup.Android, new[] {"Oculus"});
if (Camera.main != null) Camera.main.nearClipPlane = 0.01f;
#endif
Apply();
}
void Start()
{
Apply();
}
void OnValidate()
{
Apply();
}
void Apply()
{
QualitySettings.antiAliasing = (int) antiAliasing;
#if UNITY_STANDALONE
XRDevice.SetTrackingSpaceType(trackingSpace);
XRSettings.eyeTextureResolutionScale = resolutionScale;
#elif UNITY_ANDROID
XRSettings.eyeTextureResolutionScale = nativeResolutionScale ? 1.25f : 1f;
OVRManager.tiledMultiResLevel = OVRManager.TiledMultiResLevel.LMSHigh;
#endif
#if UNITY_ANDROID && !UNITY_EDITOR
OVRManager.display.displayFrequency = setFramerateTo72 ? 72f : 60f;
#endif
}
}