From 186c2e186e3adf6bc2c11635a4343749b7df90ea Mon Sep 17 00:00:00 2001 From: para Date: Sun, 22 Dec 2024 05:56:05 -0800 Subject: [PATCH] Create NetworkManager, Client, and Hud --- Assets/prefabs/player.prefab | 179 ++++++++++++++++++++++++++++++ Assets/prefabs/spawn_point.prefab | 22 ++++ code/Client.cs | 18 +++ code/NetworkManager.cs | 18 +++ code/UI/Hud.razor | 27 +++++ lucker_party.sln.DotSettings.user | 12 ++ 6 files changed, 276 insertions(+) create mode 100644 Assets/prefabs/player.prefab create mode 100644 Assets/prefabs/spawn_point.prefab create mode 100644 code/Client.cs create mode 100644 code/NetworkManager.cs create mode 100644 code/UI/Hud.razor create mode 100644 lucker_party.sln.DotSettings.user diff --git a/Assets/prefabs/player.prefab b/Assets/prefabs/player.prefab new file mode 100644 index 0000000..65e8417 --- /dev/null +++ b/Assets/prefabs/player.prefab @@ -0,0 +1,179 @@ +{ + "RootObject": { + "__guid": "226bae44-5ffa-4e59-8314-fb7704d99792", + "Flags": 0, + "Name": "Player Controller", + "Position": "-200.7519,-55.49498,1.470044", + "Enabled": true, + "Components": [ + { + "__type": "Sandbox.PlayerController", + "__guid": "f87ac628-ba1d-4ea4-ad35-061fbdd92fbc", + "AimStrengthBody": 1, + "AimStrengthEyes": 1, + "AimStrengthHead": 1, + "Body": { + "_type": "component", + "component_id": "3b090c90-c4ba-48dc-945e-46457cb453b1", + "go": "226bae44-5ffa-4e59-8314-fb7704d99792", + "component_type": "Rigidbody" + }, + "BodyHeight": 72, + "BodyMass": 500, + "BodyRadius": 16, + "CameraOffset": "256,0,12", + "ColliderObject": { + "_type": "gameobject", + "go": "f45df165-faec-47b8-9e73-d2d0d1d94660" + }, + "DuckedHeight": 36, + "DuckedSpeed": 70, + "EnableFootstepSounds": true, + "EnablePressing": true, + "EyeDistanceFromTop": 8, + "FootstepMixer": { + "Name": "unknown", + "Id": "00000000-0000-0000-0000-000000000000" + }, + "FootstepVolume": 1, + "HideBodyInFirstPerson": true, + "JumpSpeed": 300, + "ReachLength": 130, + "Renderer": { + "_type": "component", + "component_id": "5ff01433-a4b1-4ac0-9437-20f18966c556", + "go": "e98ba887-3414-4817-a78a-8004711774c5", + "component_type": "SkinnedModelRenderer" + }, + "RotateWithGround": true, + "RotationAngleLimit": 45, + "RotationSpeed": 1, + "RunSpeed": 320, + "ShowColliderComponents": false, + "ShowRigidbodyComponent": false, + "ThirdPerson": true, + "ToggleCameraModeButton": "view", + "UseAnimatorControls": true, + "UseButton": "use", + "UseCameraControls": true, + "UseInputControls": true, + "WalkSpeed": 110 + }, + { + "__type": "Sandbox.Rigidbody", + "__guid": "3b090c90-c4ba-48dc-945e-46457cb453b1", + "AngularDamping": 1, + "Gravity": true, + "LinearDamping": 0.1, + "Locking": { + "X": false, + "Y": false, + "Z": false, + "Pitch": true, + "Yaw": true, + "Roll": true + }, + "MassCenterOverride": "0,0,36", + "MassOverride": 500, + "MotionEnabled": true, + "OverrideMassCenter": true, + "RigidbodyFlags": "DisableCollisionSounds", + "StartAsleep": false + }, + { + "__type": "Sandbox.Movement.MoveModeWalk", + "__guid": "063da125-6f28-49be-96cd-da5b52cb4007", + "GroundAngle": 45, + "Priority": 0, + "StepDownHeight": 18, + "StepUpHeight": 18 + }, + { + "__type": "Sandbox.Movement.MoveModeSwim", + "__guid": "72adfaa2-8d48-4eee-9037-16b57c737aaf", + "Priority": 10, + "SwimLevel": 0.7 + }, + { + "__type": "Sandbox.Movement.MoveModeLadder", + "__guid": "bb0f3a51-8973-4f40-af23-60c7c2d1f479", + "ClimbableTags": "ladder", + "Priority": 5 + } + ], + "Children": [ + { + "__guid": "e98ba887-3414-4817-a78a-8004711774c5", + "Flags": 0, + "Name": "Body", + "Enabled": true, + "Components": [ + { + "__type": "Sandbox.SkinnedModelRenderer", + "__guid": "5ff01433-a4b1-4ac0-9437-20f18966c556", + "BodyGroups": 341, + "CreateAttachments": false, + "CreateBoneObjects": false, + "Model": "models/citizen/citizen.vmdl", + "Morphs": {}, + "Parameters": { + "bools": {}, + "ints": {}, + "floats": {}, + "vectors": {}, + "rotations": {} + }, + "RenderOptions": { + "GameLayer": true, + "OverlayLayer": false, + "BloomLayer": false, + "AfterUILayer": false + }, + "RenderType": "On", + "Sequence": { + "Name": null + }, + "Tint": "1,1,1,1", + "UseAnimGraph": true + } + ] + }, + { + "__guid": "f45df165-faec-47b8-9e73-d2d0d1d94660", + "Flags": 1, + "Name": "Colliders", + "Enabled": true, + "Components": [ + { + "__type": "Sandbox.CapsuleCollider", + "__guid": "5d2196ca-4be8-4fb2-84af-09d1e9b29b30", + "End": "0,0,45.05097", + "Friction": 0, + "IsTrigger": false, + "Radius": 11.313708, + "Start": "0,0,60.68629", + "Static": false, + "SurfaceVelocity": "0,0,0" + }, + { + "__type": "Sandbox.BoxCollider", + "__guid": "73ed41e5-51cc-4ee4-aac2-87df6bd120c3", + "Center": "0,0,18", + "Friction": 0, + "IsTrigger": false, + "Scale": "16,16,36", + "Static": false, + "SurfaceVelocity": "0,0,0" + } + ] + } + ] + }, + "ShowInMenu": false, + "MenuPath": null, + "MenuIcon": null, + "DontBreakAsTemplate": false, + "ResourceVersion": 1, + "__references": [], + "__version": 1 +} \ No newline at end of file diff --git a/Assets/prefabs/spawn_point.prefab b/Assets/prefabs/spawn_point.prefab new file mode 100644 index 0000000..edebbc7 --- /dev/null +++ b/Assets/prefabs/spawn_point.prefab @@ -0,0 +1,22 @@ +{ + "RootObject": { + "__guid": "15c44ba2-0e41-4b18-a7fa-6aeeca6b546b", + "Flags": 0, + "Name": "Spawn Point", + "Enabled": true, + "Components": [ + { + "__type": "Sandbox.SpawnPoint", + "__guid": "e86b1cd6-90b3-45f5-a809-1ed7055fb3f9", + "Color": "0.8902,0.31765,0.05098,1" + } + ] + }, + "ShowInMenu": false, + "MenuPath": null, + "MenuIcon": null, + "DontBreakAsTemplate": false, + "ResourceVersion": 1, + "__references": [], + "__version": 1 +} \ No newline at end of file diff --git a/code/Client.cs b/code/Client.cs new file mode 100644 index 0000000..967dcf7 --- /dev/null +++ b/code/Client.cs @@ -0,0 +1,18 @@ +using LuckerParty.UI; + +namespace LuckerParty; + +/// +/// A Lucker Party Client. Entry point for a user (or bot?) to get a UI and become a Spectator or Lucker after they've +/// connected to the lobby. +/// +public sealed class Client : Component +{ + public Connection Connection { get; set; } + + protected override void OnStart() + { + GameObject.AddComponent(); + GameObject.AddComponent(); + } +} diff --git a/code/NetworkManager.cs b/code/NetworkManager.cs new file mode 100644 index 0000000..5422802 --- /dev/null +++ b/code/NetworkManager.cs @@ -0,0 +1,18 @@ +namespace LuckerParty; + +/// +/// Listens to Network events and creates Client GameObjects +/// +public sealed class NetworkManager : Component, Component.INetworkListener +{ + [Property] private GameObject ClientGroup { get; set; } + + public void OnActive( Connection channel ) + { + var gameObject = new GameObject( ClientGroup ) { Name = $"{channel.DisplayName} ({channel.SteamId})" }; + gameObject.NetworkSpawn( channel ); + + var client = gameObject.AddComponent(); + client.Connection = channel; + } +} diff --git a/code/UI/Hud.razor b/code/UI/Hud.razor new file mode 100644 index 0000000..8548b51 --- /dev/null +++ b/code/UI/Hud.razor @@ -0,0 +1,27 @@ +@using System +@inherits PanelComponent +@namespace LuckerParty.UI + + +
Hello, @_name
+
+ +@code +{ + + private string _name; + + protected override void OnAwake() + { + base.OnAwake(); + _name = GameObject.GetComponent().Connection.DisplayName; + } + + /// + /// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt + /// + protected override int BuildHash() + { + return HashCode.Combine( _name ); + } +} diff --git a/lucker_party.sln.DotSettings.user b/lucker_party.sln.DotSettings.user new file mode 100644 index 0000000..ff392ab --- /dev/null +++ b/lucker_party.sln.DotSettings.user @@ -0,0 +1,12 @@ + + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + <AssemblyExplorer> + <Assembly Path="D:\SteamLibrary\steamapps\common\sbox\bin\managed\Sandbox.Game.dll" /> +</AssemblyExplorer> \ No newline at end of file