Skip to content

Instantly share code, notes, and snippets.

@vrobel
Last active April 14, 2024 23:50
Show Gist options
  • Save vrobel/7af0e513e06a969bd6ef4f157a9994c3 to your computer and use it in GitHub Desktop.
Save vrobel/7af0e513e06a969bd6ef4f157a9994c3 to your computer and use it in GitHub Desktop.
Helps to record Normcore sessions along with RealtimeSessionCapture (to be deprecated) that is bundled with Normcore. Script creates a mirror client that receives from the host data that might not recorded locally, or are not available at the moment of recording (scene view models). To record: Add RealtimeSessionCapture, set mode to Record, add …
using System;
using System.Collections;
using Normal.Realtime;
using UnityEngine;
namespace Network
{
[RequireComponent(typeof(Realtime))]
public class RealtimeSessionCaptureDouble : MonoBehaviour
{
private Realtime _realtime;
private Coroutine _recordingCoroutine;
private SessionCapture _sessionCaptureDouble;
private Room _roomDouble;
private void Awake()
{
_realtime = GetComponent<Realtime>();
_realtime.didConnectToRoom += RealtimeOnDidConnectToRoom;
}
private void RealtimeOnDidConnectToRoom(Realtime realtime)
{
if (enabled)
{
_recordingCoroutine = StartCoroutine(RecordRealtime());
}
}
private void OnEnable()
{
if (_realtime.connected)
{
_recordingCoroutine = StartCoroutine(RecordRealtime());
}
}
private void OnDisable()
{
if (_recordingCoroutine != null) StopCoroutine(_recordingCoroutine);
Dispose();
}
private IEnumerator RecordRealtime()
{
var folderPath = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"Normal\\SessionCapture");
var fileNameDouble = "Session_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_double.realtime";
System.IO.Directory.CreateDirectory(folderPath);
var recordDoubleFilePath = System.IO.Path.Combine(folderPath, fileNameDouble);
Debug.Log("Record file path: " + recordDoubleFilePath);
_sessionCaptureDouble = new SessionCapture(recordDoubleFilePath);
_roomDouble = new Room(_sessionCaptureDouble);
_roomDouble.Connect(_realtime.room.name,
new Room.ConnectOptions
{
appKey = _realtime.normcoreAppSettings.normcoreAppKey,
matcherURL = _realtime.normcoreAppSettings.matcherURL
});
do
{
yield return null;
_roomDouble.Tick(Time.deltaTime);
} while (_realtime.connected && (_roomDouble.connected || _roomDouble.connecting));
Dispose();
}
private void Dispose()
{
if (_sessionCaptureDouble != null)
{
_sessionCaptureDouble.StopRecording();
_sessionCaptureDouble = null;
}
if (_roomDouble != null)
{
_roomDouble.Disconnect();
_roomDouble.Dispose();
_roomDouble = null;
}
enabled = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment