04-12-2022 01:16 PM
Are you using Meta Avatars and Photon Fusion? I have seen sample projects using Photon Pun, but none that use Fusion. I have tried using the docs and adding Meta Avatars to my existing Fusion project, but everything stops compiling once I add the Oculus Integration Package. If you have samples or insights, it would be a huge help.
Thanks!
06-06-2023 02:18 AM
Here is a script I created for Meta Avatars + Photon Fusion, hope it helps:
using Fusion;
using UnityEngine;
using System.Collections.Generic;
using Oculus.Avatar2;
public class NetworkAvatar : NetworkBehaviour
{
[SerializeField] public OvrAvatarEntity Avatar;
[SerializeField] public bool isLocal = true;
private float cycleStartTime_Local = 0;
private float intervalToSendData_Local = 0.08f;
private List<byte[]> streamedDataList_Remote = new List<byte[]>();
void LateUpdate()
{
if (isLocal) LocalLateUpdate();
}
void Update()
{
if (!isLocal) RemoteUpdate();
}
#region Local Functions
private void LocalLateUpdate()
{
float elapsedTime = Time.time - cycleStartTime_Local;
if (elapsedTime <= intervalToSendData_Local) return;
RecordAndSendStreamData();
cycleStartTime_Local = Time.time;
}
void RecordAndSendStreamData()
{
byte[] bytes = Avatar.RecordStreamData(Avatar.activeStreamLod);
if (bytes == null) return;
RPC_ReceiveStreamData(bytes);
}
#endregion
#region Remote Functions
[Rpc(RpcSources.All, RpcTargets.All, InvokeLocal = false)]
public void RPC_ReceiveStreamData(byte[] bytes)
{
streamedDataList_Remote.Add(bytes);
}
private void RemoteUpdate()
{
if (streamedDataList_Remote.Count == 0) return;
byte[] firstBytesInList = streamedDataList_Remote[0];
if (firstBytesInList != null)
{
Avatar.ApplyStreamData(firstBytesInList);
}
streamedDataList_Remote.RemoveAt(0);
}
#endregion
}