/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal { using UnityEngine; /// /// Oprate AR system state and handles the session lifecycle for application layer. [HelpURL("https://developer.nreal.ai/develop/discover/introduction-nrsdk")] [ScriptOrder(NativeConstants.NRSESSIONBEHAVIOUR_ORDER)] public class NRSessionBehaviour : SingletonBehaviour { /// LogVevel of NRSDK should be while release. [Tooltip("LogLevel of NRSDK.")] [SerializeField] LogLevel LogLevel = LogLevel.Info; /// The SessionConfig of nrsession. [Tooltip("A scriptable object specifying the NRSDK session configuration.")] [SerializeField] public NRSessionConfig SessionConfig; /// /// Base Awake method that sets the Singleton's unique instance. Called by Unity when /// initializing a MonoBehaviour. Scripts that extend Singleton should be sure to call /// base.Awake() to ensure the static Instance reference is properly created. new void Awake() { #if NRDEBUG NRDebugger.logLevel = LogLevel.All; #elif !UNITY_EDITOR NRDebugger.logLevel = Debug.isDebugBuild ? LogLevel.Debug : LogLevel; #else NRDebugger.logLevel = LogLevel; #endif Debug.LogFormat("[SessionBehaviour] Awake: logLevel={0}", NRDebugger.logLevel); base.Awake(); if (isDirty) return; NRDebugger.Info("[SessionBehaviour] Awake: CreateSession"); NRSessionManager.Instance.CreateSession(this); } /// Starts this object. void Start() { if (isDirty) return; NRDebugger.Info("[SessionBehaviour] Start: StartSession"); NRSessionManager.Instance.StartSession(); } /// Executes the 'application pause' action. /// True to pause. private void OnApplicationPause(bool pause) { if (isDirty) return; NRDebugger.Info("[SessionBehaviour] OnApplicationPause: {0}", pause); if (pause) { NRSessionManager.Instance.DisableSession(); } else { NRSessionManager.Instance.ResumeSession(); } } /// Executes the 'enable' action. void OnEnable() { if (isDirty) return; NRDebugger.Info("[SessionBehaviour] OnEnable: ResumeSession"); NRSessionManager.Instance.ResumeSession(); } /// Executes the 'disable' action. void OnDisable() { if (isDirty) return; NRDebugger.Info("[SessionBehaviour] OnDisable: DisableSession"); NRSessionManager.Instance.DisableSession(); } /// /// Base OnDestroy method that destroys the Singleton's unique instance. Called by Unity when /// destroying a MonoBehaviour. Scripts that extend Singleton should be sure to call /// base.OnDestroy() to ensure the underlying static Instance reference is properly cleaned up. new void OnDestroy() { if (isDirty) return; base.OnDestroy(); NRDebugger.Info("[SessionBehaviour] OnDestroy: DestroySession"); NRSessionManager.Instance.DestroySession(); } } }