Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/conventional-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- master
- develop
- release/**

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down Expand Up @@ -35,4 +36,4 @@ jobs:
# For work-in-progress PRs you can typically use draft pull requests from Github. However, private repositories on the free plan don't have this option and therefore this action allows you to opt-in to using the special '[WIP]' prefix to indicate this state. This will avoid the validation of the PR title and the pull request checks remain pending. Note that a second check will be reported if this is enabled.
#wip: # optional
# When using "Squash and merge" on a PR with only one commit, GitHub will suggest using that commit message instead of the PR title for the merge commit, and it's easy to commit this by mistake. Enable this option to also validate the commit message for one commit PRs.
validateSingleCommit: true # optional
validateSingleCommit: true # optional
4 changes: 3 additions & 1 deletion .yamato/project-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,6 @@ develop_pull_request_trigger:
pull_requests:
- targets:
only:
- "develop"
- "master"
- "develop"
- "/release\/.*/"
8 changes: 1 addition & 7 deletions com.unity.multiplayer.mlapi/Editor/PostProcessScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ public class NetworkScenePostProcess : MonoBehaviour
[PostProcessScene(int.MaxValue)]
public static void ProcessScene()
{
//If we are in playmode (editor or stand alone) we do not want this to execute
if (Application.isPlaying)
{
return;
}

var traverseSortedObjects = FindObjectsOfType<NetworkObject>().ToList();

traverseSortedObjects.Sort((x, y) =>
Expand Down Expand Up @@ -68,4 +62,4 @@ internal static List<int> TraversedSiblingIndex(this NetworkObject networkObject
return paths;
}
}
}
}
1 change: 1 addition & 0 deletions com.unity.multiplayer.mlapi/Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

#if UNITY_EDITOR
[assembly: InternalsVisibleTo("Unity.Multiplayer.MLAPI.EditorTests")]
[assembly: InternalsVisibleTo("Unity.Multiplayer.MLAPI.RuntimeTests")]
#endif
8 changes: 4 additions & 4 deletions com.unity.multiplayer.mlapi/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private void OnValidate()
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal)
{
NetworkLog.LogWarning($"{nameof(NetworkManager)} cannot be a {nameof(NetworkObject)}. This will lead to weird side effects.");
NetworkLog.LogWarning($"{nameof(NetworkManager)} cannot be a {nameof(NetworkObject)}.");
}
}

Expand Down Expand Up @@ -360,14 +360,14 @@ private void Init(bool server)
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
{
NetworkLog.LogError($"{nameof(NetworkPrefab)} cannot be null");
NetworkLog.LogError($"{nameof(NetworkPrefab)} cannot be null ({nameof(NetworkPrefab)} at index: {i})");
}
}
else if (ReferenceEquals(NetworkConfig.NetworkPrefabs[i].Prefab.GetComponent<NetworkObject>(), null))
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
{
NetworkLog.LogError($"{nameof(NetworkPrefab)} is missing a {nameof(NetworkObject)} component");
NetworkLog.LogError($"{nameof(NetworkPrefab)} (\"{NetworkConfig.NetworkPrefabs[i].Prefab.name}\") is missing a {nameof(NetworkObject)} component");
}
}
else
Expand Down Expand Up @@ -932,7 +932,7 @@ internal void HandleIncomingData(ulong clientId, NetworkChannel networkChannel,
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
{
NetworkLog.LogError("Message unwrap could not be completed. Was the header corrupt? Crypto error?");
NetworkLog.LogError("Message unwrap could not be completed. Was the header corrupt?");
}

return;
Expand Down
59 changes: 26 additions & 33 deletions com.unity.multiplayer.mlapi/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using MLAPI.Configuration;
using MLAPI.Exceptions;
using MLAPI.Hashing;
Expand Down Expand Up @@ -366,21 +367,22 @@ private void OnDestroy()
}
}

/// <summary>
/// Spawns this GameObject across the network. Can only be called from the Server
/// </summary>
/// <param name="spawnPayload">The writer containing the spawn payload</param>
/// <param name="destroyWithScene">Should the object be destroyd when the scene is changed</param>
public void Spawn(Stream spawnPayload = null, bool destroyWithScene = false)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SpawnInternal(Stream spawnPayload, bool destroyWithScene , ulong? ownerClientId, bool playerObject)
{
if (!NetworkManager.Singleton.IsListening)
{
throw new NotListeningException($"{nameof(NetworkManager)} isn't listening, start a server, client or host before spawning objects.");
throw new NotListeningException($"{nameof(NetworkManager)} isn't listening, start a server or host before spawning objects.");
}

if (!NetworkManager.Singleton.IsServer)
{
throw new NotServerException($"Only server can spawn {nameof(NetworkObject)}s");
}

if (spawnPayload != null) spawnPayload.Position = 0;

NetworkSpawnManager.SpawnNetworkObjectLocally(this, NetworkSpawnManager.GetNetworkObjectId(), false, false, null, spawnPayload, spawnPayload != null, spawnPayload == null ? 0 : (int)spawnPayload.Length, false, destroyWithScene);
NetworkSpawnManager.SpawnNetworkObjectLocally(this, NetworkSpawnManager.GetNetworkObjectId(), false, playerObject, ownerClientId, spawnPayload, spawnPayload != null, spawnPayload == null ? 0 : (int)spawnPayload.Length, false, destroyWithScene);

for (int i = 0; i < NetworkManager.Singleton.ConnectedClientsList.Count; i++)
{
Expand All @@ -392,11 +394,13 @@ public void Spawn(Stream spawnPayload = null, bool destroyWithScene = false)
}

/// <summary>
/// Despawns this GameObject and destroys it for other clients. This should be used if the object should be kept on the server
/// Spawns this GameObject across the network. Can only be called from the Server
/// </summary>
public void Despawn(bool destroy = false)
/// <param name="spawnPayload">The writer containing the spawn payload</param>
/// <param name="destroyWithScene">Should the object be destroyd when the scene is changed</param>
public void Spawn(Stream spawnPayload = null, bool destroyWithScene = false)
{
NetworkSpawnManager.DespawnObject(this, destroy);
SpawnInternal(spawnPayload, destroyWithScene, null, false);
}

/// <summary>
Expand All @@ -407,17 +411,7 @@ public void Despawn(bool destroy = false)
/// <param name="destroyWithScene">Should the object be destroyd when the scene is changed</param>
public void SpawnWithOwnership(ulong clientId, Stream spawnPayload = null, bool destroyWithScene = false)
{
if (spawnPayload != null) spawnPayload.Position = 0;

NetworkSpawnManager.SpawnNetworkObjectLocally(this, NetworkSpawnManager.GetNetworkObjectId(), false, false, clientId, spawnPayload, spawnPayload != null, spawnPayload == null ? 0 : (int)spawnPayload.Length, false, destroyWithScene);

for (int i = 0; i < NetworkManager.Singleton.ConnectedClientsList.Count; i++)
{
if (m_Observers.Contains(NetworkManager.Singleton.ConnectedClientsList[i].ClientId))
{
NetworkSpawnManager.SendSpawnCallForObject(NetworkManager.Singleton.ConnectedClientsList[i].ClientId, this, spawnPayload);
}
}
SpawnInternal(spawnPayload, destroyWithScene, clientId, false);
}

/// <summary>
Expand All @@ -428,19 +422,18 @@ public void SpawnWithOwnership(ulong clientId, Stream spawnPayload = null, bool
/// <param name="destroyWithScene">Should the object be destroyd when the scene is changed</param>
public void SpawnAsPlayerObject(ulong clientId, Stream spawnPayload = null, bool destroyWithScene = false)
{
if (spawnPayload != null) spawnPayload.Position = 0;

NetworkSpawnManager.SpawnNetworkObjectLocally(this, NetworkSpawnManager.GetNetworkObjectId(), false, true, clientId, spawnPayload, spawnPayload != null, spawnPayload == null ? 0 : (int)spawnPayload.Length, false, destroyWithScene);
SpawnInternal(spawnPayload, destroyWithScene, clientId, true);
}

for (int i = 0; i < NetworkManager.Singleton.ConnectedClientsList.Count; i++)
{
if (m_Observers.Contains(NetworkManager.Singleton.ConnectedClientsList[i].ClientId))
{
NetworkSpawnManager.SendSpawnCallForObject(NetworkManager.Singleton.ConnectedClientsList[i].ClientId, this, spawnPayload);
}
}
/// <summary>
/// Despawns this GameObject and destroys it for other clients. This should be used if the object should be kept on the server
/// </summary>
public void Despawn(bool destroy = false)
{
NetworkSpawnManager.DespawnObject(this, destroy);
}


/// <summary>
/// Removes all ownership of an object from any client. Can only be called from server
/// </summary>
Expand Down Expand Up @@ -575,4 +568,4 @@ internal NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index)
return ChildNetworkBehaviours[index];
}
}
}
}
16 changes: 8 additions & 8 deletions com.unity.multiplayer.mlapi/Runtime/Core/NetworkUpdateLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private static void RunNetworkUpdateStage(NetworkUpdateStage updateStage)
}
}

private struct NetworkInitialization
internal struct NetworkInitialization
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -162,7 +162,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkEarlyUpdate
internal struct NetworkEarlyUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -174,7 +174,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkFixedUpdate
internal struct NetworkFixedUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -186,7 +186,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkPreUpdate
internal struct NetworkPreUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -198,7 +198,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkUpdate
internal struct NetworkUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -210,7 +210,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkPreLateUpdate
internal struct NetworkPreLateUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -222,7 +222,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkPostLateUpdate
internal struct NetworkPostLateUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand Down Expand Up @@ -361,4 +361,4 @@ private static void Initialize()
PlayerLoop.SetPlayerLoop(customPlayerLoop);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,26 @@ private static void RegisterMLAPIPerformanceEvent()
private static void OnPerformanceTickData(PerformanceTickData tickData)
{
// Operations
k_ConnectionsCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfConnections);
k_TickRateCounterValue.Value += tickData.GetData(ProfilerConstants.ReceiveTickRate);
k_ConnectionsCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfConnections);
k_TickRateCounterValue.Value = tickData.GetData(ProfilerConstants.ReceiveTickRate);

// Messages
k_NamedMessagesCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfNamedMessages);
k_UnnamedMessagesCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfUnnamedMessages);
k_BytesSentCounterValue.Value += tickData.GetData(ProfilerConstants.NumberBytesSent);
k_BytesReceivedCounterValue.Value += tickData.GetData(ProfilerConstants.NumberBytesReceived);
k_NetworkVarsCounterValue.Value += tickData.GetData(ProfilerConstants.NumberNetworkVarsReceived);
k_NamedMessagesCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfNamedMessages);
k_UnnamedMessagesCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfUnnamedMessages);
k_BytesSentCounterValue.Value = tickData.GetData(ProfilerConstants.NumberBytesSent);
k_BytesReceivedCounterValue.Value = tickData.GetData(ProfilerConstants.NumberBytesReceived);
k_NetworkVarsCounterValue.Value = tickData.GetData(ProfilerConstants.NumberNetworkVarsReceived);

// RPCs
k_RPCsSentCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfRPCsSent);
k_RPCsReceivedCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfRPCsReceived);
k_RPCBatchesSentCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfRPCBatchesSent);
k_RPCBatchesReceivedCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfRPCBatchesReceived);
k_RPCBatchesReceivedCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfRPCBatchesReceived);
k_RPCQueueProcessedCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfRPCQueueProcessed);
k_RPCsInQueueSizeCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfRPCsInQueueSize);
k_RPCsOutQueueSizeCounterValue.Value += tickData.GetData(ProfilerConstants.NumberOfRPCsOutQueueSize);
k_RPCsSentCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfRPCsSent);
k_RPCsReceivedCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfRPCsReceived);
k_RPCBatchesSentCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfRPCBatchesSent);
k_RPCBatchesReceivedCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfRPCBatchesReceived);
k_RPCBatchesReceivedCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfRPCBatchesReceived);
k_RPCQueueProcessedCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfRPCQueueProcessed);
k_RPCsInQueueSizeCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfRPCsInQueueSize);
k_RPCsOutQueueSizeCounterValue.Value = tickData.GetData(ProfilerConstants.NumberOfRPCsOutQueueSize);
}
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void WriteObjectPacked(object value)
}
else if (value is bool)
{
WriteBit((bool)value);
WriteBool((bool)value);
return;
}
else if (value is Vector2)
Expand Down Expand Up @@ -1606,4 +1606,4 @@ public void WriteDoubleArrayPackedDiff(double[] write, double[] compare, long co
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void RegisterSpawnHandler(ulong prefabHash, SpawnHandlerDelegate h
/// </summary>
/// <param name="prefabHash">The prefab hash to destroy</param>
/// <param name="handler">The delegate handler</param>
public static void RegisterCustomDestroyHandler(ulong prefabHash, DestroyHandlerDelegate handler)
public static void RegisterDestroyHandler(ulong prefabHash, DestroyHandlerDelegate handler)
{
if (CustomDestroyHandlers.ContainsKey(prefabHash))
{
Expand All @@ -83,19 +83,19 @@ public static void RegisterCustomDestroyHandler(ulong prefabHash, DestroyHandler
}

/// <summary>
/// Removes the custom spawn handler for a specific prefab hash
/// Unregisters the custom spawn handler for a specific prefab hash
/// </summary>
/// <param name="prefabHash">The prefab hash of the prefab spawn handler that is to be removed</param>
public static void RemoveCustomSpawnHandler(ulong prefabHash)
public static void UnregisterSpawnHandler(ulong prefabHash)
{
CustomSpawnHandlers.Remove(prefabHash);
}

/// <summary>
/// Removes the custom destroy handler for a specific prefab hash
/// Unregisters the custom destroy handler for a specific prefab hash
/// </summary>
/// <param name="prefabHash">The prefab hash of the prefab destroy handler that is to be removed</param>
public static void RemoveCustomDestroyHandler(ulong prefabHash)
public static void UnregisterDestroyHandler(ulong prefabHash)
{
CustomDestroyHandlers.Remove(prefabHash);
}
Expand Down Expand Up @@ -743,4 +743,4 @@ internal static void OnDestroyObject(ulong networkId, bool destroyGameObject)
}
}
}
}
}
Loading