This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/FishNet/Runtime/Serializing/Helping/Broadcasts.cs

38 lines
1.2 KiB
C#
Raw Normal View History

2023-05-31 17:32:21 +02:00
using FishNet.Managing.Scened;
using FishNet.Managing.Server;
using FishNet.Object.Helping;
using FishNet.Transporting;
using UnityEngine;
namespace FishNet.Serializing.Helping
{
internal static class Broadcasts
{
/// <summary>
/// Writes a broadcast to writer.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="writer"></param>
/// <param name="message"></param>
/// <param name="channel"></param>
/// <returns></returns>
internal static PooledWriter WriteBroadcast<T>(PooledWriter writer, T message, Channel channel)
{
writer.WritePacketId(PacketId.Broadcast);
writer.WriteUInt16(typeof(T).FullName.GetStableHash16()); //muchlater codegen this to pass in hash. use technique similar to rpcs to limit byte/shorts.
//Write data to a new writer.
PooledWriter dataWriter = WriterPool.GetWriter();
dataWriter.Write<T>(message);
//Write length of data.
writer.WriteLength(dataWriter.Length);
//Write data.
writer.WriteArraySegment(dataWriter.GetArraySegment());
dataWriter.Dispose();
return writer;
}
}
}