Ejemplo n.º 1
0
 public static void ReplaceTexture(UnityParser parser, ImportedTexture texture)
 {
     if (!Operations.ReplaceTexture(parser, texture, false))
     {
         throw new Exception("Texture " + texture.Name + " not present");
     }
 }
Ejemplo n.º 2
0
        public static void ExportAsset([DefaultVar] UnityParser parser, Component asset, string path)
        {
            FileInfo      file = new FileInfo(path + "." + (asset.classID() == UnityClassID.MonoBehaviour ? ((int)asset.classID1).ToString() : asset.classID().ToString()));
            DirectoryInfo dir  = file.Directory;

            if (!dir.Exists)
            {
                dir.Create();
            }

            using (FileStream fs = file.Create())
            {
                NeedsSourceStreamForWriting notLoaded = asset as NeedsSourceStreamForWriting;
                if (notLoaded != null)
                {
                    notLoaded.SourceStream = parser.Uncompressed == null?File.OpenRead(parser.FilePath) : parser.Uncompressed;
                }
                try
                {
                    asset.WriteTo(fs);
                }
                finally
                {
                    if (notLoaded != parser.Uncompressed)
                    {
                        notLoaded.SourceStream.Close();
                        notLoaded.SourceStream.Dispose();
                        notLoaded.SourceStream = null;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void ExportUnity3d([DefaultVar] UnityParser parser, string path)
        {
            if (path == String.Empty)
            {
                path = @".\";
            }
            DirectoryInfo dir = new DirectoryInfo(path);

            if (!dir.Exists)
            {
                dir.Create();
            }

            using (Stream sourceStream = File.OpenRead(parser.FilePath))
            {
                for (int i = 0; i < parser.Cabinet.Components.Count; i++)
                {
                    var asset = parser.Cabinet.Components[i];
                    using (FileStream fs = File.Create(dir.FullName + @"\" + asset.pathID + "." + asset.classID1))
                    {
                        NeedsSourceStreamForWriting notLoaded = asset as NeedsSourceStreamForWriting;
                        if (notLoaded != null)
                        {
                            notLoaded.SourceStream = sourceStream;
                        }
                        asset.WriteTo(fs);
                        if (notLoaded != null)
                        {
                            notLoaded.SourceStream = null;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static bool RemoveMod(UnityParser parser, UnityParser originalsParser, bool deleteOriginals)
        {
            Match m = Regex.Match(originalsParser.FilePath, @"-(-*\d+)\.", RegexOptions.CultureInvariant);
            int   firstNewPathID = -1;

            if (!m.Success || !int.TryParse(m.Groups[1].Value, out firstNewPathID))
            {
                Report.ReportLog("Warning! Mod filename \"" + Path.GetFileName(originalsParser.FilePath) + "\" is malformed or lies in a folder with a confusing name.");
                firstNewPathID = -1;
            }
            bool error = false;

            for (int i = originalsParser.Cabinet.Components.Count - 1; i >= 0; i--)
            {
                int       pathID = originalsParser.Cabinet.Components[i].pathID;
                Component comp   = parser.Cabinet.FindComponent(pathID);
                if (comp != null)
                {
                    if (comp.classID2 == originalsParser.Cabinet.Components[i].classID2)
                    {
                        if (firstNewPathID == -1 || pathID < firstNewPathID)
                        {
                            parser.Cabinet.ReplaceSubfile(comp, originalsParser.Cabinet.Components[i]);
                        }
                        else
                        {
                            if (parser.Cabinet.Components.IndexOf(comp) == parser.Cabinet.Components.Count - 1)
                            {
                                parser.Cabinet.RemoveSubfile(comp);
                            }
                            else
                            {
                                Report.ReportLog("Asset with PathID=" + pathID + " is not located at the end. Other mods will become unremovable when this asset would be removed.");
                                error = true;
                            }
                        }
                    }
                    else
                    {
                        Report.ReportLog("Unexpected asset in " + Path.GetFileName(parser.FilePath) + " with PathID=" + pathID + " was not " + (firstNewPathID == -1 || pathID < firstNewPathID ? "replaced." : "removed."));
                        error = true;
                    }
                }
                else
                {
                    Report.ReportLog("Asset with PathID=" + pathID + " is not present in " + Path.GetFileName(parser.FilePath));
                    error = true;
                }
            }
            if (error)
            {
                Report.ReportLog(Path.GetFileName(originalsParser.FilePath) + " was partially removed. Saving " + Path.GetFileName(parser.FilePath) + " may corrupt the file.");
                return(false);
            }
            if (deleteOriginals)
            {
                parser.DeleteModFiles.Add(originalsParser.Cabinet);
            }
            return(true);
        }
Ejemplo n.º 5
0
        public static void ExportAsset([DefaultVar] UnityParser parser, int pathID, string path)
        {
            Component asset = parser.Cabinet.FindComponent(pathID);

            if (asset != null)
            {
                FileInfo      file = new FileInfo(path + "." + asset.classID1);
                DirectoryInfo dir  = file.Directory;
                if (!dir.Exists)
                {
                    dir.Create();
                }

                using (FileStream fs = file.Create())
                {
                    NeedsSourceStreamForWriting notLoaded = asset as NeedsSourceStreamForWriting;
                    if (notLoaded != null)
                    {
                        notLoaded.SourceStream = File.OpenRead(parser.FilePath);
                    }
                    asset.WriteTo(fs);
                    if (notLoaded != null)
                    {
                        notLoaded.SourceStream.Close();
                        notLoaded.SourceStream.Dispose();
                        notLoaded.SourceStream = null;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static void ReplaceAudioClip(UnityParser parser, string path)
        {
            AudioClip ac = AudioClip.Import(path);

            if (ac.m_AudioData.Length > 0)
            {
                for (int i = 0; i < parser.Cabinet.Components.Count; i++)
                {
                    Component asset = parser.Cabinet.Components[i];
                    if (asset.classID() == UnityClassID.AudioClip)
                    {
                        AudioClip acic = parser.Cabinet.LoadComponent(asset.pathID);
                        if (acic.m_Name == ac.m_Name)
                        {
                            acic.m_AudioData = ac.m_AudioData;
                            if (parser.Cabinet.VersionNumber >= AssetCabinet.VERSION_5_0_0)
                            {
                                acic.m_Resource.m_Source = path;
                            }
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static void ExportTexture([DefaultVar] UnityParser parser, string name, string path)
        {
            string folder = Path.GetDirectoryName(path);

            if (folder.Length > 0)
            {
                folder += "\\";
            }
            folder += Path.GetFileNameWithoutExtension(path);
            ImageFileFormat preferredUncompressedFormat = (string)Properties.Settings.Default["ExportUncompressedAs"] == "BMP"
                                ? ImageFileFormat.Bmp : (ImageFileFormat)(-1);

            if (name != "*")
            {
                Texture2D tex = parser.GetTexture(name);
                if (tex != null)
                {
                    tex.Export(folder, preferredUncompressedFormat);
                }
            }
            else
            {
                for (int i = 0; i < parser.Textures.Count; i++)
                {
                    Texture2D tex = parser.GetTexture(i);
                    tex.Export(folder, preferredUncompressedFormat);
                }
            }
        }
Ejemplo n.º 8
0
        public static void ExportTexture([DefaultVar] UnityParser parser, string name, string path)
        {
            string folder = Path.GetDirectoryName(path);

            if (folder.Length > 0)
            {
                folder += "\\";
            }
            folder += Path.GetFileNameWithoutExtension(path);
            if (name != "*")
            {
                Texture2D tex = parser.GetTexture(name);
                if (tex != null)
                {
                    tex.Export(folder);
                }
            }
            else
            {
                for (int i = 0; i < parser.Textures.Count; i++)
                {
                    Texture2D tex = parser.GetTexture(i);
                    tex.Export(folder);
                }
            }
        }
Ejemplo n.º 9
0
 public static void RemoveAsset([DefaultVar] UnityParser parser, Component asset)
 {
     if (asset.classID() == UnityClassID.AssetBundle)
     {
         return;
     }
     if (asset is NotLoaded)
     {
         Component loadedAsset = parser.Cabinet.LoadComponent(((NotLoaded)asset).pathID);
         if (loadedAsset != null)
         {
             asset = loadedAsset;
         }
     }
     if (asset is LinkedByGameObject)
     {
         LinkedByGameObject linked = (LinkedByGameObject)asset;
         if (linked.m_GameObject != null && linked.m_GameObject.instance != null)
         {
             linked.m_GameObject.instance.RemoveLinkedComponent(linked);
         }
     }
     parser.Cabinet.RemoveSubfile(asset);
     if (asset.classID() == UnityClassID.Texture2D || asset.classID() == UnityClassID.Cubemap)
     {
         parser.Textures.Remove(asset);
     }
     if (parser.Cabinet.Bundle != null)
     {
         parser.Cabinet.Bundle.DeleteComponent(asset);
     }
 }
Ejemplo n.º 10
0
        public FormNmlMonoBehaviour(UnityParser uParser, string nmlMonoBehaviourParserVar)
        {
            try
            {
                InitializeComponent();

                NmlMonoBehaviour parser = (NmlMonoBehaviour)Gui.Scripting.Variables[nmlMonoBehaviourParserVar];

                this.ShowHint    = DockState.Document;
                this.Text        = parser.m_Name;
                this.ToolTipText = uParser.FilePath + @"\" + this.Text;

                ParserVar = nmlMonoBehaviourParserVar;

                EditorVar = Gui.Scripting.GetNextVariable("nmlMonoBehaviourEditor");
                Editor    = (NmlMonoBehaviourEditor)Gui.Scripting.RunScript(EditorVar + " = NmlMonoBehaviourEditor(parser=" + ParserVar + ")");

                Init();
                LoadNml();
            }
            catch (Exception ex)
            {
                Utility.ReportException(ex);
            }
        }
Ejemplo n.º 11
0
        public FormMonoBehaviour(UnityParser uParser, string parserVar)
        {
            try
            {
                InitializeComponent();

                this.ShowHint = DockState.Document;
                MonoBehaviour parser = (MonoBehaviour)Gui.Scripting.Variables[parserVar];
                this.Text        = AssetCabinet.ToString(parser);
                this.ToolTipText = uParser.FilePath + @"\" + this.Text;

                EditorVar = Gui.Scripting.GetNextVariable("monoBehaviourEditor");
                Editor    = (MonoBehaviourEditor)Gui.Scripting.RunScript(EditorVar + " = MonoBehaviourEditor(parser=" + parserVar + ")");
                toolTip1.SetToolTip(buttonRevert, DateTime.Now.ToString());

                Gui.Docking.ShowDockContent(this, Gui.Docking.DockEditors, ContentCategory.Others);

                float treeViewFontSize = (float)Gui.Config["TreeViewFontSize"];
                if (treeViewFontSize > 0)
                {
                    treeViewAdditionalMembers.Font = new Font(treeViewAdditionalMembers.Font.Name, treeViewFontSize);
                }

                LoadContents();
            }
            catch (Exception e)
            {
                Utility.ReportException(e);
            }
        }
Ejemplo n.º 12
0
        public static void ExportFbx([DefaultVar] UnityParser parser, object[] skinnedMeshRendererIDs, object[] animationParsers, int startKeyframe, int endKeyframe, bool linear, bool EulerFilter, double filterPrecision, string path, string exportFormat, bool allFrames, bool allBones, bool skins, bool compatibility)
        {
            List <double>       sMeshIDList = new List <double>(Utility.Convert <double>(skinnedMeshRendererIDs));
            List <MeshRenderer> sMeshes     = new List <MeshRenderer>(sMeshIDList.Count);

            for (int i = 0; i < sMeshIDList.Count; i++)
            {
                int sMeshID = (int)sMeshIDList[i];
                if (i > 0 && sMeshID < 0)
                {
                    for (sMeshID = (int)sMeshIDList[i - 1] + 1; sMeshID < -(int)sMeshIDList[i]; sMeshID++)
                    {
                        SkinnedMeshRenderer sMesh = parser.Cabinet.LoadComponent(sMeshID);
                        if (sMesh == null)
                        {
                            continue;
                        }
                        sMeshes.Add(sMesh);
                    }
                }
                else
                {
                    SkinnedMeshRenderer sMesh = parser.Cabinet.LoadComponent(sMeshID);
                    if (sMesh == null)
                    {
                        continue;
                    }
                    sMeshes.Add(sMesh);
                }
            }

            UnityConverter imp = new UnityConverter(parser, sMeshes, skins);

            FbxUtility.Export(path, imp, startKeyframe, endKeyframe, linear, EulerFilter, (float)filterPrecision, exportFormat, allFrames, allBones, skins, compatibility);
        }
Ejemplo n.º 13
0
        public static Animator OpenAnimator([DefaultVar] UnityParser parser, string name)
        {
            foreach (Component subfile in parser.Cabinet.Components)
            {
                if (subfile.classID() == UnityClassID.Animator)
                {
                    if (subfile is Animator)
                    {
                        Animator a = (Animator)subfile;
                        if (a.m_GameObject.instance.m_Name == name)
                        {
                            return(a);
                        }
                        continue;
                    }
                    NotLoaded animatorComp = (NotLoaded)subfile;
                    Stream    stream       = parser.Uncompressed == null?File.OpenRead(parser.FilePath) : parser.Uncompressed;

                    try
                    {
                        stream.Position = animatorComp.offset;
                        PPtr <GameObject> gameObjPtr = Animator.LoadGameObject(stream, parser.Cabinet.VersionNumber);
                        for (int i = 0; i < parser.Cabinet.Components.Count; i++)
                        {
                            Component gameObjSubfile = parser.Cabinet.Components[i];
                            if (gameObjSubfile.pathID == gameObjPtr.m_PathID)
                            {
                                if (gameObjSubfile is GameObject)
                                {
                                    GameObject gameObj = (GameObject)gameObjSubfile;
                                    if (gameObj.m_Name == name)
                                    {
                                        return(parser.Cabinet.LoadComponent(stream, animatorComp));
                                    }
                                    break;
                                }
                                NotLoaded gameObjComp = (NotLoaded)gameObjSubfile;
                                stream.Position = gameObjComp.offset;
                                if (GameObject.LoadName(stream, parser.Cabinet.VersionNumber) == name)
                                {
                                    return(parser.Cabinet.LoadComponent(stream, animatorComp));
                                }
                                break;
                            }
                        }
                    }
                    finally
                    {
                        if (stream != parser.Uncompressed)
                        {
                            stream.Close();
                            stream.Dispose();
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 14
0
        public static void RemoveAsset([DefaultVar] UnityParser parser, int pathID)
        {
            Component asset = parser.Cabinet.FindComponent(pathID);

            if (asset == null)
            {
                throw new Exception("Couldn't find asset PathID=" + pathID);
            }
            parser.Cabinet.RemoveSubfile(asset);
        }
Ejemplo n.º 15
0
        public static void ReplaceTexture(UnityParser parser, ImportedTexture texture)
        {
            Texture2D tex = parser.GetTexture(Path.GetFileNameWithoutExtension(texture.Name));

            if (tex == null)
            {
                parser.AddTexture(texture);
                return;
            }
            ReplaceTexture(tex, texture);
        }
Ejemplo n.º 16
0
        public static void MergeTextures(UnityParser parser, string folder)
        {
            DirectoryInfo dir = new DirectoryInfo(folder);

            if (!dir.Exists)
            {
                throw new Exception("Directory <" + folder + "> does not exist");
            }
            foreach (FileInfo file in dir.EnumerateFiles())
            {
                MergeTexture(parser, file.FullName);
            }
        }
Ejemplo n.º 17
0
        public Unity3dEditor(UnityParser parser, bool showContents)
        {
            Parser = parser;

            VirtualAnimators = new HashSet <Animator>();
            if (Parser.Cabinet.Bundle != null)
            {
                for (int i = 0; i < Parser.Cabinet.Bundle.m_Container.Count; i++)
                {
                    AssetInfo info = Parser.Cabinet.Bundle.m_Container[i].Value;
                    if (info.asset.m_PathID == 0)
                    {
                        string msg = "Invalid container entry for " + Parser.Cabinet.Bundle.m_Container[i].Key;
                        if (msgFilter.Add(msg))
                        {
                            Report.ReportLog(msg);
                        }
                        continue;
                    }
                    if (info.asset.m_FileID == 0 && info.asset.asset.classID1 == UnityClassID.GameObject)
                    {
                        bool animatorFound  = false;
                        int  nextPreloadIdx = info.preloadIndex + info.preloadSize;
                        for (int j = info.preloadIndex; j < nextPreloadIdx; j++)
                        {
                            PPtr <Object> preTabEntry = Parser.Cabinet.Bundle.m_PreloadTable[j];
                            if (preTabEntry.m_FileID == 0 && preTabEntry.asset.classID1 == UnityClassID.Animator)
                            {
                                animatorFound = true;
                                break;
                            }
                        }
                        if (!animatorFound)
                        {
                            CreateVirtualAnimator(info.asset.asset);
                        }
                    }
                }
            }

            if (showContents)
            {
                string[] names = GetAssetNames(false);
                for (int i = 0; i < names.Length; i++)
                {
                    Component asset = Parser.Cabinet.Components[i];
                    Console.WriteLine("PathID=" + asset.pathID.ToString("D") + " id1=" + (int)asset.classID1 + "/" + asset.classID1 + " id2=" + asset.classID2 + " " + names[i]);
                }
            }
        }
Ejemplo n.º 18
0
        public void ComputeMinMaxNormals(object[] nmlMeshIds, AnimatorEditor dstAnimatorEditor, object[] adjacentAnimatorEditorMeshIdPairs, double adjacentSquaredDistance, bool worldCoordinates)
        {
            string path      = Path.GetDirectoryName(Parser.file.Parser.FilePath);
            string file      = Path.GetFileNameWithoutExtension(Parser.file.Parser.FilePath);
            string backupExt = Path.GetExtension(Parser.file.Parser.FilePath);

            backupExt = backupExt == String.Empty ? backupExt = "None" : backupExt.Substring(1);
            backupExt = (string)Properties.Settings.Default["BackupExtension" + backupExt];
            UnityParser   srcFileParser = new UnityParser(path + @"\" + file + ".bak0" + backupExt);
            Unity3dEditor srcFileEditor = new Unity3dEditor(srcFileParser);

            srcFileEditor.GetAssetNames(true);
            Animator srcAnimator = null;

            if (dstAnimatorEditor.Parser.classID() != UnityClassID.Animator)
            {
                Component baseAsset = srcFileParser.Cabinet.Components.Find
                                      (
                    delegate(Component asset)
                {
                    return(asset is NotLoaded && asset.classID() == UnityClassID.GameObject && ((NotLoaded)asset).Name == dstAnimatorEditor.Parser.m_GameObject.instance.m_Name);
                }
                                      );
                srcAnimator = srcFileEditor.OpenVirtualAnimator(srcFileParser.Cabinet.Components.IndexOf(baseAsset));
            }
            else
            {
                Component baseAsset = srcFileParser.Cabinet.Components.Find
                                      (
                    delegate(Component asset)
                {
                    return(asset is NotLoaded && asset.classID() == UnityClassID.Animator && ((NotLoaded)asset).Name == dstAnimatorEditor.Parser.m_GameObject.instance.m_Name);
                }
                                      );
                srcAnimator = srcFileEditor.OpenAnimator(srcFileParser.Cabinet.Components.IndexOf(baseAsset));
            }
            AnimatorEditor srcAnimatorEditor = new AnimatorEditor(srcAnimator);

            Component srcNmlAsset = srcFileParser.Cabinet.Components.Find
                                    (
                delegate(Component asset)
            {
                return(asset is NotLoaded && asset.classID() == UnityClassID.MonoBehaviour && ((NotLoaded)asset).Name == Parser.m_Name);
            }
                                    );
            NmlMonoBehaviour srcNml = srcFileEditor.OpenNmlMonoBehaviour(srcFileParser.Cabinet.Components.IndexOf(srcNmlAsset));

            ComputeMinMaxNormals(nmlMeshIds, dstAnimatorEditor, srcNml, -1, srcAnimatorEditor, adjacentAnimatorEditorMeshIdPairs, adjacentSquaredDistance, worldCoordinates);
        }
Ejemplo n.º 19
0
 public static void ExportAudioClip(UnityParser parser, string name, string path)
 {
     for (int i = 0; i < parser.Cabinet.Components.Count; i++)
     {
         Component asset = parser.Cabinet.Components[i];
         if (asset.classID1 == UnityClassID.AudioClip)
         {
             AudioClip ac = parser.Cabinet.LoadComponent(asset.pathID);
             if (name == "*" || ac.m_Name == name)
             {
                 ac.Export(path);
             }
         }
     }
 }
Ejemplo n.º 20
0
 public static void ExportShader(UnityParser parser, string name, string path)
 {
     for (int i = 0; i < parser.Cabinet.Components.Count; i++)
     {
         Component asset = parser.Cabinet.Components[i];
         if (asset.classID() == UnityClassID.Shader)
         {
             Shader sic = parser.Cabinet.LoadComponent(asset.pathID);
             if (name == "*" || sic.m_Name == name)
             {
                 sic.Export(path);
             }
         }
     }
 }
Ejemplo n.º 21
0
 public static void ExportTextAsset(UnityParser parser, string name, string path)
 {
     for (int i = 0; i < parser.Cabinet.Components.Count; i++)
     {
         Component asset = parser.Cabinet.Components[i];
         if (asset.classID1 == UnityClassID.TextAsset)
         {
             TextAsset taic = parser.Cabinet.LoadComponent(asset.pathID);
             if (name == "*" || taic.m_Name == name)
             {
                 taic.Export(path);
             }
         }
     }
 }
Ejemplo n.º 22
0
        public static string AddFirstNewPathID(UnityParser originalParser, UnityParser modParser, string path)
        {
            int firstNewPathID = -1;

            for (int i = 0; i < modParser.Cabinet.Components.Count; i++)
            {
                int       pathID = modParser.Cabinet.Components[i].pathID;
                Component comp   = originalParser.Cabinet.FindComponent(pathID);
                if (comp == null)
                {
                    firstNewPathID = pathID;
                    break;
                }
            }
            return(Path.GetDirectoryName(path) + @"\" + Path.GetFileNameWithoutExtension(path) + "-" + firstNewPathID + Path.GetExtension(path));
        }
Ejemplo n.º 23
0
        public static string AddFirstNewPathID(UnityParser originalParser, UnityParser modParser, string path)
        {
            long firstNewPathID = -1;

            for (int i = 0; i < modParser.Cabinet.Components.Count; i++)
            {
                long      pathID = modParser.Cabinet.Components[i].pathID;
                Component comp;
                if (!originalParser.Cabinet.findComponent.TryGetValue(pathID, out comp))
                {
                    firstNewPathID = pathID;
                    break;
                }
            }
            return(Path.GetDirectoryName(path) + @"\" + Path.GetFileNameWithoutExtension(path) + "-" + firstNewPathID + Path.GetExtension(path));
        }
Ejemplo n.º 24
0
        public static void ReplaceMaterial(UnityParser parser, ImportedMaterial material)
        {
            for (int i = 0; i < parser.Cabinet.Components.Count; i++)
            {
                Component comp = parser.Cabinet.Components[i];
                if (comp.classID1 == UnityClassID.Material)
                {
                    Material mat = parser.Cabinet.LoadComponent(comp.pathID);
                    if (mat.m_Name == material.Name)
                    {
                        ReplaceMaterial(mat, material);
                        return;
                    }
                }
            }

            throw new Exception("Replacing a material currently requires an existing material with the same name");
        }
Ejemplo n.º 25
0
        public FormAudioClip(UnityParser uParser, string audioClipParserVar)
        {
            InitializeComponent();

            AudioClip parser = (AudioClip)Gui.Scripting.Variables[audioClipParserVar];

            this.Text        = parser.m_Name;
            this.ToolTipText = uParser.FilePath + @"\" + parser.m_Name;

            ParserVar = audioClipParserVar;

            EditorVar = Gui.Scripting.GetNextVariable("audioClipEditor");
            Editor    = (AudioClipEditor)Gui.Scripting.RunScript(EditorVar + " = AudioClipEditor(parser=" + ParserVar + ")");

            Gui.Docking.ShowDockContent(this, Gui.Docking.DockEditors, ContentCategory.Others);

            Init();
            LoadAudioClip();
        }
Ejemplo n.º 26
0
        public static UnityParser DeployCollect(UnityParser parser, object[] animatorEditors, object[] singleAssets)
        {
            HashSet <Component> collection = new HashSet <Component>();

            if (animatorEditors != null)
            {
                AnimatorEditor[] editors = Utility.Convert <AnimatorEditor>(animatorEditors);
                foreach (AnimatorEditor animEditor in editors)
                {
                    Collect(animEditor, collection);
                }
            }

            if (singleAssets != null)
            {
                long[] singles = Utility.Convert <long>(singleAssets);
                foreach (long pathID in singles)
                {
                    Component asset = parser.Cabinet.LoadComponent(pathID);
                    collection.Add(asset);
                }
            }

            collection.Remove(null);

            UnityParser p = new UnityParser(parser);

            p.Cabinet.Components.AddRange(collection);
            p.Cabinet.Components.Sort
            (
                delegate(Component a, Component b)
            {
                return(a.pathID.CompareTo(b.pathID));
            }
            );
            p.InitTextures();
            if (parser.Cabinet.Bundle != null)
            {
                parser.Cabinet.Bundle.Clone(p.Cabinet);
            }
            return(p);
        }
Ejemplo n.º 27
0
        public static void ReplaceTextAsset(UnityParser parser, string path)
        {
            TextAsset ta = TextAsset.Import(path);

            if (ta.m_Script.Length > 0)
            {
                for (int i = 0; i < parser.Cabinet.Components.Count; i++)
                {
                    Component asset = parser.Cabinet.Components[i];
                    if (asset.classID1 == UnityClassID.TextAsset)
                    {
                        TextAsset taic = parser.Cabinet.LoadComponent(asset.pathID);
                        if (taic.m_Name == ta.m_Name)
                        {
                            taic.m_Script = ta.m_Script;
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 28
0
        public static void ReplaceShader(UnityParser parser, string path)
        {
            Shader s = Shader.Import(path);

            if (s.m_Script.Length > 0)
            {
                for (int i = 0; i < parser.Cabinet.Components.Count; i++)
                {
                    Component asset = parser.Cabinet.Components[i];
                    if (asset.classID1 == UnityClassID.Shader)
                    {
                        Shader sic = parser.Cabinet.LoadComponent(asset.pathID);
                        if (sic.m_Name == s.m_Name)
                        {
                            sic.m_Script = s.m_Script;
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
0
        public static void ReplaceAudioClip(UnityParser parser, string path)
        {
            AudioClip ac = AudioClip.Import(path);

            if (ac.m_AudioData.Length > 0)
            {
                for (int i = 0; i < parser.Cabinet.Components.Count; i++)
                {
                    Component asset = parser.Cabinet.Components[i];
                    if (asset.classID1 == UnityClassID.AudioClip)
                    {
                        AudioClip acic = parser.Cabinet.LoadComponent(asset.pathID);
                        if (acic.m_Name == ac.m_Name)
                        {
                            acic.m_AudioData = ac.m_AudioData;
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 30
0
        public static void UnloadModifiedTextures(UnityParser parser)
        {
            if (parser.Cabinet.VersionNumber >= AssetCabinet.VERSION_5_0_0)
            {
                Stream stream = parser.Uncompressed == null?File.OpenRead(parser.FilePath) : parser.Uncompressed;

                try
                {
                    for (int i = 0; i < parser.Textures.Count; i++)
                    {
                        Texture2D tex = parser.Textures[i] as Texture2D;
                        if (tex == null || tex.m_StreamData.path.Length == 0)
                        {
                            continue;
                        }
                        if (tex.m_StreamData.path != Path.GetFileName(parser.FilePath) + ".resS")
                        {
                            foreach (NotLoaded notLoaded in parser.Cabinet.RemovedList)
                            {
                                if (notLoaded.replacement == tex)
                                {
                                    stream.Position = notLoaded.offset;
                                    tex.LoadFrom(stream);
                                    break;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    if (stream != parser.Uncompressed)
                    {
                        stream.Close();
                        stream.Dispose();
                    }
                }
            }
        }