Feature: Upgrading 2D Space Shooter to NGO 1.8.1 [MTT-8498] (#174)

* upgrading to NGO 1.8.1 and adjusting scripts to include new RPC attribute and OnConnectionEvent

* update CHANGELOG
This commit is contained in:
Elfi0Kuhndorf 2024-05-15 15:42:57 +02:00 коммит произвёл GitHub
Родитель ad2eaa3f3b
Коммит eb69754c93
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
6 изменённых файлов: 34 добавлений и 32 удалений

Просмотреть файл

@ -52,12 +52,12 @@ public class Bullet : NetworkBehaviour
{
var bulletRb = GetComponent<Rigidbody2D>();
bulletRb.velocity = velocity;
SetVelocityClientRpc(velocity);
ClientSetVelocityRpc(velocity);
}
}
[ClientRpc]
void SetVelocityClientRpc(Vector2 velocity)
[Rpc(SendTo.ClientsAndHost)]
void ClientSetVelocityRpc(Vector2 velocity)
{
if (!IsHost)
{

Просмотреть файл

@ -80,24 +80,25 @@ public class NetworkManagerHud : MonoBehaviour
ShowInGameUI(false);
ShowStatusText(false);
NetworkManager.Singleton.OnClientConnectedCallback += OnOnClientConnectedCallback;
NetworkManager.Singleton.OnClientDisconnectCallback += OnOnClientDisconnectCallback;
NetworkManager.Singleton.OnConnectionEvent += OnConnectionEvent;
}
void OnOnClientConnectedCallback(ulong obj)
void OnConnectionEvent(NetworkManager networkManager, ConnectionEventData connectionEventData)
{
ShowMainMenuUI(false);
ShowInGameUI(true);
}
void OnOnClientDisconnectCallback(ulong clientId)
{
if ((NetworkManager.Singleton.IsServer && clientId != NetworkManager.ServerClientId))
if (connectionEventData.EventType == ConnectionEvent.ClientConnected)
{
return;
ShowMainMenuUI(false);
ShowInGameUI(true);
}
else if (connectionEventData.EventType == ConnectionEvent.ClientDisconnected)
{
if ((NetworkManager.Singleton.IsServer && connectionEventData.ClientId != NetworkManager.ServerClientId))
{
return;
}
ShowMainMenuUI(true);
ShowInGameUI(false);
}
ShowMainMenuUI(true);
ShowInGameUI(false);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -262,7 +263,6 @@ public class NetworkManagerHud : MonoBehaviour
{
m_ShutdownButton.clickable.clickedWithEventInfo -= ShutdownButtonClicked;
}
m_NetworkManager.OnClientConnectedCallback -= OnOnClientConnectedCallback;
m_NetworkManager.OnClientDisconnectCallback -= OnOnClientDisconnectCallback;
m_NetworkManager.OnConnectionEvent -= OnConnectionEvent;
}
}

Просмотреть файл

@ -141,7 +141,6 @@ public class ShipControl : NetworkBehaviour
if (IsServer)
{
LatestShipColor.Value = m_ShipGlowDefaultColor;
PlayerName.Value = $"Player {OwnerClientId}";
if (!IsHost)
@ -199,7 +198,7 @@ public class ShipControl : NetworkBehaviour
void Fire(Vector3 direction)
{
PlayFireSoundClientRpc();
ClientPlayFireSoundRpc();
var damage = 5;
if (QuadDamageTimer.Value > NetworkManager.ServerTime.TimeAsFloat)
{
@ -366,7 +365,7 @@ public class ShipControl : NetworkBehaviour
if (m_OldMoveForce != moveForce || m_OldSpin != spin)
{
ThrustServerRpc(moveForce, spin);
ServerThrustRpc(moveForce, spin);
m_OldMoveForce = moveForce;
m_OldSpin = spin;
}
@ -388,7 +387,7 @@ public class ShipControl : NetworkBehaviour
// fire
if (Input.GetKeyDown(KeyCode.Space))
{
FireServerRpc();
ServerFireRpc();
}
}
@ -505,22 +504,22 @@ public class ShipControl : NetworkBehaviour
// --- ClientRPCs ---
[ClientRpc]
void PlayFireSoundClientRpc()
[Rpc(SendTo.ClientsAndHost)]
void ClientPlayFireSoundRpc()
{
fireSound.Play();
}
// --- ServerRPCs ---
[ServerRpc]
public void ThrustServerRpc(float thrusting, int spin)
[Rpc(SendTo.Server)]
public void ServerThrustRpc(float thrusting, int spin)
{
m_Thrust = thrusting;
m_Spin = spin;
}
[ServerRpc]
public void FireServerRpc()
[Rpc(SendTo.Server)]
public void ServerFireRpc()
{
if (Energy.Value >= 10)
{
@ -549,8 +548,8 @@ public class ShipControl : NetworkBehaviour
}
}
[ServerRpc]
public void SetNameServerRpc(string name)
[Rpc(SendTo.Server)]
public void ServerSetNameRpc(FixedString32Bytes name)
{
PlayerName.Value = name;
}

Просмотреть файл

@ -7,7 +7,7 @@
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.ide.vscode": "1.2.5",
"com.unity.multiplayer.samples.coop": "https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop.git?path=/Packages/com.unity.multiplayer.samples.coop#v2.4.0",
"com.unity.netcode.gameobjects": "1.7.1",
"com.unity.netcode.gameobjects": "1.8.1",
"com.unity.postprocessing": "3.2.2",
"com.unity.render-pipelines.universal": "14.0.9",
"com.unity.test-framework": "1.1.33",

Просмотреть файл

@ -124,7 +124,7 @@
"url": "https://packages.unity.com"
},
"com.unity.netcode.gameobjects": {
"version": "1.7.1",
"version": "1.8.1",
"depth": 0,
"source": "registry",
"dependencies": {

Просмотреть файл

@ -24,6 +24,9 @@
- upgraded to com.unity.services.qos v1.3.0
- upgraded to com.unity.transport v1.4.1
- upgraded to com.unity.services.core v1.12.5
- Upgraded to Netcode for GameObjects v1.8.1 (#174)
- Upgraded to the newer API for Rpcs, Universal Rpcs
- Upgraded to newer API for Connection Events, OnConnectionEvent
#### Fixed
- Reset values and buffs after respawn of ship (#167)