Ported HUmanoidPlayerNetcode (untested)

This commit is contained in:
Pascal Serrarens 2024-03-18 12:22:52 +01:00
parent b46d2ce2ef
commit fcffefc794
3 changed files with 215 additions and 161 deletions

View File

@ -6,7 +6,7 @@ using UnityEngine;
namespace Passer.Humanoid { namespace Passer.Humanoid {
#pragma warning disable 0618 #pragma warning disable 0618
#if hNW_UNET || hNW_MIRROR || hNW_PHOTON || hNW_BOLT #if hNW_UNET || hNW_MIRROR || hNW_PHOTON || hNW_BOLT || hNETCODE
public partial class HumanoidPlayer { public partial class HumanoidPlayer {
[SerializeField] [SerializeField]

View File

@ -1,69 +1,113 @@
#if hNETCODE
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using Unity.Netcode;
using Unity.Netcode.Components;
namespace Passer.Humanoid { namespace Passer.Humanoid {
#if hNW_UNET
#pragma warning disable 0618 #pragma warning disable 0618
[RequireComponent(typeof(NetworkIdentity))] [RequireComponent(typeof(NetworkObject))]
public partial class HumanoidPlayer : PawnUnet, IHumanoidNetworking { public partial class HumanoidPlayer : NetworkBehaviour, IHumanoidNetworking {
// temporary (?) dummies
public void Send(bool b) { }
public void Send(byte b) { }
public void Send(int x) { }
public void Send(float f) { }
public void Send(Vector3 v) { }
public void Send(Quaternion q) { }
public bool ReceiveBool() {
return false;
}
public byte ReceiveByte() {
return 0;
}
public int ReceiveInt() {
return 0;
}
public float ReceiveFloat() {
return 0;
}
public Vector3 ReceiveVector3() {
return Vector3.zero;
}
public Quaternion ReceiveQuaternion() {
return Quaternion.identity;
}
// end temporary dummies
public ulong nwId { public ulong nwId {
get { return netId.Value; } get { return identity.objectIdentity; }
} }
[SerializeField]
protected float _sendRate = 25;
public float sendRate {
get { return _sendRate; }
}
public HumanoidNetworking.Smoothing smoothing => HumanoidNetworking.Smoothing.None;
public bool isLocal { get; set; }
public List<HumanoidControl> humanoids { get; set; } public List<HumanoidControl> humanoids { get; set; }
protected NetworkIdentity identity; protected NetworkObject identity;
public ulong GetObjectIdentity(GameObject obj) { public ulong GetObjectIdentity(GameObject obj) {
NetworkIdentity identity = obj.GetComponent<NetworkIdentity>(); NetworkObject identity = obj.GetComponent<NetworkObject>();
if (identity == null) if (identity == null)
return 0; return 0;
return identity.netId.Value; return identity.objectIdentity;
} }
public GameObject GetGameObject(ulong objIdentity) { public GameObject GetGameObject(ulong objIdentity) {
NetworkInstanceId netId = new NetworkInstanceId((uint)objIdentity); Unity.Netcode.NetworkObject nwObject = GetNetworkObject(objIdentity);
GameObject gameObject = ClientScene.FindLocalObject(netId); if (nwObject == null)
return null;
GameObject gameObject = nwObject.gameObject;
return gameObject; return gameObject;
} }
#region Init float lastSend;
override public void Awake() { [SerializeField]
DontDestroyOnLoad(this); protected bool _createLocalRemotes = false;
public bool createLocalRemotes {
identity = GetComponent<NetworkIdentity>(); get { return _createLocalRemotes; }
humanoids = new List<HumanoidControl>(); set { _createLocalRemotes = value; }
lastSend = Time.time;
} }
public override void OnStartClient() {
name = name + " " + netId; #region Init
public virtual void OnStartClient() {
//name = name + " " + netId;
//NetworkManager nwManager = FindObjectOfType<NetworkManager>(); //NetworkManager nwManager = FindObjectOfType<NetworkManager>();
//short msgType = MsgType.Highest + 2; //short msgType = MsgType.Highest + 2;
//nwManager.client.RegisterHandler(msgType, ClientProcessAvatarPose); //nwManager.client.RegisterHandler(msgType, ClientProcessAvatarPose);
if (identity.isServer) { // No idea how this works with Netcode
IHumanoidNetworking[] nwHumanoids = FindObjectsOfType<HumanoidPlayer>(); //if (identity.isServer) {
foreach (IHumanoidNetworking nwHumanoid in nwHumanoids) { // IHumanoidNetworking[] nwHumanoids = FindObjectsOfType<HumanoidPlayer>();
foreach (HumanoidControl humanoid in nwHumanoid.humanoids) { // foreach (IHumanoidNetworking nwHumanoid in nwHumanoids) {
if (humanoid.isRemote) // foreach (HumanoidControl humanoid in nwHumanoid.humanoids) {
continue; // if (humanoid.isRemote)
// continue;
DebugLog("Server Instantiate " + humanoid.nwId + " " + humanoid.humanoidId); // DebugLog("Server Instantiate " + humanoid.nwId + " " + humanoid.humanoidId);
((IHumanoidNetworking)this).InstantiateHumanoid(humanoid); // ((IHumanoidNetworking)this).InstantiateHumanoid(humanoid);
} // }
} // }
} //}
} }
public override void OnStartServer() { public virtual void OnStartServer() {
//short msgType = MsgType.Highest + 1; //short msgType = MsgType.Highest + 1;
//NetworkServer.RegisterHandler(msgType, ForwardAvatarPose); //NetworkServer.RegisterHandler(msgType, ForwardAvatarPose);
} }
@ -72,23 +116,23 @@ namespace Passer.Humanoid {
#region Start #region Start
public override void OnStartLocalPlayer() { public virtual void OnStartLocalPlayer() {
isLocal = true; isLocal = true;
name = "HumanoidPlayer(Local)"; name = "HumanoidPlayer(Local)";
humanoids = HumanoidNetworking.FindLocalHumanoids(); humanoids = HumanoidNetworking.FindLocalHumanoids();
if (debug <= PawnNetworking.DebugLevel.Info) if (debug <= HumanoidNetworking.DebugLevel.Info)
Debug.Log((int)netId.Value + ": Found " + humanoids.Count + " Humanoids"); Debug.Log((int)identity.objectIdentity + ": Found " + humanoids.Count + " Humanoids");
for (int i = 0; i < humanoids.Count; i++) { for (int i = 0; i < humanoids.Count; i++) {
HumanoidControl humanoid = humanoids[i]; HumanoidControl humanoid = humanoids[i];
if (humanoid.isRemote) if (humanoid.isRemote)
continue; continue;
humanoid.nwId = netId.Value; humanoid.nwId = identity.objectIdentity;
humanoid.humanoidNetworking = this; humanoid.humanoidNetworking = this;
if (debug <= PawnNetworking.DebugLevel.Info) if (debug <= HumanoidNetworking.DebugLevel.Info)
Debug.Log(humanoid.nwId + ": Send Start Humanoid " + humanoid.humanoidId); Debug.Log(humanoid.nwId + ": Send Start Humanoid " + humanoid.humanoidId);
((IHumanoidNetworking)this).InstantiateHumanoid(humanoid); ((IHumanoidNetworking)this).InstantiateHumanoid(humanoid);
@ -120,14 +164,14 @@ namespace Passer.Humanoid {
} }
protected virtual void Update() { protected virtual void Update() {
if (smoothing == PawnNetworking.Smoothing.Interpolation || if (smoothing == HumanoidNetworking.Smoothing.Interpolation ||
smoothing == PawnNetworking.Smoothing.Extrapolation) { smoothing == HumanoidNetworking.Smoothing.Extrapolation) {
HumanoidNetworking.SmoothUpdate(humanoids); HumanoidNetworking.SmoothUpdate(humanoids);
} }
} }
public override void LateUpdate() { public virtual void LateUpdate() {
if (Time.time > lastSend + 1 / sendRate) { if (Time.time > lastSend + 1 / sendRate) {
foreach (HumanoidControl humanoid in humanoids) { foreach (HumanoidControl humanoid in humanoids) {
if (!humanoid.isRemote) { if (!humanoid.isRemote) {
@ -145,8 +189,8 @@ namespace Passer.Humanoid {
#region Stop #region Stop
override public void OnDestroy() { override public void OnDestroy() {
if (debug <= PawnNetworking.DebugLevel.Info) if (debug <= HumanoidNetworking.DebugLevel.Info)
Debug.Log((int)netId.Value + ": Destroy Remote Humanoid"); Debug.Log((int)identity.objectIdentity + ": Destroy Remote Humanoid");
foreach (HumanoidControl humanoid in humanoids) { foreach (HumanoidControl humanoid in humanoids) {
if (humanoid == null) if (humanoid == null)
@ -160,74 +204,77 @@ namespace Passer.Humanoid {
humanoid.nwId = 0; humanoid.nwId = 0;
} }
} }
#endregion
protected virtual void SendToServer(NetworkIdentity identity, HumanoidNetworking.IMessage msg) { #endregion Stop
byte[] data = msg.Serialize();
short msgType = MsgType.Highest + 1; //protected virtual void SendToServer(NetworkObject identity, HumanoidNetworking.IMessage msg) {
writer = new NetworkWriter(); // byte[] data = msg.Serialize();
writer.StartMessage(msgType);
writer.WriteBytesAndSize(data, data.Length);
writer.FinishMessage();
identity.connectionToServer.SendWriter(writer, Channels.DefaultUnreliable);
}
protected virtual void SendToClients(byte[] data) { // short msgType = MsgType.Highest + 1;
short msgType = MsgType.Highest + 2; // writer = new NetworkWriter();
NetworkWriter sWriter = new NetworkWriter(); // writer.StartMessage(msgType);
// writer.WriteBytesAndSize(data, data.Length);
// writer.FinishMessage();
// identity.connectionToServer.SendWriter(writer, Channels.DefaultUnreliable);
//}
sWriter.StartMessage(msgType); //protected virtual void SendToClients(byte[] data) {
sWriter.WriteBytesAndSize(data, data.Length); // short msgType = MsgType.Highest + 2;
sWriter.FinishMessage(); // NetworkWriter sWriter = new NetworkWriter();
NetworkServer.SendWriterToReady(null, sWriter, Channels.DefaultUnreliable); // sWriter.StartMessage(msgType);
} // sWriter.WriteBytesAndSize(data, data.Length);
// sWriter.FinishMessage();
// NetworkServer.SendWriterToReady(null, sWriter, Channels.DefaultUnreliable);
//}
#region Instantiate Humanoid #region Instantiate Humanoid
void IHumanoidNetworking.InstantiateHumanoid(HumanoidControl humanoid) { void IHumanoidNetworking.InstantiateHumanoid(HumanoidControl humanoid) {
if (debug <= PawnNetworking.DebugLevel.Info) if (debug <= HumanoidNetworking.DebugLevel.Info)
DebugLog("Instantiate Humanoid " + humanoid.nwId + "/" + humanoid.humanoidId); DebugLog("Send Instantiate Humanoid " + humanoid.humanoidId);
HumanoidNetworking.InstantiateHumanoid instantiateHumanoid = new HumanoidNetworking.InstantiateHumanoid(humanoid); HumanoidNetworking.InstantiateHumanoid instantiateHumanoid = new HumanoidNetworking.InstantiateHumanoid(humanoid);
byte[] data = instantiateHumanoid.Serialize(); if (createLocalRemotes)
this.Receive(instantiateHumanoid);
CmdForwardInstantiateHumanoid(data); byte[] data = instantiateHumanoid.Serialize();
ForwardInstantiateHumanoidRpc(data);
} }
protected HumanoidNetworking.InstantiateHumanoid instantiatedHumanoid; protected HumanoidNetworking.InstantiateHumanoid instantiatedHumanoid;
[Command] // @ server [Rpc(SendTo.Server)] // @ server
protected virtual void CmdForwardInstantiateHumanoid(byte[] data) { protected virtual void ForwardInstantiateHumanoidRpc(byte[] data) {
instantiatedHumanoid = new HumanoidNetworking.InstantiateHumanoid(data); instantiatedHumanoid = new HumanoidNetworking.InstantiateHumanoid(data);
HumanoidPlayer[] nwHumanoids = FindObjectsOfType<HumanoidPlayer>(); HumanoidPlayer[] nwHumanoids = UnityEngine.Object.FindObjectsOfType<HumanoidPlayer>();
foreach (HumanoidPlayer nwHumanoid in nwHumanoids) foreach (HumanoidPlayer nwHumanoid in nwHumanoids)
nwHumanoid.ServerSendInstantiateHumanoid(); nwHumanoid.ServerSendInstantiateHumanoid();
} }
protected virtual void ServerSendInstantiateHumanoid() { protected virtual void ServerSendInstantiateHumanoid() {
if (debug <= PawnNetworking.DebugLevel.Info) { if (debug <= HumanoidNetworking.DebugLevel.Info) {
DebugLog("Server Send InstantiateHumanoid: " + instantiatedHumanoid.nwId + "/" + instantiatedHumanoid.humanoidId); DebugLog("Server Send InstantiateHumanoid: " + instantiatedHumanoid.nwId + "/" + instantiatedHumanoid.humanoidId);
} }
byte[] data = instantiatedHumanoid.Serialize(); byte[] data = instantiatedHumanoid.Serialize();
RpcReceiveInitiateHumanoid(data); ReceiveInitiateHumanoidRpc(data);
} }
[ClientRpc] // @ remote client [Rpc(SendTo.NotServer)] // @ remote client
protected virtual void RpcReceiveInitiateHumanoid(byte[] data) { protected virtual void ReceiveInitiateHumanoidRpc(byte[] data) {
HumanoidNetworking.InstantiateHumanoid instantiateHumanoid = new HumanoidNetworking.InstantiateHumanoid(data); HumanoidNetworking.InstantiateHumanoid instantiateHumanoid = new HumanoidNetworking.InstantiateHumanoid(data);
if (debug <= HumanoidNetworking.DebugLevel.Info)
if (debug <= PawnNetworking.DebugLevel.Info)
DebugLog("Received Instantiate Humanoid " + instantiateHumanoid.nwId + "/" + instantiateHumanoid.humanoidId); DebugLog("Received Instantiate Humanoid " + instantiateHumanoid.nwId + "/" + instantiateHumanoid.humanoidId);
if (instantiateHumanoid.nwId != identity.netId.Value) { if (instantiateHumanoid.nwId != identity.objectIdentity) {
// Get the right HumanoidPlayer for this humanoid // Get the right HumanoidPlayer for this humanoid
NetworkInstanceId netId = new NetworkInstanceId((uint)instantiateHumanoid.nwId); //NetworkInstanceId netId = new NetworkInstanceId((uint)instantiateHumanoid.nwId);
GameObject gameObject = ClientScene.FindLocalObject(netId); //GameObject gameObject = ClientScene.FindLocalObject(netId);
Unity.Netcode.NetworkObject nwObject = GetNetworkObject(instantiatedHumanoid.nwId);
GameObject gameObject = nwObject.gameObject;
HumanoidPlayer humanoidPlayer = gameObject.GetComponent<HumanoidPlayer>(); HumanoidPlayer humanoidPlayer = gameObject.GetComponent<HumanoidPlayer>();
if (humanoidPlayer != null) if (humanoidPlayer != null)
humanoidPlayer.ReceiveInstantiate(data); humanoidPlayer.ReceiveInstantiate(data);
@ -238,7 +285,7 @@ namespace Passer.Humanoid {
this.ReceiveInstantiate(data); this.ReceiveInstantiate(data);
} }
#endregion #endregion Instantiate Humanoid
#region Destroy Humanoid #region Destroy Humanoid
@ -246,56 +293,59 @@ namespace Passer.Humanoid {
if (humanoid == null) if (humanoid == null)
return; return;
if (debug <= PawnNetworking.DebugLevel.Info) if (debug <= HumanoidNetworking.DebugLevel.Info)
DebugLog("Destroy Humanoid " + humanoid.humanoidId); DebugLog("Destroy Humanoid " + humanoid.humanoidId);
HumanoidNetworking.DestroyHumanoid destroyHumanoid = new HumanoidNetworking.DestroyHumanoid(humanoid); HumanoidNetworking.DestroyHumanoid destroyHumanoid = new HumanoidNetworking.DestroyHumanoid(humanoid);
byte[] data = destroyHumanoid.Serialize(); byte[] data = destroyHumanoid.Serialize();
CmdForwardDestroyHumanoid(data); ForwardDestroyHumanoidRpc(data);
} }
[Command] // @ server [Rpc(SendTo.Server)] // @ server
private void CmdForwardDestroyHumanoid(byte[] data) { private void ForwardDestroyHumanoidRpc(byte[] data) {
if (debug <= PawnNetworking.DebugLevel.Debug) if (debug <= HumanoidNetworking.DebugLevel.Debug)
DebugLog("Forward DestroyHumanoid"); DebugLog("Forward DestroyHumanoid");
RpcReceiveDestroyHumanoid(data); ReceiveDestroyHumanoidRpc(data);
} }
[ClientRpc] [Rpc(SendTo.NotServer)]
private void RpcReceiveDestroyHumanoid(byte[] data) { private void ReceiveDestroyHumanoidRpc(byte[] data) {
this.ReceiveDestroy(data); this.ReceiveDestroy(data);
} }
#endregion #endregion Destroy Humanoid
#region Pose #region Pose
public HumanoidNetworking.HumanoidPose lastHumanoidPose { get; set; } public HumanoidNetworking.HumanoidPose lastHumanoidPose { get; set; }
public void UpdateHumanoidPose(HumanoidControl humanoid) { public void UpdateHumanoidPose(HumanoidControl humanoid) {
if (debug <= HumanoidNetworking.DebugLevel.Debug)
DebugLog("Send Pose Humanoid " + humanoid.humanoidId + " nwId: " + humanoid.nwId);
HumanoidNetworking.HumanoidPose humanoidPose = HumanoidNetworking.HumanoidPose humanoidPose =
new HumanoidNetworking.HumanoidPose(humanoid, Time.time, syncFingerSwing, syncFace); new HumanoidNetworking.HumanoidPose(humanoid, Time.time, syncFingerSwing, syncFace);
if (debug <= PawnNetworking.DebugLevel.Debug) if (createLocalRemotes)
DebugLog("Send Humanoid Pose " + humanoid.nwId + "/" + humanoid.humanoidId); this.Receive(humanoidPose);
byte[] data = humanoidPose.Serialize(); byte[] data = humanoidPose.Serialize();
CmdForwardHumanoidPose(data); ForwardHumanoidPoseRpc(data);
} }
[Command] [Rpc(SendTo.Server)]
protected virtual void CmdForwardHumanoidPose(byte[] data) { protected virtual void ForwardHumanoidPoseRpc(byte[] data) {
if (debug <= PawnNetworking.DebugLevel.Debug) { if (debug <= HumanoidNetworking.DebugLevel.Debug) {
HumanoidNetworking.HumanoidPose humanoidPose = new HumanoidNetworking.HumanoidPose(data); HumanoidNetworking.HumanoidPose humanoidPose = new HumanoidNetworking.HumanoidPose(data);
DebugLog("Forward HumanoidPose " + humanoidPose.nwId + "/" + humanoidPose.humanoidId); DebugLog("Forward HumanoidPose " + humanoidPose.nwId + "/" + humanoidPose.humanoidId);
} }
RpcReceiveHumanoidPose(data); ReceiveHumanoidPoseRpc(data);
} }
[ClientRpc] [Rpc(SendTo.NotServer)]
protected virtual void RpcReceiveHumanoidPose(byte[] data) { protected virtual void ReceiveHumanoidPoseRpc(byte[] data) {
this.ReceiveHumanoidPose(data); this.ReceiveHumanoidPose(data);
} }
@ -304,28 +354,28 @@ namespace Passer.Humanoid {
#region Grab #region Grab
void IHumanoidNetworking.Grab(HandTarget handTarget, GameObject obj, bool rangeCheck, HandTarget.GrabType grabType) { void IHumanoidNetworking.Grab(HandTarget handTarget, GameObject obj, bool rangeCheck, HandTarget.GrabType grabType) {
if (debug <= PawnNetworking.DebugLevel.Info) if (debug <= HumanoidNetworking.DebugLevel.Info)
Debug.Log(handTarget.humanoid.nwId + ": Grab " + obj); Debug.Log(handTarget.humanoid.nwId + ": Grab " + obj);
ulong objIdentity = GetObjectIdentity(obj); ulong objIdentity = GetObjectIdentity(obj);
if (objIdentity == 0) { if (objIdentity == 0) {
if (debug <= PawnNetworking.DebugLevel.Error) if (debug <= HumanoidNetworking.DebugLevel.Error)
Debug.LogError("Grabbed object " + obj + " does not have a network identity"); Debug.LogError("Grabbed object " + obj + " does not have a network identity");
return; return;
} }
HumanoidNetworking.Grab grab = new HumanoidNetworking.Grab(handTarget, objIdentity, rangeCheck, grabType); HumanoidNetworking.Grab grab = new HumanoidNetworking.Grab(handTarget, objIdentity, rangeCheck, grabType);
byte[] data = grab.Serialize(); byte[] data = grab.Serialize();
CmdForwardGrab(data); ForwardGrabRpc(data);
} }
[Command] [Rpc(SendTo.Server)]
protected virtual void CmdForwardGrab(byte[] data) { protected virtual void ForwardGrabRpc(byte[] data) {
RpcReceiveGrab(data); ReceiveGrabRpc(data);
} }
[ClientRpc] [Rpc(SendTo.NotServer)]
protected virtual void RpcReceiveGrab(byte[] data) { protected virtual void ReceiveGrabRpc(byte[] data) {
this.ReceiveGrab(data); this.ReceiveGrab(data);
} }
@ -334,21 +384,21 @@ namespace Passer.Humanoid {
#region Let Go #region Let Go
void IHumanoidNetworking.LetGo(HandTarget handTarget) { void IHumanoidNetworking.LetGo(HandTarget handTarget) {
if (debug <= PawnNetworking.DebugLevel.Info) if (debug <= HumanoidNetworking.DebugLevel.Info)
DebugLog("LetGo"); DebugLog("LetGo");
HumanoidNetworking.LetGo letGo = new HumanoidNetworking.LetGo(handTarget); HumanoidNetworking.LetGo letGo = new HumanoidNetworking.LetGo(handTarget);
byte[] data = letGo.Serialize(); byte[] data = letGo.Serialize();
CmdForwardLetGo(data); ForwardLetGoRpc(data);
} }
[Command] [Rpc(SendTo.Server)]
protected virtual void CmdForwardLetGo(byte[] data) { protected virtual void ForwardLetGoRpc(byte[] data) {
RpcReceiveLetGo(data); ReceiveLetGoRpc(data);
} }
[ClientRpc] [Rpc(SendTo.NotServer)]
protected virtual void RpcReceiveLetGo(byte[] data) { protected virtual void ReceiveLetGoRpc(byte[] data) {
this.ReceiveLetGo(data); this.ReceiveLetGo(data);
} }
@ -356,22 +406,22 @@ namespace Passer.Humanoid {
#region ChangeAvatar #region ChangeAvatar
void IHumanoidNetworking.ChangeAvatar(HumanoidControl humanoid, string avatarPrefabName) { void IHumanoidNetworking.ChangeAvatar(HumanoidControl humanoid, string avatarPrefabName, string possessionLocation) {
if (debug <= PawnNetworking.DebugLevel.Info) if (debug <= HumanoidNetworking.DebugLevel.Info)
DebugLog("Change Avatar: " + avatarPrefabName); DebugLog("Change Avatar: " + avatarPrefabName);
HumanoidNetworking.ChangeAvatar changeAvatar = new HumanoidNetworking.ChangeAvatar(humanoid, avatarPrefabName); HumanoidNetworking.ChangeAvatar changeAvatar = new HumanoidNetworking.ChangeAvatar(humanoid, avatarPrefabName, possessionLocation);
byte[] data = changeAvatar.Serialize(); byte[] data = changeAvatar.Serialize();
CmdForwardChangeAvatar(data); ForwardChangeAvatarRpc(data);
} }
[Command] [Rpc(SendTo.Server)]
protected virtual void CmdForwardChangeAvatar(byte[] data) { protected virtual void ForwardChangeAvatarRpc(byte[] data) {
RpcReceiveChangeAvatar(data); ReceiveChangeAvatarRpc(data);
} }
[ClientRpc] [Rpc(SendTo.NotServer)]
protected virtual void RpcReceiveChangeAvatar(byte[] data) { protected virtual void ReceiveChangeAvatarRpc(byte[] data) {
this.ReceiveChangeAvatar(data); this.ReceiveChangeAvatar(data);
} }
@ -386,16 +436,16 @@ namespace Passer.Humanoid {
HumanoidNetworking.SyncTrackingSpace syncTracking = new HumanoidNetworking.SyncTrackingSpace(humanoid, trackingTransform.position, trackingTransform.rotation); HumanoidNetworking.SyncTrackingSpace syncTracking = new HumanoidNetworking.SyncTrackingSpace(humanoid, trackingTransform.position, trackingTransform.rotation);
byte[] data = syncTracking.Serialize(); byte[] data = syncTracking.Serialize();
CmdForwardSyncTracking(data); ForwardSyncTrackingRpc(data);
} }
[Command] [Rpc(SendTo.Server)]
protected virtual void CmdForwardSyncTracking(byte[] data) { protected virtual void ForwardSyncTrackingRpc(byte[] data) {
RpcReceiveSyncTracking(data); ReceiveSyncTrackingRpc(data);
} }
[ClientRpc] [Rpc(SendTo.NotServer)]
protected virtual void RpcReceiveSyncTracking(byte[] data) { protected virtual void ReceiveSyncTrackingRpc(byte[] data) {
this.ReceiveSyncTrackingSpace(data); this.ReceiveSyncTrackingSpace(data);
} }
@ -425,7 +475,7 @@ namespace Passer.Humanoid {
} }
} }
#endregion #endregion Network Sync
#region Network Object #region Network Object
@ -447,38 +497,38 @@ namespace Passer.Humanoid {
#region Void Event #region Void Event
public void RPC(FunctionCall functionCall) { //public void RPC(FunctionCall functionCall) {
CmdRPCVoid(functionCall.targetGameObject, functionCall.methodName); // RPCVoidServerRpc(functionCall.targetGameObject, functionCall.methodName);
} //}
[Command] // @ server //[Rpc(SendTo.Server)] // @ server
public void CmdRPCVoid(GameObject target, string methodName) { //public void RPCVoidServerRpc(GameObject target, string methodName) {
RpcRPCVoid(target, methodName); // RPCVoidRpc(target, methodName);
} //}
[ClientRpc] // @ remote client //[Rpc(SendTo.NotServer)] // @ remote client
public void RpcRPCVoid(GameObject targetGameObject, string methodName) { //public void RPCVoidRpc(GameObject targetGameObject, string methodName) {
Debug.Log("RPC: " + methodName); // Debug.Log("RPC: " + methodName);
FunctionCall.Execute(targetGameObject, methodName); // FunctionCall.Execute(targetGameObject, methodName);
} //}
#endregion #endregion
#region Bool Event #region Bool Event
public void RPC(FunctionCall functionCall, bool value) { //public void RPC(FunctionCall functionCall, bool value) {
CmdRPCBool(functionCall.targetGameObject, functionCall.methodName, value); // RPCBoolServerRpc(functionCall.targetGameObject, functionCall.methodName, value);
} //}
[Command] // @ server //[Rpc(SendTo.Server)] // @ server
public void CmdRPCBool(GameObject target, string methodName, bool value) { //public void RPCBoolServerRpc(GameObject target, string methodName, bool value) {
RpcRPCBool(target, methodName, value); // RPCBoolRpc(target, methodName, value);
} //}
[ClientRpc] // @ remote client //[Rpc(SendTo.NotServer)] // @ remote client
public void RpcRPCBool(GameObject target, string methodName, bool value) { //public void RPCBoolRpc(GameObject target, string methodName, bool value) {
FunctionCall.Execute(target, methodName, value); // FunctionCall.Execute(target, methodName, value);
} //}
#endregion #endregion
@ -504,20 +554,21 @@ namespace Passer.Humanoid {
//} //}
#endregion #endregion
#endregion
#endregion Network Object
#region Debug #region Debug
public void DebugLog(string s) { public void DebugLog(string message) {
Debug.Log(netId + ": " + s); Debug.Log(identity.objectIdentity + ": " + message);
} }
public void DebugWarning(string s) { public void DebugWarning(string message) {
Debug.LogWarning(netId + ": " + s); Debug.LogWarning(identity.objectIdentity + ": " + message);
} }
public void DebugError(string s) { public void DebugError(string message) {
Debug.LogError(netId + ": " + s); Debug.LogError(identity.objectIdentity + ": " + message);
} }
#endregion #endregion
@ -525,4 +576,4 @@ namespace Passer.Humanoid {
#pragma warning restore 0618 #pragma warning restore 0618
} }
#endif #endif
} }

View File

@ -1,5 +1,6 @@
{ {
"name": "PasserVR.HumanoidControl", "name": "PasserVR.HumanoidControl",
"rootNamespace": "",
"references": [ "references": [
"UnityEditor.SpatialTracking", "UnityEditor.SpatialTracking",
"UnityEngine.SpatialTracking", "UnityEngine.SpatialTracking",
@ -13,7 +14,9 @@
"LeapMotion.LeapCSharp", "LeapMotion.LeapCSharp",
"Ultraleap.Tracking.Core", "Ultraleap.Tracking.Core",
"SteamVR", "SteamVR",
"Unity.XR.OpenVR" "Unity.XR.OpenVR",
"Unity.Netcode.Runtime",
"Unity.Netcode.Components"
], ],
"includePlatforms": [], "includePlatforms": [],
"excludePlatforms": [], "excludePlatforms": [],