コード例 #1
0
 public void MergeTypeDefinition(AssetCabinet file, UnityClassID cls)
 {
     AssetCabinet.TypeDefinition clsDef = Types.Find
                                          (
         delegate(AssetCabinet.TypeDefinition def)
     {
         return(def.typeId == (int)cls);
     }
                                          );
     if (clsDef == null)
     {
         clsDef = file.Types.Find
                  (
             delegate(AssetCabinet.TypeDefinition def)
         {
             return(def.typeId == (int)cls);
         }
                  );
         if (clsDef == null)
         {
             Report.ReportLog("Warning! Class Definition for " + cls + " not found!");
             return;
         }
         Types.Add(clsDef);
     }
 }
コード例 #2
0
ファイル: MonoBehaviour.cs プロジェクト: kkdevs/sb3u
        public virtual MonoBehaviour Clone(AssetCabinet file)
        {
            if (file.Parser.ExtendedSignature == null)
            {
                return(null);
            }
            AssetCabinet.TypeDefinition srcDef;
            if (this.file.VersionNumber < AssetCabinet.VERSION_5_5_0)
            {
                srcDef = this.file.Types.Find
                         (
                    delegate(AssetCabinet.TypeDefinition def)
                {
                    return(def.typeId == (int)this.classID1);
                }
                         );
            }
            else
            {
                srcDef = this.file.Types[(int)this.classID1];
            }
            int  destId = 0, minId = 0;
            bool found = false;

            AssetCabinet.TypeDefinition destDef = null;
            for (int i = 0; i < file.Types.Count; i++)
            {
                if (AssetCabinet.CompareTypes(srcDef, file.Types[i]))
                {
                    destDef = file.Types[i];
                    destId  = this.file.VersionNumber < AssetCabinet.VERSION_5_5_0 ? destDef.typeId : i;
                    found   = true;
                    break;
                }
                if (file.Types[i].typeId < minId)
                {
                    minId = file.Types[i].typeId;
                }
            }
            if (!found)
            {
                destDef = srcDef.Clone(file.VersionNumber);
                if (this.file.VersionNumber < AssetCabinet.VERSION_5_5_0)
                {
                    destId = destDef.typeId = minId - 1;
                    file.Types.Insert(0, destDef);
                }
                else
                {
                    destId = file.Types.Count;
                    file.Types.Add(destDef);
                }
            }

            MonoBehaviour dest = new MonoBehaviour(file, (UnityClassID)destId);

            dest.Parser = new TypeParser(file, destDef);
            AssetCabinet.IncompleteClones.Add(new Tuple <Component, Component>(this, dest));
            return(dest);
        }
コード例 #3
0
ファイル: MonoBehaviour.cs プロジェクト: kkdevs/sb3u
 public void LoadFrom(Stream stream)
 {
     AssetCabinet.TypeDefinition oldDef = null;
     try
     {
         AssetCabinet.TypeDefinition typeDef;
         if (file.Parser.ExtendedSignature == null)
         {
             MonoScript monoScript;
             typeDef = AssetCabinet.GetExternalMBTypeDefinition(this, false, out monoScript);
             if (typeDef == null)
             {
                 return;
             }
             oldDef = file.Types[(int)classID1];
             file.Types[(int)classID1] = typeDef;
         }
         else
         {
             typeDef = AssetCabinet.GetInternalMBTypeDefinition(file, classID1);
         }
         Parser = new TypeParser(file, typeDef);
         Parser.type.LoadFrom(stream);
     }
     finally
     {
         if (oldDef != null)
         {
             file.Types[(int)classID1] = oldDef;
         }
     }
 }
コード例 #4
0
ファイル: MonoBehaviour.cs プロジェクト: kkdevs/sb3u
        public void CopyTo(MonoBehaviour dest)
        {
            GameObject destGameObj = dest.m_GameObject.instance;

            if (destGameObj != null)
            {
                Transform animFrame = destGameObj.FindLinkedComponent(typeof(Transform));
                while (animFrame.Parent != null)
                {
                    animFrame = animFrame.Parent;
                }
                UPPtr.AnimatorRoot = animFrame;
            }
            else
            {
                if (m_Name.Length > 0)
                {
                    dest.file.Bundle.AddComponent(m_Name, dest);
                }

                UPPtr.AnimatorRoot = null;
            }
            Parser.type.CopyToRootClass(dest.Parser.type);

            if (dest.file.VersionNumber >= AssetCabinet.VERSION_5_5_0)
            {
                AssetCabinet.TypeDefinition destDef = dest.file.Types[(int)dest.classID1];
                if (destDef.assetRefIndex == 0xFFFF)
                {
                    for (int i = 0; i < dest.file.AssetRefs.Count; i++)
                    {
                        PPtr <Object> msRef = dest.file.AssetRefs[i];
                        if (msRef.asset == dest.m_MonoScript.asset)
                        {
                            destDef.assetRefIndex = (ushort)i;
                            break;
                        }
                    }
                }
            }
            else if (dest.file.VersionNumber > AssetCabinet.VERSION_5_0_0 && dest.file.VersionNumber < AssetCabinet.VERSION_5_4_1)
            {
                MonoScript ms    = dest.m_MonoScript.instance;
                int        index = -1;
                if (ms != null)
                {
                    for (int i = 0; i < dest.file.AssetRefs.Count; i++)
                    {
                        PPtr <Object> objPtr = dest.file.AssetRefs[i];
                        if (objPtr.asset == ms)
                        {
                            index = i;
                            break;
                        }
                    }
                }
                dest.classID2 = (UnityClassID)(index << 16) | UnityClassID.MonoBehaviour;
            }
        }
コード例 #5
0
        UClass GenerateType(AssetCabinet.TypeDefinition typeDef)
        {
            UClass cls = new UClass(typeDef.definitions.type, typeDef.definitions.identifier);

            for (int i = 0; i < typeDef.definitions.children.Length; i++)
            {
                AssetCabinet.TypeDefinitionString memberDef = typeDef.definitions.children[i];
                UType member = GetMember(memberDef);
                cls.Members.Add(member);
            }
            return(cls);
        }
コード例 #6
0
ファイル: LoadedByTypeDefinition.cs プロジェクト: kkdevs/sb3u
        public LoadedByTypeDefinition Clone(AssetCabinet file)
        {
            if (file.Parser.ExtendedSignature == null)
            {
                return(null);
            }
            AssetCabinet.TypeDefinition srcDef;
            if (this.file.VersionNumber < AssetCabinet.VERSION_5_5_0 || classID2 != UnityClassID.MonoBehaviour)
            {
                srcDef = this.file.Types.Find
                         (
                    delegate(AssetCabinet.TypeDefinition def)
                {
                    return(def.typeId == (int)this.classID1);
                }
                         );
            }
            else
            {
                srcDef = this.file.Types[(int)this.classID1];
            }
            bool found = false;

            AssetCabinet.TypeDefinition destDef = null;
            for (int i = 0; i < file.Types.Count; i++)
            {
                if (AssetCabinet.CompareTypes(srcDef, file.Types[i]))
                {
                    destDef = file.Types[i];
                    found   = true;
                    break;
                }
            }
            if (!found)
            {
                destDef = srcDef.Clone(file.VersionNumber);
                file.Types.Add(destDef);
            }

            LoadedByTypeDefinition dest = new LoadedByTypeDefinition(file, classID1, classID2);

            dest.parser = new TypeParser(file, destDef);
            AssetCabinet.IncompleteClones.Add(new Tuple <Component, Component>(this, dest));
            return(dest);
        }
コード例 #7
0
ファイル: LoadedByTypeDefinition.cs プロジェクト: kkdevs/sb3u
        public void LoadFrom(Stream stream)
        {
            if (file.Types == null)
            {
                throw new Exception("No Types in file");
            }
            AssetCabinet.TypeDefinition typeDef = file.Types.Find
                                                  (
                delegate(AssetCabinet.TypeDefinition def)
            {
                return(def.typeId == (int)this.classID());
            }
                                                  );
            if (typeDef.definitions == null)
            {
                throw new Exception("Type definition is incomplete");
            }
            parser = new TypeParser(file, typeDef);

            parser.type.LoadFrom(stream);
        }
コード例 #8
0
        public MonoBehaviour Clone(AssetCabinet file)
        {
            AssetCabinet.TypeDefinition srcDef = this.file.Types.Find
                                                 (
                delegate(AssetCabinet.TypeDefinition def)
            {
                return(def.typeId == (int)this.classID1);
            }
                                                 );
            int destId = 0, minId = 0;

            AssetCabinet.TypeDefinition destDef = null;
            for (int i = 0; i < file.Types.Count; i++)
            {
                if (AssetCabinet.CompareTypes(srcDef, file.Types[i]))
                {
                    destDef = file.Types[i];
                    destId  = destDef.typeId;
                    break;
                }
                if (file.Types[i].typeId < minId)
                {
                    minId = file.Types[i].typeId;
                }
            }
            if (destId == 0)
            {
                destDef = srcDef.Clone();
                destId  = destDef.typeId = minId - 1;
                file.Types.Add(destDef);
            }

            MonoBehaviour dest = new MonoBehaviour(file, (UnityClassID)destId);

            dest.Parser = new TypeParser(file, destDef);
            AssetCabinet.IncompleteClones.Add(new Tuple <Component, Component>(this, dest));
            return(dest);
        }
コード例 #9
0
 public TypeParser(AssetCabinet file, AssetCabinet.TypeDefinition typeDef)
 {
     this.file = file;
     type      = GenerateType(typeDef);
 }
コード例 #10
0
        public override void CopyTo(UType dest)
        {
            Component asset = null;

            if (Value.asset != null)
            {
                string name = AssetCabinet.ToString(Value.asset);
                asset = ((UPPtr)dest).file.Bundle.FindComponent(name, Value.asset.classID2);
                if (asset == null)
                {
                    switch (Value.asset.classID2)
                    {
                    case UnityClassID.GameObject:
                        if (((UPPtr)dest).Value == null)
                        {
                            Report.ReportLog("Warning! Unset MonoBehaviour to GameObject " + name);
                            break;
                        }
                        return;

                    case UnityClassID.MonoBehaviour:
                        if (((MonoBehaviour)Value.asset).m_GameObject.instance != null)
                        {
                            Transform trans = Operations.FindFrame(name, AnimatorRoot);
                            if (trans != null)
                            {
                                AssetCabinet.TypeDefinition srcDef = this.file.Types.Find
                                                                     (
                                    delegate(AssetCabinet.TypeDefinition def)
                                {
                                    return(def.typeId == (int)((MonoBehaviour)Value.asset).classID1);
                                }
                                                                     );
                                bool found       = false;
                                var  m_Component = trans.m_GameObject.instance.m_Component;
                                for (int i = 0; i < m_Component.Count; i++)
                                {
                                    if (m_Component[i].Value.asset != null && m_Component[i].Value.asset.classID2 == UnityClassID.MonoBehaviour)
                                    {
                                        AssetCabinet.TypeDefinition destDef = ((UPPtr)dest).file.Types.Find
                                                                              (
                                            delegate(AssetCabinet.TypeDefinition def)
                                        {
                                            return(def.typeId == (int)((MonoBehaviour)m_Component[i].Value.asset).classID1);
                                        }
                                                                              );
                                        if (AssetCabinet.CompareTypes(destDef, srcDef))
                                        {
                                            asset = m_Component[i].Value.asset;
                                            found = true;
                                            break;
                                        }
                                    }
                                }
                                if (!found)
                                {
                                    asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                                    trans.m_GameObject.instance.AddLinkedComponent((LinkedByGameObject)asset);
                                }
                            }
                            else
                            {
                                Report.ReportLog("Error! MonoBehaviour reference to " + name + " lost. Member " + Name);
                            }
                        }
                        else
                        {
                            asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                        }
                        break;

                    case UnityClassID.MonoScript:
                        asset = ((MonoScript)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Transform:
                        asset = Operations.FindFrame(name, AnimatorRoot);
                        if (asset == null)
                        {
                            Report.ReportLog("Warning! Transform reference to " + name + " lost. Member " + Name);
                        }
                        break;

                    case UnityClassID.Texture2D:
                        asset = ((Texture2D)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    default:
                        Report.ReportLog("Warning! MonoBehaviour reference to " + Value.asset.classID2 + " " + name + " unhandled. Member " + Name);
                        break;
                    }
                }
            }
            ((UPPtr)dest).Value = new PPtr <Object>(asset);
        }
コード例 #11
0
 public static bool CompareTypes(AssetCabinet.TypeDefinition td1, AssetCabinet.TypeDefinition td2)
 {
     return(CompareTypes(td1.definitions, td2.definitions));
 }
コード例 #12
0
ファイル: TypeParser.cs プロジェクト: kkdevs/sb3u
        public override void CopyTo(UType dest)
        {
            Component asset = null;

            if (Value.asset != null)
            {
                string name = AssetCabinet.ToString(Value.asset);
                asset = ((UPPtr)dest).file.Bundle.FindComponent(name, Value.asset.classID());
                if (asset == null)
                {
                    switch (Value.asset.classID())
                    {
                    case UnityClassID.GameObject:
                        if (((UPPtr)dest).Value == null)
                        {
                            GameObject gObj = (GameObject)Value.asset;
                            if (gObj != null)
                            {
                                Transform trans = gObj.FindLinkedComponent(typeof(Transform));
                                trans = AnimatorRoot != null?Operations.FindFrame(trans.GetTransformPath(), AnimatorRoot) : null;

                                if (trans != null)
                                {
                                    asset = trans.m_GameObject.instance;
                                    break;
                                }
                            }
                            Report.ReportLog("Warning! Losing PPtr<" + Value.asset.classID() + "> " + Name + " to " + name);
                            break;
                        }
                        return;

                    case UnityClassID.Light:
                        GameObject gameObj = ((Light)Value.asset).m_GameObject.instance;
                        if (gameObj != null)
                        {
                            Transform trans = gameObj.FindLinkedComponent(typeof(Transform));
                            trans = AnimatorRoot != null?Operations.FindFrame(trans.GetTransformPath(), AnimatorRoot) : null;

                            if (trans != null)
                            {
                                asset = trans.m_GameObject.instance.FindLinkedComponent(UnityClassID.Light);
                            }
                            else
                            {
                                foreach (Component a in ((UPPtr)dest).file.Components)
                                {
                                    if (a.classID() == UnityClassID.Light)
                                    {
                                        string n = a is NotLoaded ? ((NotLoaded)a).Name : AssetCabinet.ToString(a);
                                        if (n == name)
                                        {
                                            asset = a;
                                            Report.ReportLog("Warning! Unsharp search for PPtr<" + Value.asset.classID() + "> " + Name + " to " + name + " found PathID=" + a.pathID);
                                            break;
                                        }
                                    }
                                }
                                if (asset == null)
                                {
                                    Report.ReportLog("Warning! Losing PPtr<" + Value.asset.classID() + "> " + Name + " to " + name);
                                }
                            }
                        }
                        break;

                    case UnityClassID.MonoBehaviour:
                        gameObj = ((MonoBehaviour)Value.asset).m_GameObject.instance;
                        if (gameObj != null)
                        {
                            Transform trans = gameObj.FindLinkedComponent(typeof(Transform));
                            trans = AnimatorRoot != null?Operations.FindFrame(trans.GetTransformPath(), AnimatorRoot) : null;

                            if (trans != null)
                            {
                                AssetCabinet.TypeDefinition srcDef =
                                    this.file.VersionNumber < AssetCabinet.VERSION_5_5_0
                                                                        ? this.file.Types.Find
                                    (
                                        delegate(AssetCabinet.TypeDefinition def)
                                {
                                    return(def.typeId == (int)((MonoBehaviour)Value.asset).classID1);
                                }
                                    )
                                                                        : this.file.Types[(int)((MonoBehaviour)Value.asset).classID1];
                                bool found       = false;
                                var  m_Component = trans.m_GameObject.instance.m_Component;
                                for (int i = 0; i < m_Component.Count; i++)
                                {
                                    if (m_Component[i].Value.asset != null && m_Component[i].Value.asset.classID() == UnityClassID.MonoBehaviour)
                                    {
                                        AssetCabinet.TypeDefinition destDef =
                                            ((UPPtr)dest).file.VersionNumber < AssetCabinet.VERSION_5_5_0
                                                                                        ? ((UPPtr)dest).file.Types.Find
                                            (
                                                delegate(AssetCabinet.TypeDefinition def)
                                        {
                                            return(def.typeId == (int)((MonoBehaviour)m_Component[i].Value.asset).classID1);
                                        }
                                            )
                                                                                        : ((UPPtr)dest).file.Types[(int)((MonoBehaviour)m_Component[i].Value.asset).classID1];
                                        if (AssetCabinet.CompareTypes(destDef, srcDef))
                                        {
                                            asset = m_Component[i].Value.asset;
                                            found = true;
                                            break;
                                        }
                                    }
                                }
                                if (!found)
                                {
                                    asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                                    trans.m_GameObject.instance.AddLinkedComponent((LinkedByGameObject)asset);
                                }
                            }
                            else
                            {
                                Report.ReportLog("Error! Reference to " + Value.asset.classID() + " " + name + " lost. Member " + Name);
                            }
                        }
                        else
                        {
                            asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                        }
                        break;

                    case UnityClassID.MonoScript:
                        asset = ((MonoScript)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Sprite:
                        asset = ((Sprite)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Transform:
                        asset = AnimatorRoot != null?Operations.FindFrame(((Transform)Value.asset).GetTransformPath(), AnimatorRoot) : null;

                        if (asset == null)
                        {
                            Report.ReportLog("Warning! Reference to " + UnityClassID.Transform + " " + name + " lost. Member " + Name);
                        }
                        break;

                    case UnityClassID.Material:
                        asset = ((Material)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.MeshRenderer:
                    case UnityClassID.SkinnedMeshRenderer:
                        asset = AnimatorRoot != null?Operations.FindMesh(AnimatorRoot, name) : null;

                        if (asset == null)
                        {
                            Report.ReportLog("Warning! Reference to " + Value.asset.classID() + " " + name + " lost. Member " + Name);
                        }
                        break;

                    case UnityClassID.Texture2D:
                        asset = ((Texture2D)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Cubemap:
                        asset = ((Cubemap)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    default:
                        if (Value.asset is LoadedByTypeDefinition)
                        {
                            LoadedByTypeDefinition loadedByTypeDef = (LoadedByTypeDefinition)Value.asset;
                            PPtr <GameObject>      gameObjPtr      = loadedByTypeDef.m_GameObject;
                            if (gameObjPtr == null)
                            {
                                AssetCabinet file = ((UPPtr)dest).file;
                                foreach (Component a in file.Components)
                                {
                                    if (a.classID() == loadedByTypeDef.classID() &&
                                        (a is NotLoaded ? ((NotLoaded)a).Name : AssetCabinet.ToString(a)) == loadedByTypeDef.m_Name)
                                    {
                                        asset = a;

                                        file = null;
                                        break;
                                    }
                                }
                                if (file != null)
                                {
                                    asset = loadedByTypeDef.Clone(file);
                                }
                            }
                            else
                            {
                                Transform srcTrans  = gameObjPtr.instance.FindLinkedComponent(typeof(Transform));
                                Transform destTrans = AnimatorRoot != null?Operations.FindFrame(srcTrans.GetTransformPath(), AnimatorRoot) : null;

                                if (destTrans != null)
                                {
                                    asset = destTrans.m_GameObject.instance.FindLinkedComponent(loadedByTypeDef.classID());
                                }
                                else
                                {
                                    foreach (Component a in ((UPPtr)dest).file.Components)
                                    {
                                        if (a.classID() == Value.asset.classID())
                                        {
                                            string n = a is NotLoaded ? ((NotLoaded)a).Name : AssetCabinet.ToString(a);
                                            if (n == name)
                                            {
                                                asset = a;
                                                Report.ReportLog("Warning! Unsharp search for PPtr<" + Value.asset.classID() + "> " + Name + " to " + name + " found PathID=" + a.pathID);
                                                break;
                                            }
                                        }
                                    }
                                    if (asset == null)
                                    {
                                        Report.ReportLog("Warning! Losing PPtr<" + Value.asset.classID() + "> " + Name + " to " + name);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Report.ReportLog("Warning! Reference to " + Value.asset.classID() + " " + name + " unhandled. Member " + Name);
                        }
                        break;
                    }
                }
            }
            ((UPPtr)dest).Value = new PPtr <Object>(asset);
        }