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
6 changes: 4 additions & 2 deletions Basic/ClientDriven/Assets/Scenes/Bootstrap.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.21890283, g: 0.16790575, b: 0.67034173, a: 1}
m_IndirectSpecularColor: {r: 0.21890238, g: 0.16790517, b: 0.6703396, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -925,6 +925,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 2084257867
InScenePlacedSourceGlobalObjectIdHash: 0
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1
ActiveSceneSynchronization: 0
Expand Down Expand Up @@ -1525,6 +1526,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 1374255023
InScenePlacedSourceGlobalObjectIdHash: 0
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1
ActiveSceneSynchronization: 0
Expand All @@ -1550,7 +1552,7 @@ MonoBehaviour:
- {fileID: 1422708175}
- {fileID: 796975752}
m_SpawnRatePerSecond: 10
m_IngredientPrefab: {fileID: 8321201880322001125, guid: a6b33b41508134c09957e076f4d53415, type: 3}
m_IngredientPrefab: {fileID: 5818429371130516787, guid: a6b33b41508134c09957e076f4d53415, type: 3}
m_MaxSpawnWaves: 8
--- !u!4 &2060465724
Transform:
Expand Down
13 changes: 8 additions & 5 deletions Basic/ClientDriven/Assets/Scripts/NetworkObjectSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Unity.Multiplayer.Samples.ClientDriven
/// <remarks>
/// A NetworkManager is expected to be part of the scene that this NetworkObject is a part of.
/// </remarks>
internal class NetworkObjectSpawner : MonoBehaviour
class NetworkObjectSpawner : MonoBehaviour
{
[SerializeField]
NetworkObject m_PrefabReference;
Expand All @@ -27,17 +27,20 @@ void Start()

void OnDestroy()
{
if(NetworkManager.Singleton != null)
{
if (NetworkManager.Singleton != null)
{
NetworkManager.Singleton.OnServerStarted -= SpawnIngredient;
}
}

void SpawnIngredient()
{
// Note: this will be converted to NetworkObject.InstantiateAndSpawn(), but a current limitation on Netcode
// for GameObjects invoking this method on OnServerStarted prevents this API upgrade.
// Specifically, if you were to spawn a Rigidbody with Rigidbody Interpolation enabled, you would need to
// update the Rigidbody's position immediately after invoking NetworkObject.InstantitateAndSpawn().
NetworkObject instantiatedNetworkObject = Instantiate(m_PrefabReference, transform.position, transform.rotation, null);
var ingredient = instantiatedNetworkObject.GetComponent<ServerIngredient>();
ingredient.NetworkObject.Spawn();
instantiatedNetworkObject.Spawn();
}
}
}
14 changes: 7 additions & 7 deletions Basic/ClientDriven/Assets/Scripts/ServerIngredientSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ServerIngredientSpawner : NetworkBehaviour
float m_SpawnRatePerSecond;

[SerializeField]
GameObject m_IngredientPrefab;
NetworkObject m_IngredientPrefab;

[SerializeField]
int m_MaxSpawnWaves;
Expand All @@ -26,9 +26,9 @@ public class ServerIngredientSpawner : NetworkBehaviour
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
enabled = IsServer;
if (!IsServer)
{
enabled = false;
return;
}

Expand All @@ -38,11 +38,12 @@ public override void OnNetworkSpawn()
public override void OnNetworkDespawn()
{
m_SpawnWaves = 0;
enabled = false;
}

void FixedUpdate()
{
if (NetworkManager != null && !IsServer)
if (NetworkManager == null || !NetworkManager.IsListening || !IsServer)
{
return;
}
Expand All @@ -51,11 +52,10 @@ void FixedUpdate()
{
foreach (var spawnPoint in m_SpawnPoints)
{
var newIngredientObject = Instantiate(m_IngredientPrefab, spawnPoint.transform.position, spawnPoint.transform.rotation);
newIngredientObject.transform.position = spawnPoint.transform.position +
new Vector3(UnityEngine.Random.Range(-0.25f, 0.25f), 0, UnityEngine.Random.Range(-0.25f, 0.25f));
var newIngredientObject = m_IngredientPrefab.InstantiateAndSpawn(NetworkManager,
position: spawnPoint.transform.position + new Vector3(UnityEngine.Random.Range(-0.25f, 0.25f), 0, UnityEngine.Random.Range(-0.25f, 0.25f)),
rotation: spawnPoint.transform.rotation);
var ingredient = newIngredientObject.GetComponent<ServerIngredient>();
ingredient.NetworkObject.Spawn();
ingredient.currentIngredientType.Value = (IngredientType)m_RandomGenerator.Next((int)IngredientType.MAX);
}
m_SpawnWaves++;
Expand Down
2 changes: 1 addition & 1 deletion Basic/ClientDriven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Client Driven

[![UnityVersion](https://img.shields.io/badge/Unity%20Version:-2022.3%20LTS-57b9d3.svg?logo=unity&color=2196F3)](https://unity.com/releases/editor/whats-new/2022.3.0)
[![NetcodeVersion](https://img.shields.io/badge/Netcode%20Version:-1.7.1-57b9d3.svg?logo=unity&color=2196F3)](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/releases/tag/ngo%2F1.7.1)
[![NetcodeVersion](https://img.shields.io/badge/Netcode%20Version:-1.8.1-57b9d3.svg?logo=unity&color=2196F3)](https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/releases/tag/ngo%2F1.8.1)
[![LatestRelease](https://img.shields.io/badge/Latest%20%20Github%20Release:-v1.5.0-57b9d3.svg?logo=github&color=brightgreen)](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize/releases/tag/v1.5.0)
<br><br>

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Upgraded to Netcode for GameObjects v1.8.1 (#164)
- Upgraded to the newer API for Rpcs, Universal Rpcs
- The place of execution for a client's position was moved to ClientNetworkTransform child class, ClientDrivenNetworkTransform. This ensures no race condition issues on a client's first position sync. Server code now modifies a NetworkVariable that client-owned instances of ClientDrivenNetworkTransform use on OnNetworkSpawn to initially move a player
- Upgraded to use NetworkObject.InstantiateAndSpawn() API where appropriate (#173)
- Upgraded to IDE Rider v3.0.28 (#166)
- Upgraded to Unity 2022.3.27f1 (#175)
- com.unity.render-pipelines.core upgraded to v14.0.11
Expand Down