|
@@ -26,6 +26,7 @@ public class PcWebCamera : MonoBehaviour
|
|
|
private void Awake()
|
|
private void Awake()
|
|
|
{
|
|
{
|
|
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
|
|
|
|
+ // SceneManager.sceneUnloaded += OnSceneUnloaded;
|
|
|
}
|
|
}
|
|
|
private IEnumerator Start()
|
|
private IEnumerator Start()
|
|
|
{
|
|
{
|
|
@@ -41,22 +42,30 @@ public class PcWebCamera : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
Debug.Log("Scene Loaded: " + scene.name);
|
|
Debug.Log("Scene Loaded: " + scene.name);
|
|
|
Debug.Log("Load Scene Mode: " + mode);
|
|
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()
|
|
IEnumerator RestartWebCam()
|
|
|
{
|
|
{
|
|
|
- yield return new WaitForSecondsRealtime(1); // 延迟 x 秒重启 WebCamTexture
|
|
|
|
|
|
|
+ //yield return new WaitForSecondsRealtime(1); // 延迟 x 秒重启 WebCamTexture
|
|
|
|
|
+ yield return new WaitForEndOfFrame();
|
|
|
if (_webCamTexture != null)
|
|
if (_webCamTexture != null)
|
|
|
{
|
|
{
|
|
|
- _webCamTexture.Stop();
|
|
|
|
|
|
|
+ //_webCamTexture.Stop();
|
|
|
_webCamTexture.Play();
|
|
_webCamTexture.Play();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -121,7 +130,9 @@ public class PcWebCamera : MonoBehaviour
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
deviceName = devices[cameraIndex].name;
|
|
deviceName = devices[cameraIndex].name;
|
|
|
- StartCoroutine(DetectResolutions());
|
|
|
|
|
|
|
+ //StartCoroutine(DetectResolutions());
|
|
|
|
|
+ StartWebCam(width, height);
|
|
|
|
|
+
|
|
|
//Debug.Log("PCWebCamera fps:" + fps + ",size:[" + width + "," + height + "]");
|
|
//Debug.Log("PCWebCamera fps:" + fps + ",size:[" + width + "," + height + "]");
|
|
|
//_webCamTexture = new WebCamTexture(deviceName, width, height, fps);
|
|
//_webCamTexture = new WebCamTexture(deviceName, width, height, fps);
|
|
|
//_webCamTexture.Play();
|
|
//_webCamTexture.Play();
|