Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions com.unity.multiplayer.mlapi/Prototyping/NetworkTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ internal class ClientSendInfo
public Vector3? LastMissedPosition;
public Quaternion? LastMissedRotation;
}

/// <summary>
/// Sync the server position of the object instead of the owner
/// </summary>
public bool SyncServer = false;

/// <summary>
/// The base amount of sends per seconds to use when range is disabled
Expand Down Expand Up @@ -167,7 +172,7 @@ public override void NetworkStart()

private void Update()
{
if (IsOwner)
if ((IsOwner && !SyncServer) || (IsServer && SyncServer))
{
if (NetworkManager.NetworkTime - m_LastSendTime >= (1f / FixedSendsPerSecond) && (Vector3.Distance(transform.position, m_LastSentPos) > MinMeters || Quaternion.Angle(transform.rotation, m_LastSentRot) > MinDegrees))
{
Expand All @@ -177,8 +182,12 @@ private void Update()

if (IsServer)
{
ApplyTransformClientRpc(transform.position, transform.rotation.eulerAngles,
new ClientRpcParams { Send = new ClientRpcSendParams { TargetClientIds = NetworkManager.ConnectedClientsList.Where(c => c.ClientId != OwnerClientId).Select(c => c.ClientId).ToArray() } });
if (SyncServer)
{
ApplyTransformClientRpc(transform.position, transform.rotation.eulerAngles);
}
else
ApplyTransformClientRpc(transform.position, transform.rotation.eulerAngles, new ClientRpcParams { Send = new ClientRpcSendParams { TargetClientIds = NetworkManager.Singleton.ConnectedClientsList.Where(c => c.ClientId != OwnerClientId).Select(c => c.ClientId).ToArray() } });
}
else
{
Expand Down Expand Up @@ -261,7 +270,7 @@ private void ApplyTransformInternal(Vector3 position, Quaternion rotation)
[ServerRpc]
private void SubmitTransformServerRpc(Vector3 position, Vector3 eulerAngles, ServerRpcParams rpcParams = default)
{
if (!enabled)
if (!enabled || SyncServer)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion com.unity.multiplayer.mlapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.unity.multiplayer.mlapi",
"displayName": "MLAPI Networking Library",
"version": "0.1.0",
"version": "0.1.1",
"unity": "2020.3",
"unityRelease": "0f1",
"description": "This the Core Unity Mid-level API that provides core SDK for multiplayer games within unity",
Expand Down