You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB
C#

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) };
}
}