Пример #1
0
 protected virtual void SerializeKey(NetworkWriter writer, TKey item)
 {
 }
Пример #2
0
        // zigzag encoding https://gist.github.com/mfuerstenau/ba870a29e16536fdbaba
        public static void WritePackedInt64(this NetworkWriter writer, long i)
        {
            ulong zigzagged = (ulong)((i >> 63) ^ (i << 1));

            writer.WritePackedUInt64(zigzagged);
        }
Пример #3
0
 public static void WriteVector3(this NetworkWriter writer, Vector3 value)
 {
     writer.WriteSingle(value.x);
     writer.WriteSingle(value.y);
     writer.WriteSingle(value.z);
 }
Пример #4
0
 // Weaver needs a write function with just one byte[] parameter
 // (we don't name it .Write(byte[]) because it's really a WriteBytesAndSize since we write size / null info too)
 public static void WriteBytesAndSize(this NetworkWriter writer, byte[] buffer)
 {
     // buffer might be null, so we can't use .Length in that case
     writer.WriteBytesAndSize(buffer, 0, buffer != null ? buffer.Length : 0);
 }
Пример #5
0
        // zigzag encoding https://gist.github.com/mfuerstenau/ba870a29e16536fdbaba
        public static void WritePackedInt32(this NetworkWriter writer, int i)
        {
            uint zigzagged = (uint)((i >> 31) ^ (i << 1));

            writer.WritePackedUInt32(zigzagged);
        }
Пример #6
0
 public static void WriteChar(this NetworkWriter writer, char value) => writer.WriteUInt16((ushort)value);
Пример #7
0
 public static void WriteUInt16(this NetworkWriter writer, ushort value)
 {
     writer.WriteByte((byte)(value & 0xFF));
     writer.WriteByte((byte)(value >> 8));
 }
Пример #8
0
        protected void SendTargetRPCInternal(NetworkConnection conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
        {
            if (!NetworkServer.active)
            {
                Debug.LogError($"TargetRPC {rpcName} called when server not active");
                return;
            }

            if (!isServer)
            {
                Debug.LogWarning($"TargetRpc {rpcName} called on {name} but that object has not been spawned or has been unspawned");
                return;
            }

            // connection parameter is optional. assign if null.
            if (conn is null)
            {
                conn = connectionToClient;
            }

            // if still null
            if (conn is null)
            {
                Debug.LogError($"TargetRPC {rpcName} was given a null connection, make sure the object has an owner or you pass in the target connection");
                return;
            }

            if (!(conn is NetworkConnectionToClient))
            {
                Debug.LogError($"TargetRPC {rpcName} requires a NetworkConnectionToClient but was given {conn.GetType().Name}");
                return;
            }

            // construct the message
            RpcMessage message = new RpcMessage
            {
                netId          = netId,
                componentIndex = (byte)ComponentIndex,
                // type+func so Inventory.RpcUse != Equipment.RpcUse
                functionHash = RemoteCallHelper.GetMethodHash(invokeClass, rpcName),
                // segment to avoid reader allocations
                payload = writer.ToArraySegment()
            };

            conn.Send(message, channelId);
        }
Пример #9
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedInt32(value);
 }
Пример #10
0
 protected virtual void SerializeItem(NetworkWriter writer, T item)
 {
 }
Пример #11
0
 protected override void SerializeItem(NetworkWriter writer, string item) => writer.WriteString(item);
Пример #12
0
 protected override void SerializeItem(NetworkWriter writer, bool item) => writer.WriteBoolean(item);
Пример #13
0
 protected override void SerializeItem(NetworkWriter writer, uint item) => writer.WritePackedUInt32(item);
Пример #14
0
 protected override void SerializeItem(NetworkWriter writer, float item) => writer.WriteSingle(item);
Пример #15
0
 public static void WriteByte(this NetworkWriter writer, byte value) => writer.WriteByte(value);
Пример #16
0
 public override void Serialize(NetworkWriter writer)
 {
 }
Пример #17
0
 public static void WriteSByte(this NetworkWriter writer, sbyte value) => writer.WriteByte((byte)value);
Пример #18
0
 // Serialize the contents of this message into the writer
 public virtual void Serialize(NetworkWriter writer)
 {
 }
Пример #19
0
 public static void WriteBoolean(this NetworkWriter writer, bool value) => writer.WriteByte((byte)(value ? 1 : 0));
Пример #20
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32(netId);
     writer.Write(authority);
 }
Пример #21
0
 public static void WriteInt16(this NetworkWriter writer, short value) => writer.WriteUInt16((ushort)value);
Пример #22
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WritePackedUInt32(netId);
     writer.WriteBytesAndSize(payload);
 }
Пример #23
0
 public static void WriteBytesAndSizeSegment(this NetworkWriter writer, ArraySegment <byte> buffer)
 {
     writer.WriteBytesAndSize(buffer.Array, buffer.Offset, buffer.Count);
 }
Пример #24
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.Write(clientTime);
     writer.Write(serverTime);
 }
Пример #25
0
 // http://sqlite.org/src4/doc/trunk/www/varint.wiki
 public static void WritePackedUInt32(this NetworkWriter writer, uint value)
 {
     // for 32 bit values WritePackedUInt64 writes the
     // same exact thing bit by bit
     writer.WritePackedUInt64(value);
 }
Пример #26
0
 public override void Serialize(NetworkWriter writer)
 {
     writer.WriteBytesAndSize(value);
 }
Пример #27
0
        public static void WritePackedUInt64(this NetworkWriter writer, ulong value)
        {
            if (value <= 240)
            {
                writer.WriteByte((byte)value);
                return;
            }
            if (value <= 2287)
            {
                writer.WriteByte((byte)(((value - 240) >> 8) + 241));
                writer.WriteByte((byte)((value - 240) & 0xFF));
                return;
            }
            if (value <= 67823)
            {
                writer.WriteByte((byte)249);
                writer.WriteByte((byte)((value - 2288) >> 8));
                writer.WriteByte((byte)((value - 2288) & 0xFF));
                return;
            }
            if (value <= 16777215)
            {
                writer.WriteByte((byte)250);
                writer.WriteByte((byte)(value & 0xFF));
                writer.WriteByte((byte)((value >> 8) & 0xFF));
                writer.WriteByte((byte)((value >> 16) & 0xFF));
                return;
            }
            if (value <= 4294967295)
            {
                writer.WriteByte((byte)251);
                writer.WriteByte((byte)(value & 0xFF));
                writer.WriteByte((byte)((value >> 8) & 0xFF));
                writer.WriteByte((byte)((value >> 16) & 0xFF));
                writer.WriteByte((byte)((value >> 24) & 0xFF));
                return;
            }
            if (value <= 1099511627775)
            {
                writer.WriteByte((byte)252);
                writer.WriteByte((byte)(value & 0xFF));
                writer.WriteByte((byte)((value >> 8) & 0xFF));
                writer.WriteByte((byte)((value >> 16) & 0xFF));
                writer.WriteByte((byte)((value >> 24) & 0xFF));
                writer.WriteByte((byte)((value >> 32) & 0xFF));
                return;
            }
            if (value <= 281474976710655)
            {
                writer.WriteByte((byte)253);
                writer.WriteByte((byte)(value & 0xFF));
                writer.WriteByte((byte)((value >> 8) & 0xFF));
                writer.WriteByte((byte)((value >> 16) & 0xFF));
                writer.WriteByte((byte)((value >> 24) & 0xFF));
                writer.WriteByte((byte)((value >> 32) & 0xFF));
                writer.WriteByte((byte)((value >> 40) & 0xFF));
                return;
            }
            if (value <= 72057594037927935)
            {
                writer.WriteByte((byte)254);
                writer.WriteByte((byte)(value & 0xFF));
                writer.WriteByte((byte)((value >> 8) & 0xFF));
                writer.WriteByte((byte)((value >> 16) & 0xFF));
                writer.WriteByte((byte)((value >> 24) & 0xFF));
                writer.WriteByte((byte)((value >> 32) & 0xFF));
                writer.WriteByte((byte)((value >> 40) & 0xFF));
                writer.WriteByte((byte)((value >> 48) & 0xFF));
                return;
            }

            // all others
            {
                writer.WriteByte((byte)255);
                writer.WriteByte((byte)(value & 0xFF));
                writer.WriteByte((byte)((value >> 8) & 0xFF));
                writer.WriteByte((byte)((value >> 16) & 0xFF));
                writer.WriteByte((byte)((value >> 24) & 0xFF));
                writer.WriteByte((byte)((value >> 32) & 0xFF));
                writer.WriteByte((byte)((value >> 40) & 0xFF));
                writer.WriteByte((byte)((value >> 48) & 0xFF));
                writer.WriteByte((byte)((value >> 56) & 0xFF));
            }
        }
Пример #28
0
        protected void SendTargetRPCInternal(NetworkConnection conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
        {
            // this was in Weaver before
            if (!NetworkServer.active)
            {
                logger.LogError("TargetRPC Function " + rpcName + " called on client.");
                return;
            }
            // connection parameter is optional. assign if null.
            if (conn == null)
            {
                conn = connectionToClient;
            }
            // this was in Weaver before
            if (conn is NetworkConnectionToServer)
            {
                logger.LogError("TargetRPC Function " + rpcName + " called on connection to server");
                return;
            }
            // This cannot use NetworkServer.active, as that is not specific to this object.
            if (!isServer)
            {
                logger.LogWarning("TargetRpc " + rpcName + " called on un-spawned object: " + name);
                return;
            }

            // construct the message
            RpcMessage message = new RpcMessage
            {
                netId          = netId,
                componentIndex = ComponentIndex,
                // type+func so Inventory.RpcUse != Equipment.RpcUse
                functionHash = RemoteCallHelper.GetMethodHash(invokeClass, rpcName),
                // segment to avoid reader allocations
                payload = writer.ToArraySegment()
            };

            conn.Send(message, channelId);
        }
Пример #29
0
 public static void WriteVector2Int(this NetworkWriter writer, Vector2Int value)
 {
     writer.WritePackedInt32(value.x);
     writer.WritePackedInt32(value.y);
 }
 public override bool OnSerialize(NetworkWriter writer, bool initialState)
 {
     // use local position/rotation/scale for VR support
     SerializeIntoWriter(writer, targetComponent.transform.localPosition, targetComponent.transform.localRotation, compressRotation, targetComponent.transform.localScale);
     return(true);
 }