Procházet zdrojové kódy

PC环境适配版本,红外版本需要合并到九轴版本

slambb před 1 měsícem
rodič
revize
49ec685814

+ 2 - 2
Assets/Game_Hyperspace/Script/ShootingEvent.cs

@@ -47,8 +47,8 @@ public class ShootingEvent : MonoBehaviour
         //if (limitAimInScrren) aimTransform.eulerAngles = LimitAngles(aimTransform.eulerAngles);
         //UpdateCrossHairPosition();
 #else
-        Vector3 pos = new Vector3(Input.mousePosition.x - Screen.width * 0.5f, Input.mousePosition.y - Screen.height * 0.5f, 0);
-        _rectTransform.localPosition = pos;
+        //Vector3 pos = new Vector3(Input.mousePosition.x - Screen.width * 0.5f, Input.mousePosition.y - Screen.height * 0.5f, 0);
+        //_rectTransform.localPosition = pos;
 #endif
     }
 

+ 20 - 9
Assets/InfraredProject/WebCamera/Script/PcWebCamera.cs

@@ -26,6 +26,7 @@ public class PcWebCamera : MonoBehaviour
     private void Awake()
     {
         SceneManager.sceneLoaded += OnSceneLoaded;
+       // SceneManager.sceneUnloaded += OnSceneUnloaded;
     }
     private IEnumerator Start()
     {
@@ -41,22 +42,30 @@ public class PcWebCamera : MonoBehaviour
     {
         Debug.Log("Scene Loaded: " + scene.name);
         Debug.Log("Load Scene Mode: " + mode);
+        StartCoroutine(RestartWebCam());
         // 在场景加载时执行的代码
-        if (BluetoothAim.ins && (BluetoothAim.ins.isMainConnectToInfraredDevice() || BluetoothAim.ins.isMainConnectToGun()))
+        //if (BluetoothAim.ins && (BluetoothAim.ins.isMainConnectToInfraredDevice() || BluetoothAim.ins.isMainConnectToGun()))
+        //{
+        //    StartCoroutine(RestartWebCam());
+        //}
+        //else if (scene.name == "Home") {
+        //    //没连接设备时候,如果跳回home页面,设置一次
+        //    StartCoroutine(RestartWebCam());
+        //}
+    }
+    void OnSceneUnloaded(Scene scene) {
+        if (_webCamTexture != null && _webCamTexture.isPlaying)
         {
-            StartCoroutine(RestartWebCam());
-        }
-        else if (scene.name == "Home") {
-            //没连接设备时候,如果跳回home页面,设置一次
-            StartCoroutine(RestartWebCam());
+            _webCamTexture.Stop();
         }
     }
     IEnumerator RestartWebCam()
     {
-        yield return new WaitForSecondsRealtime(1); // 延迟 x 秒重启 WebCamTexture
+        //yield return new WaitForSecondsRealtime(1); // 延迟 x 秒重启 WebCamTexture
+        yield return new WaitForEndOfFrame();
         if (_webCamTexture != null)
         {
-            _webCamTexture.Stop();
+            //_webCamTexture.Stop();
             _webCamTexture.Play();
         }
     }
@@ -121,7 +130,9 @@ public class PcWebCamera : MonoBehaviour
                 return;
             }
             deviceName = devices[cameraIndex].name;
-            StartCoroutine(DetectResolutions());
+            //StartCoroutine(DetectResolutions());
+            StartWebCam(width, height);
+
             //Debug.Log("PCWebCamera fps:" + fps + ",size:[" + width + "," + height + "]");
             //_webCamTexture = new WebCamTexture(deviceName, width, height, fps);
             //_webCamTexture.Play();