Advertisement
TwinFrame

Example Net Message

Mar 18th, 2022
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using Unity.Networking.Transport;
  2. using UnityEngine;
  3.  
  4. public class NetOption : NetMessage
  5. {
  6.     public int Option { get; private set; }
  7.  
  8.     public NetOption(int option)
  9.     {
  10.         Code = OpCode.OPTION;
  11.         Option = option;
  12.     }
  13.  
  14.     public NetOption(DataStreamReader reader)
  15.     {
  16.         Code = OpCode.OPTION;
  17.         Deserialize(reader);
  18.     }
  19.  
  20.     public override void Serialize(ref DataStreamWriter writer)
  21.     {
  22.         writer.WriteByte((byte)Code);
  23.         writer.WriteInt(Option);
  24.     }
  25.  
  26.     public override void Deserialize(DataStreamReader reader)
  27.     {
  28.         Option = reader.ReadInt();
  29.     }
  30.  
  31.     public override void RecievedOnClient()
  32.     {
  33.         NetUtility.C_OPTION?.Invoke(this);
  34.     }
  35.  
  36.     public override void RecievedOnServer(NetworkConnection networkConnection)
  37.     {
  38.         NetUtility.S_OPTION?.Invoke(this, networkConnection);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement