Skip to content

Instantly share code, notes, and snippets.

@pana-cc
Created November 15, 2020 11:39
Show Gist options
  • Save pana-cc/7069334607d17880f302e8d3e809919e to your computer and use it in GitHub Desktop.
Save pana-cc/7069334607d17880f302e8d3e809919e to your computer and use it in GitHub Desktop.
Quest Settings
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Android;
using UnityEngine.XR;
public class QuestSettings : MonoBehaviour
{
#if PLATFORM_ANDROID
public void Awake()
{
if (!XRSettings.loadedDeviceName.ToLowerInvariant().Contains("quest"))
{
return;
}
ApplyOVRSettings();
}
public void Start()
{
if (Permission.HasUserAuthorizedPermission(Permission.Microphone))
{
// The user authorized use of the microphone.
}
else
{
// We do not have permission to use the microphone.
// Ask for permission or proceed without the functionality enabled.
Permission.RequestUserPermission(Permission.Microphone);
}
}
#endif
private static void ApplyOVRSettings()
{
try
{
OVRPlugin.ovrp_SetTiledMultiResDynamic(Bool.False);
XRSettings.eyeTextureResolutionScale = 1.25f;
XRSettings.renderViewportScale = 1f;
OVRPlugin.ovrp_SetSystemDisplayFrequency(72f);
QualitySettings.antiAliasing = 4;
OVRPlugin.ovrp_SetTiledMultiResLevel(FixedFoveatedRenderingLevel.HighTop);
}
catch
{
Debug.Log("Failed applying all OVRPlugin settings.");
}
}
private static class OVRPlugin
{
private const string pluginName = "OVRPlugin";
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Result ovrp_SetSystemDisplayFrequency(float requestedFrequency);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Result ovrp_SetTiledMultiResDynamic(Bool isDynamic);
[DllImport(pluginName, CallingConvention = CallingConvention.Cdecl)]
public static extern Result ovrp_SetTiledMultiResLevel(FixedFoveatedRenderingLevel level);
}
public enum Bool
{
False = 0,
True
}
private enum Result
{
/// Success
Success = 0,
/// Failure
Failure = -1000,
Failure_InvalidParameter = -1001,
Failure_NotInitialized = -1002,
Failure_InvalidOperation = -1003,
Failure_Unsupported = -1004,
Failure_NotYetImplemented = -1005,
Failure_OperationFailed = -1006,
Failure_InsufficientSize = -1007,
}
public enum FixedFoveatedRenderingLevel
{
Off = 0,
Low = 1,
Medium = 2,
High = 3,
// High foveation setting with more detail toward the bottom of the view and more foveation near the top (Same as High on Oculus Go)
HighTop = 4,
EnumSize = 0x7FFFFFFF
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment