Skip to content

Commit e2f0928

Browse files
update samples
1 parent a760a42 commit e2f0928

File tree

4 files changed

+54
-18
lines changed

4 files changed

+54
-18
lines changed

Assets/Scenes/WebRTC-SingleClient-STUNConnection-ImmersiveSpectator-Receiver.unity

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,7 +2846,7 @@ MonoBehaviour:
28462846
ShowLogs: 1
28472847
ShowDataChannelLogs: 1
28482848
UseImmersiveSetup: 1
2849-
experimentalSupportFor6DOF: 1
2849+
experimentalSupportFor6DOF: 0
28502850
experimentalSpectatorCam6DOF: {fileID: 330585546}
28512851
RenderStereo: 0
28522852
StereoSeparation: 0.064
@@ -3992,10 +3992,10 @@ MonoBehaviour:
39923992
m_EditorClassIdentifier:
39933993
webRTCConnection: {fileID: 1200952470}
39943994
cameraSwitchKeyword: switch
3995-
manualPositionSwitch: 0
3996-
webRTCPositionSwitch: 0
39973995
cameraParentObjects: []
3998-
enableSendingPosition: 1
3996+
webRTCStartStopVideoStream: 0
3997+
webRTCPositionSwitch: 0
3998+
syncCameraPosition: 0
39993999
sendingIntervalInSeconds: 0.1
40004000
--- !u!114 &1988037981
40014001
MonoBehaviour:

Assets/Scenes/WebRTC-SingleClient-STUNConnection-ImmersiveSpectator-Sender.unity

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,15 +3258,15 @@ MonoBehaviour:
32583258
m_EditorClassIdentifier:
32593259
webRTCConnection: {fileID: 8671471656396631584}
32603260
cameraSwitchKeyword: switch
3261-
manualPositionSwitch: 0
3262-
webRTCPositionSwitch: 0
32633261
cameraParentObjects:
32643262
- {fileID: 1144258514}
32653263
- {fileID: 618052858}
32663264
- {fileID: 899997393}
32673265
- {fileID: 1269449386}
32683266
- {fileID: 1385173107}
3269-
enableSendingPosition: 0
3267+
webRTCStartStopVideoStream: 0
3268+
webRTCPositionSwitch: 0
3269+
syncCameraPosition: 0
32703270
sendingIntervalInSeconds: 0.1
32713271
--- !u!114 &1988037981
32723272
MonoBehaviour:

Assets/Settings/UniversalRenderPipelineGlobalSettings.asset

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ MonoBehaviour:
7373
- rid: 6852985685364965394
7474
- rid: 8712630790384254976
7575
- rid: 801588446733008896
76-
- rid: 7556929790737121281
77-
- rid: 7556929790737121282
7876
- rid: 7556929790737121284
7977
m_AssetVersion: 8
8078
m_ObsoleteDefaultVolumeProfile: {fileID: 0}

Assets/SimpleWebRTC/Runtime/Scripts/Utils/SwitchToNextCameraPosition.cs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,65 @@
1+
using System.Globalization;
12
using UnityEngine;
23

34
namespace SimpleWebRTC {
45
public class SwitchToNextCameraPosition : MonoBehaviour {
56

67
[SerializeField] private WebRTCConnection webRTCConnection;
78
[SerializeField] private string cameraSwitchKeyword = "switch";
8-
[SerializeField] private bool manualPositionSwitch = false;
9-
[SerializeField] private bool webRTCPositionSwitch = false;
109
[SerializeField] private Transform[] cameraParentObjects;
10+
[Header("Trigger video streaming on sender")]
11+
[SerializeField] private bool webRTCStartStopVideoStream = false;
12+
[Header("Trigger camera switch from receiver")]
13+
[SerializeField] private bool webRTCPositionSwitch = false;
1114
[Header("Sending Camera Position to Sender")]
12-
[SerializeField] private bool enableSendingPosition = false;
15+
[SerializeField] private bool syncCameraPosition = false;
1316
[SerializeField] private float sendingIntervalInSeconds = 0.1f;
1417

1518
private int cameraPositionCounter = 0;
1619
private float sendingIntervalCounter = 0;
1720

21+
// make sure the float decimal separator is converted correctly
22+
private NumberFormatInfo numberFormatInfo = new NumberFormatInfo { NumberDecimalSeparator = "." };
23+
1824
private void Start() {
25+
webRTCConnection.Connect();
26+
1927
if (webRTCConnection.IsImmersiveSetupActive && cameraParentObjects.Length > 0) {
2028
webRTCConnection.VideoStreamingCamera.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
2129
webRTCConnection.VideoStreamingCamera.transform.SetParent(cameraParentObjects[cameraPositionCounter], false);
2230
}
2331
}
2432

2533
private void Update() {
26-
if (manualPositionSwitch) {
27-
manualPositionSwitch = false;
28-
OnMessageReceived(cameraSwitchKeyword);
34+
// example: use the input system keyboard for starting/stopping the video stream
35+
//if (Keyboard.current.vKey.wasPressedThisFrame) {
36+
// webRTCConnection.StartVideoTransmission();
37+
//}
38+
//if (Keyboard.current.bKey.wasPressedThisFrame) {
39+
// webRTCConnection.StopVideoTransmission();
40+
//}
41+
42+
// example: use the OVR input for sending the camera switch
43+
//if (OVRInput.Get(OVRInput.Button.Start)) {
44+
// webRTCConnection.SendDataChannelMessage(cameraSwitchKeyword);
45+
//}
46+
47+
// use the boolean flag for starting/stopping the camera stream
48+
if (webRTCStartStopVideoStream && webRTCConnection.IsSender && webRTCConnection.IsWebRTCActive) {
49+
webRTCStartStopVideoStream = false;
50+
if (webRTCConnection.IsVideoTransmissionActive) {
51+
webRTCConnection.StopVideoTransmission();
52+
} else {
53+
webRTCConnection.StartVideoTransmission();
54+
}
2955
}
30-
if (webRTCPositionSwitch && webRTCConnection.IsWebRTCActive) {
56+
57+
// use the boolean flag for sending the camera switch
58+
if (webRTCPositionSwitch && webRTCConnection.IsWebRTCActive && webRTCConnection.IsReceiver) {
3159
webRTCPositionSwitch = false;
3260
webRTCConnection.SendDataChannelMessage(cameraSwitchKeyword);
3361
}
34-
if (enableSendingPosition && webRTCConnection.IsWebRTCActive && webRTCConnection.IsImmersiveSetupActive && webRTCConnection.IsReceiver && webRTCConnection.ExperimentalSupportFor6DOF) {
62+
if (syncCameraPosition && webRTCConnection.IsWebRTCActive && webRTCConnection.IsImmersiveSetupActive && webRTCConnection.IsReceiver && webRTCConnection.ExperimentalSupportFor6DOF) {
3563
sendingIntervalCounter += Time.deltaTime;
3664
if (sendingIntervalCounter >= sendingIntervalInSeconds) {
3765
sendingIntervalCounter = 0;
@@ -40,12 +68,22 @@ private void Update() {
4068
}
4169
}
4270

71+
private void OnDestroy() {
72+
webRTCConnection.Disconnect();
73+
}
74+
4375
public void OnMessageReceived(string message) {
4476
if (webRTCConnection.IsImmersiveSetupActive && webRTCConnection.IsSender) {
4577
string[] trylocalPosition = message.Split("||||");
4678
bool isPositionMessage = trylocalPosition.Length == 3;
4779
if (webRTCConnection.ExperimentalSupportFor6DOF && isPositionMessage) {
48-
webRTCConnection.VideoStreamingCamera.transform.localPosition = new Vector3(float.Parse(trylocalPosition[0]), float.Parse(trylocalPosition[1]), float.Parse(trylocalPosition[2]));
80+
Debug.Log($"x = {trylocalPosition[0]} = {float.Parse(trylocalPosition[0], numberFormatInfo)}, y = {trylocalPosition[1]} = {float.Parse(trylocalPosition[1], numberFormatInfo)}, z = {trylocalPosition[2]} = {float.Parse(trylocalPosition[2], numberFormatInfo)}");
81+
82+
webRTCConnection.VideoStreamingCamera.transform.localPosition = new Vector3(
83+
float.Parse(trylocalPosition[0], numberFormatInfo),
84+
float.Parse(trylocalPosition[1], numberFormatInfo),
85+
float.Parse(trylocalPosition[2], numberFormatInfo));
86+
4987
} else if (message.ToLower().Equals(cameraSwitchKeyword.ToLower()) && cameraParentObjects.Length > 0) {
5088
cameraPositionCounter = (cameraPositionCounter + 1) % cameraParentObjects.Length;
5189
webRTCConnection.VideoStreamingCamera.transform.SetParent(cameraParentObjects[cameraPositionCounter], false);

0 commit comments

Comments
 (0)