diff --git a/Netick/Editor/Netick.Unity.Editor.dll b/Netick/Editor/Netick.Unity.Editor.dll index e21669c..4cfe483 100644 Binary files a/Netick/Editor/Netick.Unity.Editor.dll and b/Netick/Editor/Netick.Unity.Editor.dll differ diff --git a/Netick/Editor/Netick.Unity.Pro.Editor.dll b/Netick/Editor/Netick.Unity.Pro.Editor.dll index c743bb1..31db0ff 100644 Binary files a/Netick/Editor/Netick.Unity.Pro.Editor.dll and b/Netick/Editor/Netick.Unity.Pro.Editor.dll differ diff --git a/Netick/Editor/Unity.Netick.CodeGen.dll b/Netick/Editor/Unity.Netick.CodeGen.dll index 3fe6db9..dab5a5c 100644 Binary files a/Netick/Editor/Unity.Netick.CodeGen.dll and b/Netick/Editor/Unity.Netick.CodeGen.dll differ diff --git a/Netick/Runtime/Netick.Unity.Pro.dll b/Netick/Runtime/Netick.Unity.Pro.dll index f3e0517..5d025dd 100644 Binary files a/Netick/Runtime/Netick.Unity.Pro.dll and b/Netick/Runtime/Netick.Unity.Pro.dll differ diff --git a/Netick/Runtime/Netick.Unity.dll b/Netick/Runtime/Netick.Unity.dll index cd1d672..14bbc2d 100644 Binary files a/Netick/Runtime/Netick.Unity.dll and b/Netick/Runtime/Netick.Unity.dll differ diff --git a/Scripts/PlayerSpawner.cs b/Scripts/PlayerSpawner.cs new file mode 100644 index 0000000..065aee5 --- /dev/null +++ b/Scripts/PlayerSpawner.cs @@ -0,0 +1,37 @@ +using Netick; +using Netick.Unity; +using UnityEngine; + +/// +/// This is a helper script for quick prototyping, used to spawn/despawn a player prefab when a player (client or host) has connected/disconnected. +/// +[AddComponentMenu("Netick/Player Spawner")] +public class PlayerSpawner : NetworkEventsListener +{ + public GameObject PlayerPrefab; + public Transform SpawnPosition; + public float HorizontalOffset = 5f; + public bool StaggerSpawns = true; + public bool DestroyPlayerObjectWhenLeaving = true; + + // This is called on the server when a player has connected. + public override void OnPlayerConnected(NetworkSandbox sandbox, Netick.NetworkPlayer client) + { + var spawnPos = SpawnPosition.position; + if (StaggerSpawns) + spawnPos += (HorizontalOffset * Vector3.left) * (1 + sandbox.ConnectedPlayers.Count); + var player = sandbox.NetworkInstantiate(PlayerPrefab, spawnPos, SpawnPosition.rotation, client); + client.PlayerObject = player; + } + + // This is called on the server when a player has disconnected. + public override void OnPlayerDisconnected(NetworkSandbox sandbox, Netick.NetworkPlayer client, TransportDisconnectReason transportDisconnectReason) + { + if (!DestroyPlayerObjectWhenLeaving) + return; + + var netObj = client.PlayerObject as NetworkObject; + if (netObj != null) + Sandbox.Destroy(netObj); + } +} \ No newline at end of file diff --git a/Scripts/PlayerSpawner.cs.meta b/Scripts/PlayerSpawner.cs.meta new file mode 100644 index 0000000..ea14840 --- /dev/null +++ b/Scripts/PlayerSpawner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13d95c28de1bac54f8b26fc8dd960077 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index 2e9a90f..7d8dfe0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.karrar.netick", - "version": "0.13.15", + "version": "0.13.16", "displayName": "Netick", "description": "A networking solution for Unity", "unity": "2021.3",