using System; using UnityEngine; namespace Oculus.Platform.Samples.EntitlementCheck { public class EntitlementCheck : MonoBehaviour { public bool exitAppOnFailure = true; public static event Action UserFailedEntitlementCheck; public static event Action UserPassedEntitlementCheck; private void Start() { try { if (!Core.IsInitialized()) { Core.Initialize(); } Entitlements.IsUserEntitledToApplication().OnComplete(EntitlementCheckCallback); } catch { HandleEntitlementCheckResult(false); } } private void EntitlementCheckCallback(Message msg) { HandleEntitlementCheckResult(!msg.IsError); } private void HandleEntitlementCheckResult(bool result) { if (result) { Debug.Log("Oculus user entitlement check successful."); try { if (EntitlementCheck.UserPassedEntitlementCheck != null) { EntitlementCheck.UserPassedEntitlementCheck(); } return; } catch { Debug.LogError("Suppressed exception in app-provided UserPassedEntitlementCheck() event handler."); return; } } try { if (EntitlementCheck.UserFailedEntitlementCheck != null) { EntitlementCheck.UserFailedEntitlementCheck(); } } catch { Debug.LogError("Suppressed exception in app-provided UserFailedEntitlementCheck() event handler."); } if (exitAppOnFailure) { Debug.LogError("Oculus user entitlement check failed. Exiting now."); UnityEngine.Application.Quit(); } else { Debug.LogError("Oculus user entitlement check failed."); } } } }