-
Notifications
You must be signed in to change notification settings - Fork 1
/
NetworkNameState.cs
36 lines (32 loc) · 1.16 KB
/
NetworkNameState.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
namespace Unity.BossRoom.Utils
{
/// <summary>
/// NetworkBehaviour containing only one NetworkVariableString which represents this object's name.
/// </summary>
public class NetworkNameState : NetworkBehaviour
{
[HideInInspector]
public NetworkVariable<FixedPlayerName> Name = new NetworkVariable<FixedPlayerName>();
}
/// <summary>
/// Wrapping FixedString so that if we want to change player name max size in the future, we only do it once here
/// </summary>
public struct FixedPlayerName : INetworkSerializable
{
FixedString32Bytes m_Name;
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
serializer.SerializeValue(ref m_Name);
}
public override string ToString()
{
return m_Name.Value.ToString();
}
public static implicit operator string(FixedPlayerName s) => s.ToString();
public static implicit operator FixedPlayerName(string s) => new FixedPlayerName() { m_Name = new FixedString32Bytes(s) };
}
}