Create NetworkManager, Client, and Hud
This commit is contained in:
18
code/Client.cs
Normal file
18
code/Client.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using LuckerParty.UI;
|
||||
|
||||
namespace LuckerParty;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public sealed class Client : Component
|
||||
{
|
||||
public Connection Connection { get; set; }
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
GameObject.AddComponent<ScreenPanel>();
|
||||
GameObject.AddComponent<Hud>();
|
||||
}
|
||||
}
|
||||
18
code/NetworkManager.cs
Normal file
18
code/NetworkManager.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace LuckerParty;
|
||||
|
||||
/// <summary>
|
||||
/// Listens to Network events and creates Client GameObjects
|
||||
/// </summary>
|
||||
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>();
|
||||
client.Connection = channel;
|
||||
}
|
||||
}
|
||||
27
code/UI/Hud.razor
Normal file
27
code/UI/Hud.razor
Normal file
@@ -0,0 +1,27 @@
|
||||
@using System
|
||||
@inherits PanelComponent
|
||||
@namespace LuckerParty.UI
|
||||
|
||||
<root>
|
||||
<div class="title">Hello, @_name</div>
|
||||
</root>
|
||||
|
||||
@code
|
||||
{
|
||||
|
||||
private string _name;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
_name = GameObject.GetComponent<Client>().Connection.DisplayName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
|
||||
/// </summary>
|
||||
protected override int BuildHash()
|
||||
{
|
||||
return HashCode.Combine( _name );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user