From a7d367ea80a38065c598408e1d941319d47506a2 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Wed, 26 Feb 2025 09:22:38 -0500 Subject: [PATCH] fix(HexSpatialHash): Renamed example scripts --- .../Scripts/Hex3DNetworkManager.cs | 70 +++++++++++++++++++ ...er.cs.meta => Hex3DNetworkManager.cs.meta} | 0 .../HexSpatialHash/Scripts/Hex3DPlayer.cs | 47 +++++++++++++ ...{HexPlayer.cs.meta => Hex3DPlayer.cs.meta} | 0 .../Scripts/HexNetworkManager.cs | 69 ------------------ .../HexSpatialHash/Scripts/HexPlayer.cs | 44 ------------ 6 files changed, 117 insertions(+), 113 deletions(-) create mode 100644 Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DNetworkManager.cs rename Assets/Mirror/Examples/HexSpatialHash/Scripts/{HexNetworkManager.cs.meta => Hex3DNetworkManager.cs.meta} (100%) create mode 100644 Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DPlayer.cs rename Assets/Mirror/Examples/HexSpatialHash/Scripts/{HexPlayer.cs.meta => Hex3DPlayer.cs.meta} (100%) delete mode 100644 Assets/Mirror/Examples/HexSpatialHash/Scripts/HexNetworkManager.cs delete mode 100644 Assets/Mirror/Examples/HexSpatialHash/Scripts/HexPlayer.cs diff --git a/Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DNetworkManager.cs b/Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DNetworkManager.cs new file mode 100644 index 0000000000..f9bd2db04d --- /dev/null +++ b/Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DNetworkManager.cs @@ -0,0 +1,70 @@ +using System; +using UnityEngine; + +namespace Mirror.Examples.Hex3D +{ + [AddComponentMenu("")] + public class Hex3DNetworkManager : NetworkManager + { + // Overrides the base singleton so we don't have to cast to this type everywhere. + public static new Hex3DNetworkManager singleton => (Hex3DNetworkManager)NetworkManager.singleton; + + [Header("Spawns")] + public GameObject spawnPrefab; + + [Range(1, 8000)] + public ushort spawnPrefabsCount = 1000; + + [Range(1, 10)] + public byte spawnPrefabSpacing = 3; + + public override void OnValidate() + { + if (Application.isPlaying) return; + base.OnValidate(); + + // Adjust spawnPrefabsCount to have an even cube root + ushort cubeRoot = (ushort)Mathf.Pow(spawnPrefabsCount, 1f / 3f); + spawnPrefabsCount = (ushort)(Mathf.Pow(cubeRoot, 3f)); + } + + public override void OnStartClient() + { + NetworkClient.RegisterPrefab(spawnPrefab); + } + + public override void OnStartServer() + { + // instantiate an empty GameObject + GameObject Spawns = new GameObject("Spawns"); + Transform SpawnsTransform = Spawns.transform; + + int spawned = 0; + + // Spawn prefabs in a cube grid centered around origin (0,0,0) + float cubeRoot = Mathf.Pow(spawnPrefabsCount, 1f / 3f); + int gridSize = Mathf.RoundToInt(cubeRoot); + + // Calculate the starting position to center the grid + float startX = -(gridSize - 1) * spawnPrefabSpacing * 0.5f; + float startY = -(gridSize - 1) * spawnPrefabSpacing * 0.5f; + float startZ = -(gridSize - 1) * spawnPrefabSpacing * 0.5f; + + //Debug.Log($"Start Positions: X={startX}, Y={startY}, Z={startZ}, gridSize={gridSize}"); + + for (int x = 0; x < gridSize; ++x) + for (int y = 0; y < gridSize; ++y) + for (int z = 0; z < gridSize; ++z) + if (spawned < spawnPrefabsCount) + { + float x1 = startX + x * spawnPrefabSpacing; + float y1 = startY + y * spawnPrefabSpacing; + float z1 = startZ + z * spawnPrefabSpacing; + Vector3 position = new Vector3(x1, y1, z1); + + NetworkServer.Spawn(Instantiate(spawnPrefab, position, Quaternion.identity, SpawnsTransform)); + ++spawned; + } + } + } +} diff --git a/Assets/Mirror/Examples/HexSpatialHash/Scripts/HexNetworkManager.cs.meta b/Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DNetworkManager.cs.meta similarity index 100% rename from Assets/Mirror/Examples/HexSpatialHash/Scripts/HexNetworkManager.cs.meta rename to Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DNetworkManager.cs.meta diff --git a/Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DPlayer.cs b/Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DPlayer.cs new file mode 100644 index 0000000000..b8c2f90983 --- /dev/null +++ b/Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DPlayer.cs @@ -0,0 +1,47 @@ +using UnityEngine; +using Mirror; + +namespace Mirror.Examples.Hex3D +{ + [AddComponentMenu("")] + public class Hex3DPlayer : NetworkBehaviour + { + [Range(1, 20)] + public float speed = 10; + + void Update() + { + if (!isLocalPlayer) return; + + float h = Input.GetAxis("Horizontal"); + float v = Input.GetAxis("Vertical"); + + // if left shift is held, apply v to y instead of z + if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) + { + Vector3 dir = new Vector3(h, v, 0); + transform.position += dir.normalized * (Time.deltaTime * speed); + } + else + { + Vector3 dir = new Vector3(h, 0, v); + transform.position += dir.normalized * (Time.deltaTime * speed); + } + + if (Input.GetKey(KeyCode.Q)) + transform.Rotate(Vector3.up, -90 * Time.deltaTime); + if (Input.GetKey(KeyCode.E)) + transform.Rotate(Vector3.up, 90 * Time.deltaTime); + } + + void OnGUI() + { + if (isLocalPlayer) + { + GUILayout.BeginArea(new Rect(10, Screen.height - 50, 300, 300)); + GUILayout.Label("Use WASD+QE to move and rotate\nHold Shift with W/S to move up/down"); + GUILayout.EndArea(); + } + } + } +} diff --git a/Assets/Mirror/Examples/HexSpatialHash/Scripts/HexPlayer.cs.meta b/Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DPlayer.cs.meta similarity index 100% rename from Assets/Mirror/Examples/HexSpatialHash/Scripts/HexPlayer.cs.meta rename to Assets/Mirror/Examples/HexSpatialHash/Scripts/Hex3DPlayer.cs.meta diff --git a/Assets/Mirror/Examples/HexSpatialHash/Scripts/HexNetworkManager.cs b/Assets/Mirror/Examples/HexSpatialHash/Scripts/HexNetworkManager.cs deleted file mode 100644 index 1bd05616bd..0000000000 --- a/Assets/Mirror/Examples/HexSpatialHash/Scripts/HexNetworkManager.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using UnityEngine; -using UnityEngine.SceneManagement; -using Mirror; - -[AddComponentMenu("")] -public class HexNetworkManager : NetworkManager -{ - // Overrides the base singleton so we don't have to cast to this type everywhere. - public static new HexNetworkManager singleton => (HexNetworkManager)NetworkManager.singleton; - - [Header("Spawns")] - public GameObject spawnPrefab; - - [Range(1, 8000)] - public ushort spawnPrefabsCount = 1000; - - [Range(1, 10)] - public byte spawnPrefabSpacing = 3; - - public override void OnValidate() - { - if (Application.isPlaying) return; - base.OnValidate(); - - // Adjust spawnPrefabsCount to have an even cube root - ushort cubeRoot = (ushort)Mathf.Pow(spawnPrefabsCount, 1f / 3f); - spawnPrefabsCount = (ushort)(Mathf.Pow(cubeRoot, 3f)); - } - - public override void OnStartClient() - { - NetworkClient.RegisterPrefab(spawnPrefab); - } - - public override void OnStartServer() - { - // instantiate an empty GameObject - GameObject Spawns = new GameObject("Spawns"); - Transform SpawnsTransform = Spawns.transform; - - int spawned = 0; - - // Spawn prefabs in a cube grid centered around origin (0,0,0) - float cubeRoot = Mathf.Pow(spawnPrefabsCount, 1f / 3f); - int gridSize = Mathf.RoundToInt(cubeRoot); - - // Calculate the starting position to center the grid - float startX = -(gridSize - 1) * spawnPrefabSpacing * 0.5f; - float startY = -(gridSize - 1) * spawnPrefabSpacing * 0.5f; - float startZ = -(gridSize - 1) * spawnPrefabSpacing * 0.5f; - - //Debug.Log($"Start Positions: X={startX}, Y={startY}, Z={startZ}, gridSize={gridSize}"); - - for (int x = 0; x < gridSize; ++x) - for (int y = 0; y < gridSize; ++y) - for (int z = 0; z < gridSize; ++z) - if (spawned < spawnPrefabsCount) - { - float x1 = startX + x * spawnPrefabSpacing; - float y1 = startY + y * spawnPrefabSpacing; - float z1 = startZ + z * spawnPrefabSpacing; - Vector3 position = new Vector3(x1, y1, z1); - - NetworkServer.Spawn(Instantiate(spawnPrefab, position, Quaternion.identity, SpawnsTransform)); - ++spawned; - } - } -} diff --git a/Assets/Mirror/Examples/HexSpatialHash/Scripts/HexPlayer.cs b/Assets/Mirror/Examples/HexSpatialHash/Scripts/HexPlayer.cs deleted file mode 100644 index 0fe4893da9..0000000000 --- a/Assets/Mirror/Examples/HexSpatialHash/Scripts/HexPlayer.cs +++ /dev/null @@ -1,44 +0,0 @@ -using UnityEngine; -using Mirror; - -[AddComponentMenu("")] -public class HexPlayer : NetworkBehaviour -{ - [Range(1, 20)] - public float speed = 10; - - void Update() - { - if (!isLocalPlayer) return; - - float h = Input.GetAxis("Horizontal"); - float v = Input.GetAxis("Vertical"); - - // if left shift is held, apply v to y instead of z - if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) - { - Vector3 dir = new Vector3(h, v, 0); - transform.position += dir.normalized * (Time.deltaTime * speed); - } - else - { - Vector3 dir = new Vector3(h, 0, v); - transform.position += dir.normalized * (Time.deltaTime * speed); - } - - if (Input.GetKey(KeyCode.Q)) - transform.Rotate(Vector3.up, -90 * Time.deltaTime); - if (Input.GetKey(KeyCode.E)) - transform.Rotate(Vector3.up, 90 * Time.deltaTime); - } - - void OnGUI() - { - if (isLocalPlayer) - { - GUILayout.BeginArea(new Rect(10, Screen.height - 50, 300, 300)); - GUILayout.Label("Use WASD+QE to move and rotate\nHold Shift with W/S to move up/down"); - GUILayout.EndArea(); - } - } -}