diff --git a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs index 894aaf76d5..017ada087b 100644 --- a/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs +++ b/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs @@ -1432,10 +1432,7 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass if (typeDefinition.HasGenericParameters) { var genericTypes = new List(); - foreach (var parameter in typeDefinition.GenericParameters) - { - genericTypes.Add(parameter); - } + genericTypes.AddRange(typeDefinition.GenericParameters); callMethod = callMethod.MakeGeneric(genericTypes.ToArray()); } @@ -3102,10 +3099,7 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition if (castType.HasGenericParameters) { var genericTypes = new List(); - foreach (var parameter in castType.GenericParameters) - { - genericTypes.Add(parameter); - } + genericTypes.AddRange(castType.GenericParameters); castType = castType.MakeGenericInstanceType(genericTypes.ToArray()); callMethod = callMethod.MakeGeneric(genericTypes.ToArray()); } diff --git a/com.unity.netcode.gameobjects/Editor/Configuration/NetcodeForGameObjectsProjectSettings.cs b/com.unity.netcode.gameobjects/Editor/Configuration/NetcodeForGameObjectsProjectSettings.cs index 52bd0ef011..63aad22d09 100644 --- a/com.unity.netcode.gameobjects/Editor/Configuration/NetcodeForGameObjectsProjectSettings.cs +++ b/com.unity.netcode.gameobjects/Editor/Configuration/NetcodeForGameObjectsProjectSettings.cs @@ -22,7 +22,7 @@ public class NetcodeForGameObjectsProjectSettings : ScriptableSingleton /// Useful to know if we should or should not send a message /// - internal bool HasRemoteObservers => !(Observers.Count() == 0 || (Observers.Contains(NetworkManager.LocalClientId) && Observers.Count() == 1)); + internal bool HasRemoteObservers => !(Observers.Count == 0 || (Observers.Contains(NetworkManager.LocalClientId) && Observers.Count == 1)); /// /// Distributed Authority Mode Only @@ -1085,7 +1085,7 @@ internal void SendOwnershipStatusUpdate() } else { - changeOwnership.ClientIdCount = Observers.Count(); + changeOwnership.ClientIdCount = Observers.Count; changeOwnership.ClientIds = Observers.ToArray(); NetworkManager.ConnectionManager.SendMessage(ref changeOwnership, NetworkDelivery.Reliable, NetworkManager.ServerClientId); } diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ParentSyncMessage.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ParentSyncMessage.cs index c2965d4b31..7b4739369d 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ParentSyncMessage.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ParentSyncMessage.cs @@ -130,13 +130,11 @@ public void Handle(ref NetworkContext context) // the values of the server-side post-parenting transform values if (!WorldPositionStays) { - networkObject.transform.localPosition = Position; - networkObject.transform.localRotation = Rotation; + networkObject.transform.SetLocalPositionAndRotation(Position, Rotation); } else { - networkObject.transform.position = Position; - networkObject.transform.rotation = Rotation; + networkObject.transform.SetPositionAndRotation(Position, Rotation); } networkObject.transform.localScale = Scale; } diff --git a/com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs b/com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs index 69376d8ed4..5cbd710f46 100644 --- a/com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs @@ -801,8 +801,7 @@ internal NetworkObject InstantiateAndSpawnNoParameterChecks(NetworkObject networ return null; } networkObject.IsPlayerObject = isPlayerObject; - networkObject.transform.position = position; - networkObject.transform.rotation = rotation; + networkObject.transform.SetPositionAndRotation(position, rotation); // If spawning as a player, then invoke SpawnAsPlayerObject if (isPlayerObject) { @@ -901,8 +900,7 @@ internal NetworkObject GetNetworkObjectToSpawn(uint globalObjectIdHash, ulong ow internal NetworkObject InstantiateNetworkPrefab(GameObject networkPrefab, uint prefabGlobalObjectIdHash, Vector3? position, Quaternion? rotation) { var networkObject = UnityEngine.Object.Instantiate(networkPrefab).GetComponent(); - networkObject.transform.position = position ?? networkObject.transform.position; - networkObject.transform.rotation = rotation ?? networkObject.transform.rotation; + networkObject.transform.SetPositionAndRotation(position ?? networkObject.transform.position, rotation ?? networkObject.transform.rotation); networkObject.NetworkManagerOwner = NetworkManager; networkObject.PrefabGlobalObjectIdHash = prefabGlobalObjectIdHash; return networkObject; @@ -996,13 +994,11 @@ internal NetworkObject CreateLocalNetworkObject(NetworkObject.SceneObject sceneO // then we want to apply the position and rotation values world space relative if ((worldPositionStays && !nonNetworkObjectParent) || !networkObject.AutoObjectParentSync) { - networkObject.transform.position = position; - networkObject.transform.rotation = rotation; + networkObject.transform.SetPositionAndRotation(position, rotation); } else { - networkObject.transform.localPosition = position; - networkObject.transform.localRotation = rotation; + networkObject.transform.SetLocalPositionAndRotation(position, rotation); } // SPECIAL CASE: diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformOwnershipTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformOwnershipTests.cs index 1c80fc61c5..22f9bc3a21 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformOwnershipTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformOwnershipTests.cs @@ -53,8 +53,7 @@ protected override void OnServerAndClientsCreated() rigidBody.detectCollisions = false; rigidBody.position = Vector3.zero; rigidBody.rotation = Quaternion.identity; - rigidBody.transform.position = Vector3.zero; - rigidBody.transform.rotation = Quaternion.identity; + rigidBody.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); // NOTE: We don't use a sphere collider for this integration test because by the time we can // assure they don't collide and skew the results the NetworkObjects are already synchronized // with skewed results @@ -77,8 +76,7 @@ protected override void OnServerAndClientsCreated() rigidBody.detectCollisions = false; rigidBody.position = Vector3.zero; rigidBody.rotation = Quaternion.identity; - rigidBody.transform.position = Vector3.zero; - rigidBody.transform.rotation = Quaternion.identity; + rigidBody.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); // NOTE: We don't use a sphere collider for this integration test because by the time we can // assure they don't collide and skew the results the NetworkObjects are already synchronized // with skewed results @@ -302,8 +300,7 @@ void LogOwnerRigidBody(int stage) } else { - ownerInstance.transform.position = valueSetByOwner; - ownerInstance.transform.rotation = rotation; + ownerInstance.transform.SetPositionAndRotation(valueSetByOwner, rotation); ownerInstance.transform.localScale = valueSetByOwner; } @@ -392,8 +389,7 @@ void LogOwnerRigidBody(int stage) else { m_UseAdjustedVariance = false; - ownerInstance.transform.position = valueSetByOwner; - ownerInstance.transform.rotation = rotation; + ownerInstance.transform.SetPositionAndRotation(valueSetByOwner, rotation); } LogOwnerRigidBody(3); diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariable/NetworkVariableCollectionsTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariable/NetworkVariableCollectionsTests.cs index 85d283df3c..224b82cf32 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariable/NetworkVariableCollectionsTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariable/NetworkVariableCollectionsTests.cs @@ -726,7 +726,7 @@ private IEnumerator ValidateClients(NetworkManager clientBeingTested, bool initi if (initialize) { - clientsInitialized.Add(client.LocalClientId, ownerInitialized & serverInitialized); + clientsInitialized.Add(client.LocalClientId, ownerInitialized && serverInitialized); } } diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/PlayerObjectTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/PlayerObjectTests.cs index e011d94c8a..a3207c5a3c 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/PlayerObjectTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/PlayerObjectTests.cs @@ -141,8 +141,7 @@ protected override void OnCreatePlayerPrefab() var playerNetworkObject = m_PlayerPrefab.GetComponent(); m_PlayerPosition = GetRandomVector3(-10.0f, 10.0f); m_PlayerRotation = Quaternion.Euler(GetRandomVector3(-180.0f, 180.0f)); - playerNetworkObject.transform.position = m_PlayerPosition; - playerNetworkObject.transform.rotation = m_PlayerRotation; + playerNetworkObject.transform.SetPositionAndRotation(m_PlayerPosition, m_PlayerRotation); base.OnCreatePlayerPrefab(); } diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Prefabs/NetworkPrefabHandlerTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Prefabs/NetworkPrefabHandlerTests.cs index 7460ea65fc..34b98001ca 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Prefabs/NetworkPrefabHandlerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Prefabs/NetworkPrefabHandlerTests.cs @@ -225,8 +225,7 @@ internal class NetworkPrefaInstanceHandler : INetworkPrefabInstanceHandler public NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation) { var networkObjectInstance = UnityEngine.Object.Instantiate(m_NetworkObject.gameObject).GetComponent(); - networkObjectInstance.transform.position = position; - networkObjectInstance.transform.rotation = rotation; + networkObjectInstance.transform.SetPositionAndRotation(position, rotation); m_Instances.Add(networkObjectInstance); return networkObjectInstance; }