예제 #1
0
        /// <summary>
        /// Reads one packet from NetDataReader and calls OnReceive delegate
        /// </summary>
        /// <param name="reader">NetDataReader with packet</param>
        /// <param name="userData">Argument that passed to OnReceivedEvent</param>
        public void ReadPacket(NetDataReader reader, object userData)
        {
            StructInfo info = ReadInfo(reader);

            if (info.CreatorFunc != null)
            {
                info.Reference = info.CreatorFunc();
            }
            info.Read(reader);
            info.OnReceive(info.Reference, userData);
        }
예제 #2
0
        /// <summary>
        /// Reads packet with known type (non alloc variant)
        /// </summary>
        /// <param name="reader">NetDataReader with packet</param>
        /// <param name="target">Deserialization target</param>
        /// <returns>Returns true if packet in reader is matched type</returns>
        public bool ReadKnownPacket <T>(NetDataReader reader, T target) where T : class, new()
        {
            StructInfo info = ReadInfo(reader);

            if (_hasher.GetHash(typeof(T).Name) != info.Hash)
            {
                return(false);
            }
            info.Reference = target;
            info.Read(reader);
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Reads packet with known type
        /// </summary>
        /// <param name="reader">NetDataReader with packet</param>
        /// <returns>Returns packet if packet in reader is matched type</returns>
        public T ReadKnownPacket <T>(NetDataReader reader) where T : class, new()
        {
            StructInfo info = ReadInfo(reader);

            if (_hasher.GetHash(typeof(T).Name) != info.Hash)
            {
                return(null);
            }
            info.Reference = ((info.CreatorFunc != null) ? info.CreatorFunc() : new T());
            info.Read(reader);
            return((T)info.Reference);
        }