Пример #1
0
        private void loadObjectType(ObjectData data)
        {
            TypeNode         typeNode     = null;
            EmbeddedTypeInfo embeddedtype = null;

            if (typeTreeStruct.embeddedTypeMap.ContainsKey(data.typeID))
            {
                embeddedtype = typeTreeStruct.embeddedTypeMap[data.typeID];
                if (embeddedtype != null)
                {
                    typeNode = embeddedtype.typeTree;
                }
            }

            // get type from database if the embedded one is missing
            if (typeNode == null)
            {
                typeNode = TypeTreeUtils.getTypeNode(data.unityClass(),
                                                     versionInfo.unityRevision, false);
            }

            data.typeTree = typeNode;

            //// Add typeless objects to an internal list. They can't be
            //// (de)serialized, but can still be written to the file.
            //if (typeNode == null)
            //{
            //    // log warning if it's not a MonoBehaviour
            //    if (info.classID != 114)
            //    {
            //        //Logger.Log("{0} has no type information!" + data.ToString());
            //    }
            //    objectListBroken.Add(data);
            //}
            //else
            //{
            //    objectList.Add(data);
            //}
        }
Пример #2
0
        //throws IOException
        public void write(DataWriter outw)
        {
            // revision/version for newer formats
            if (versionInfo.assetVersion > 6)
            {
                outw.writeStringNull(versionInfo.unityRevision.ToString());
                outw.writeInt(attributes);
            }

            TypeNodeWriter nodeWriter = new TypeNodeWriter(versionInfo);

            if (versionInfo.assetVersion > 13)
            {
                // TODO
                throw new Exception();
            }
            else
            {
                int numBaseClasses = embeddedTypeMap.Count;
                outw.writeInt(numBaseClasses);

                foreach (KeyValuePair <int, EmbeddedTypeInfo> pair in embeddedTypeMap)
                {
                    EmbeddedTypeInfo etinfo = pair.Value;
                    int classID             = etinfo.classID;
                    outw.writeInt(classID);

                    TypeNode node = etinfo.typeTree;
                    nodeWriter.write(outw, node);
                }

                // padding
                if (versionInfo.assetVersion > 6)
                {
                    outw.writeInt(0);
                }
            }
        }
Пример #3
0
        //throws IOException
        public void read(DataReader inr)
        {
            // revision/version for newer formats
            if (versionInfo.assetVersion > 6)
            {
                string sver = inr.readStringNull(255);
                versionInfo.unityRevision = new UnityVersion(sver);
                attributes = inr.readInt();
            }

            TypeNodeReader nodeReader = new TypeNodeReader(versionInfo);

            // Unity 5+ uses a serialized tree structure and string buffers
            if (versionInfo.assetVersion > 13)
            {
                embedded = inr.readBoolean();
                int numBaseClasses = inr.readInt();
                Logger.Log("numBaseClasses=" + numBaseClasses);
                if (numBaseClasses > 1000)
                {
                    return;
                }
                for (int i = 0; i < numBaseClasses; i++)
                {
                    int classID = inr.readInt();
                    EmbeddedTypeInfo embeddedtype = new EmbeddedTypeInfo();
                    embeddedtype.classID = classID;

                    if (classID < 0)
                    {
                        UnityHash128 scriptID = new UnityHash128(versionInfo);
                        scriptID.read(inr);
                        embeddedtype.scriptID = scriptID;
                    }

                    UnityHash128 oldTypeHash = new UnityHash128(versionInfo);
                    oldTypeHash.read(inr);
                    embeddedtype.oldTypeHash = oldTypeHash;

                    if (embedded)
                    {
                        TypeNode node = new TypeNode(versionInfo);
                        nodeReader.read(inr, node);
                        embeddedtype.typeTree = node;
                    }

                    embeddedTypeMap[classID] = embeddedtype;
                }
            }
            else
            {
                int numBaseClasses = inr.readInt();
                Logger.Log("numBaseClasses=" + numBaseClasses);
                for (int i = 0; i < numBaseClasses; i++)
                {
                    int classID = inr.readInt();

                    EmbeddedTypeInfo embeddedtype = new EmbeddedTypeInfo();
                    embeddedtype.classID = classID;

                    TypeNode node = new TypeNode(versionInfo);
                    nodeReader.read(inr, node);
                    embeddedtype.typeTree = node;

                    embeddedTypeMap[classID] = embeddedtype;
                }

                embedded = numBaseClasses > 0;

                // padding
                if (versionInfo.assetVersion > 6)
                {
                    inr.readInt();
                }
            }
        }