您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

36 行
1.2 KiB

using System;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
namespace Unity.Multiplayer.Samples.BossRoom
{
/// <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) };
}
}