02-23-2022 11:05 AM
I want to make a multiplayer expirience in VR with unity and I want to use de meta avatars SDK but I can't find a guide on how to do it, and I think is because I don't have to much expirience in networking but the documentation doesn't help me. I can use them locally very easily but for multiplayer I have no idea on how to implement this.
Just to add that is no like I don't know anything about multiplayer, I actually have a VR multiplayer proyect and it works perfect, is just that I want to have the meta avatars instead of custom made avatars because is so much work to do my own avatar system.
Hope sombody can help me with a guide or something to study how to do it! :c
09-19-2022 11:26 PM - edited 09-19-2022 11:27 PM
I've heard good things about this Unity asset: https://assetstore.unity.com/packages/tools/network/meta-avatars-pun2-vr-multiplayer-template-211918
06-10-2023 04:22 AM - edited 06-10-2023 04:23 AM
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
}