public static void Initialize() { bool flag = !MainThreadDispather._initialized; if (flag && MainThreadDispather._threadId != -1 && MainThreadDispather._threadId != Thread.CurrentThread.ManagedThreadId) { return; } if (flag) { GameObject gameObject = new GameObject("MainThreadDispather"); gameObject.hideFlags = HideFlags.DontSave; UnityEngine.Object.DontDestroyOnLoad(gameObject); if (MainThreadDispather._current) { if (Application.isPlaying) { UnityEngine.Object.Destroy(MainThreadDispather._current.gameObject); } else { UnityEngine.Object.DestroyImmediate(MainThreadDispather._current.gameObject); } } MainThreadDispather._current = gameObject.AddComponent <MainThreadDispather>(); UnityEngine.Object.DontDestroyOnLoad(MainThreadDispather._current); MainThreadDispather._initialized = true; MainThreadDispather._threadId = Thread.CurrentThread.ManagedThreadId; } }
private static void OnGlassesDisconnectEvent(UInt64 glasses_control_handle, IntPtr user_data, GlassesDisconnectReason reason) { Debug.Log("[NRDevice] OnGlassesDisconnectEvent:" + reason.ToString()); switch (reason) { case GlassesDisconnectReason.GLASSES_DEVICE_DISCONNECT: CallAndroidkillProcess(); break; case GlassesDisconnectReason.NOTIFY_TO_QUIT_APP: if (NRFrame.SessionStatus == SessionState.Running) { // if current status is running , need release sdk in main thread. MainThreadDispather.QueueOnMainThread(() => { ForceKill(true); }); } else { ForceKill(false); } break; default: CallAndroidkillProcess(); break; } }
private static void OnGlassesWear(UInt64 glasses_control_handle, int wearing_status, UInt64 user_data) { Debug.Log("[NRDevice] " + (wearing_status == 1 ? "Glasses put on" : "Glasses put off")); MainThreadDispather.QueueOnMainThread(() => { OnGlassesStateChanged?.Invoke(wearing_status == 1 ? GlassesEventType.PutOn : GlassesEventType.PutOff); }); }
public static void OnDisplayResolutionChanged(int w, int h) { Debug.LogFormat("[NRVirtualDisplayer] Display resolution changed width:{0} height:{1}", w, h); MainThreadDispather.QueueOnMainThread(delegate() { NRVirtualDisplayer.Instance.UpdateResolution(new Vector2(w, h)); OnDisplayScreenChangedEvent?.Invoke(new Resolution() { width = w, height = h }); }); }
/// <summary> /// Init HMD device. /// </summary> public void Init() { if (m_IsInit || isGlassesPlugOut) { return; } NRTools.Init(); MainThreadDispather.Initialize(); #if UNITY_ANDROID && !UNITY_EDITOR // Init before all actions. AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); m_UnityActivity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity"); NativeApi.NRSDKInitSetAndroidActivity(m_UnityActivity.GetRawObject()); #endif CreateGlassesController(); CreateHMD(); m_IsInit = true; }
public static void QueueOnMainThread(Action action) { MainThreadDispather.QueueOnMainThread(action, 0f); }