Skip to content

Commit

Permalink
BocchiTrackerSystem create component video capture module.
Browse files Browse the repository at this point in the history
  • Loading branch information
KirisameMarisa committed Feb 18, 2024
1 parent bc42042 commit c346505
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "BocchiTrackerPlugin",
"rootNamespace": "",
"references": [],
"references": [
"Unity.WebRTC"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public class BocchiTrackerSetting : MonoBehaviour
public int ServerPort => serverPort;

[SerializeField]
private Camera screenshotCamera = null;
public Camera ScreenshotCamera => screenshotCamera;

private Camera captureCamera = null;
public Camera CaptureCamera => captureCamera;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ public class BocchiTrackerSystem : MonoBehaviour
private bool isSentAppBasicInfo;
private Queue<object> pendingProcessRequest = new Queue<object>();

public BocchiTrackerSystem()
{
if (tcpSocket == null)
tcpSocket = new BocchiTrackerTcpSocket();
}

private void Awake()
{
if (logHook == null)
Expand All @@ -38,18 +32,16 @@ private void Awake()
private void Start()
{
setting = GetComponent<BocchiTrackerSetting>();
if(tcpSocket == null)
tcpSocket = gameObject.AddComponent<BocchiTrackerTcpSocket>();
tcpSocket = gameObject.AddComponent<BocchiTrackerTcpSocket>();
var video_capture = gameObject.AddComponent<BocchiTrackerVideoCapture>();
video_capture.ServerAddr = $"ws://{setting.ServerAddress}:{setting.ServerPort}";
video_capture.CaptureCamera = setting.CaptureCamera;

if (!IsConnect())
isSentAppBasicInfo = false;
tcpSocket.ReciveCallback = this.OnReceiveData;
}

private void OnDestroy()
{
tcpSocket.DisConnect();
}

private void Update()
{
if (IsConnect())
Expand Down Expand Up @@ -171,14 +163,14 @@ private IEnumerator ProcessSendScreenshot()

// Capture the screenshot
RenderTexture rt = new RenderTexture(screenWidth, screenHeight, 32);
RenderTexture prev_rt = setting.ScreenshotCamera.targetTexture;
Quaternion prev_rot = setting.ScreenshotCamera.transform.rotation;
RenderTexture prev_rt = setting.CaptureCamera.targetTexture;
Quaternion prev_rot = setting.CaptureCamera.transform.rotation;
Texture2D screenShot = new Texture2D(screenWidth, screenHeight, TextureFormat.RGBA32, false);

// Configure camera for screenshot
setting.ScreenshotCamera.targetTexture = rt;
setting.ScreenshotCamera.Render();
setting.ScreenshotCamera.targetTexture = prev_rt;
setting.CaptureCamera.targetTexture = rt;
setting.CaptureCamera.Render();
setting.CaptureCamera.targetTexture = prev_rt;

// Read and apply the screenshot data
RenderTexture.active = rt;
Expand Down

0 comments on commit c346505

Please sign in to comment.