public static object Read(BinaryReader reader)
            {
                var token = (UTinyBinaryToken)reader.ReadByte();

                switch (token)
                {
                case UTinyBinaryToken.Id:
                    return(ReadId(reader));

                case UTinyBinaryToken.ModuleReference:
                    return(new UTinyModule.Reference(ReadId(reader), reader.ReadString()));

                case UTinyBinaryToken.TypeReference:
                    return(new UTinyType.Reference(ReadId(reader), reader.ReadString()));

                case UTinyBinaryToken.SceneReference:
                    return(new UTinyEntityGroup.Reference(ReadId(reader), reader.ReadString()));

                case UTinyBinaryToken.EntityReference:
                    return(new UTinyEntity.Reference(ReadId(reader), reader.ReadString()));

                case UTinyBinaryToken.ScriptReference:
                    return(new UTinyScript.Reference(ReadId(reader), reader.ReadString()));

                case UTinyBinaryToken.SystemReference:
                    return(new UTinySystem.Reference(ReadId(reader), reader.ReadString()));

                case UTinyBinaryToken.UnityObject:
                    var guid   = reader.ReadString();
                    var fileId = reader.ReadInt64();
                    var type   = reader.ReadInt32();
                    return(UnityObjectSerializer.FromObjectHandle(new UnityObjectHandle {
                        Guid = guid, FileId = fileId, Type = type
                    }));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
示例#2
0
        private static Object ParseUnityObject(object obj)
        {
            var o = obj as Object;

            if (o != null)
            {
                return(o);
            }

            var dictionary = obj as IDictionary <string, object>;

            if (null == dictionary)
            {
                return(null);
            }

            var guid   = GetValue <string>(dictionary, "Guid");
            var fileId = ParseLong(GetValue(dictionary, "FileId"));
            var type   = ParseInt(GetValue(dictionary, "Type"));

            return(UnityObjectSerializer.FromObjectHandle(new UnityObjectHandle {
                Guid = guid, FileId = fileId, Type = type
            }));
        }