Exemple #1
0
        public void OnNetDeserialize(NetDataReader reader)
        {
            _isSceneObject          = reader.ReadBoolean();
            _ownerSessionId         = reader.ReadUInt16();
            transform.localPosition = reader.ReadVector3();
            transform.localRotation = reader.ReadQuaternion();
            transform.localScale    = reader.ReadVector3();

            _serializer?.Deserialize(reader);
        }
        //NetSerializer netSerializer = new NetSerializer();
        public T Deserialize <T>(NetDataReader reader) where T : new()
        {
            T t = new T();
            INetSerializable serializable = (INetSerializable)t;

            serializable.Deserialize(reader);
            //Debug.Log("Deserialize:" + JsonUtility.ToJson(serializable));
            //Debug.Log("Deserialize:" + JsonUtility.ToJson(t));
            t = (T)serializable;


            //netSerializer.RegisterNestedType<T>();
            //Debug.Log("Deserialize:" + JsonUtility.ToJson(t));
            return(t);
        }
Exemple #3
0
        //private NetDataReader reader = null;
        public object Deserialize(byte[] datas, out object msgType)
        {
            //NetDebug.Log("Deserialize收到消息:" + datas.Length);
            NetDataReader reader = new NetDataReader(byteOrder);

            reader.SetSource(datas, 0);
            msgType = reader.GetString();
            string msgT = msgType.ToString();

            if (!typeDic.ContainsKey(msgT))
            {
                NetDebug.LogError("No msgType:" + msgType);
                return(null);
            }
            Type             type         = typeDic[msgT];
            INetSerializable serializable = (INetSerializable)ReflectionTool.CreateDefultInstance(type);

            serializable.Deserialize(reader);
            return(serializable);
        }