|
|
@@ -0,0 +1,68 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+using UnityEngine.SceneManagement;
|
|
|
+
|
|
|
+/*
|
|
|
+模拟鼠标控制器
|
|
|
+主要负责自动开关模拟鼠标
|
|
|
+在蓝牙正常连接状态下,非游戏界面自动开启模拟鼠标,游戏界面自动关闭模拟鼠标。
|
|
|
+*/
|
|
|
+public class SimulateMouseController
|
|
|
+{
|
|
|
+ public static SimulateMouseController ins;
|
|
|
+
|
|
|
+ public static void Init() {
|
|
|
+ ins = new SimulateMouseController();
|
|
|
+ SceneManager.sceneLoaded += (scene, mode) => {
|
|
|
+ ins.AddOpenLocker("NotGame");
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ bool bleConnected = false;
|
|
|
+
|
|
|
+ //有locker就要保持鼠标开启状态
|
|
|
+ HashSet<object> openLockerSet = new HashSet<object>();
|
|
|
+
|
|
|
+ public void AddOpenLocker(object locker) {
|
|
|
+ openLockerSet.Add(locker);
|
|
|
+ CheckAndOpenOrClose();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void RemoveOpenLocker(object locker) {
|
|
|
+ openLockerSet.Remove(locker);
|
|
|
+ CheckAndOpenOrClose();
|
|
|
+ }
|
|
|
+
|
|
|
+ //蓝牙是否处于连接状态
|
|
|
+ public void SetBleConnected(bool connected) {
|
|
|
+ bleConnected = connected;
|
|
|
+ CheckAndOpenOrClose();
|
|
|
+ }
|
|
|
+
|
|
|
+ //检测和改变开关
|
|
|
+ void CheckAndOpenOrClose() {
|
|
|
+ if (bleConnected) {
|
|
|
+ if (openLockerSet.Count > 0) {
|
|
|
+ Open();
|
|
|
+ } else {
|
|
|
+ Close();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void Open() {
|
|
|
+ if (SB_EventSystem.ins && !SB_EventSystem.ins.simulateMouseIsAwaked) {
|
|
|
+ SB_EventSystem.ins.AwakenSimulateMouse();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void Close() {
|
|
|
+ if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked) {
|
|
|
+ SB_EventSystem.ins.AwakenSimulateMouse();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|