示例#1
0
    // Save audio to file
    private void ExportAudioClip(Unity_Studio.AssetPreloadData asset)
    {
        Unity_Studio.AudioClip m_AudioClip = new Unity_Studio.AudioClip(asset, false);
        Directory.CreateDirectory(ContentData.ContentPath());
        Directory.CreateDirectory(ContentData.ContentPath() + gameType);
        Directory.CreateDirectory(ContentData.ContentPath() + gameType + "/ffg");
        Directory.CreateDirectory(ContentData.ContentPath() + gameType + "/ffg/audio");
        string fileCandidate = ContentData.ContentPath() + gameType + "/ffg/audio/" + asset.Text;
        string fileName      = fileCandidate + asset.extension;

        m_AudioClip = new Unity_Studio.AudioClip(asset, true);
        // This should apend a postfix to the name to avoid collisions, but as we import multiple times
        // This is broken
        while (File.Exists(fileName))
        {
            return;// Fixme;
        }

        // Write to disk
        using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
        {
            writer.Write(m_AudioClip.m_AudioData);
            writer.Close();
        }
    }
示例#2
0
        // Save audio to file
        private void ExportAudioClip(Unity_Studio.AssetPreloadData asset)
        {
            Unity_Studio.AudioClip m_AudioClip = new Unity_Studio.AudioClip(asset, false);
            Directory.CreateDirectory(contentPath);
            Directory.CreateDirectory(contentPath + "/audio");

            string fileCandidate = contentPath + "/audio/" + asset.Text;
            string fileName      = fileCandidate + ".ogg";

            // This should apend a postfix to the name to avoid collisions, but as we import multiple times
            // This is broken
            while (File.Exists(fileName))
            {
                return;// Fixme;
            }

            // Pass to FSB Export
            m_AudioClip = new Unity_Studio.AudioClip(asset, true);
            FSBExport.Write(m_AudioClip.m_AudioData, fileName);
        }
示例#3
0
        // Save audio to file
        private void ExportAudioClip(Unity_Studio.AssetPreloadData asset)
        {
            if (asset == null)
            {
                throw new ArgumentNullException("asset");
            }
            var    audioClip = new Unity_Studio.AudioClip(asset, false);
            string audioPath = Path.Combine(contentPath, "audio");

            Directory.CreateDirectory(audioPath);

            string fileCandidate = Path.Combine(audioPath, asset.Text);

            // This should apends a postfix to the name to avoid collisions
            string fileName = GetAvailableFileName(fileCandidate, ".ogg");

            // Pass to FSB Export
            audioClip = new Unity_Studio.AudioClip(asset, true);
            FSBExport.Write(audioClip.m_AudioData, fileName);
        }
示例#4
0
    private void ExportAudioClip(Unity_Studio.AssetPreloadData asset)
    {
        Unity_Studio.AudioClip m_AudioClip = new Unity_Studio.AudioClip(asset, false);
        Directory.CreateDirectory(ContentData.ContentPath());
        Directory.CreateDirectory(ContentData.ContentPath() + gameType);
        Directory.CreateDirectory(ContentData.ContentPath() + gameType + "/ffg");
        Directory.CreateDirectory(ContentData.ContentPath() + gameType + "/ffg/audio");
        string fileCandidate = ContentData.ContentPath() + gameType + "/ffg/audio/" + asset.Text;
        string fileName      = fileCandidate + asset.extension;

        m_AudioClip = new Unity_Studio.AudioClip(asset, true);
        while (File.Exists(fileName))
        {
            return;// Fixme;
        }

        using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
        {
            writer.Write(m_AudioClip.m_AudioData);
            writer.Close();
        }
    }
示例#5
0
        private void BuildAssetStrucutres()
        {
            #region first loop - read asset data & create list
            if (!dontLoadAssetsMenuItem.Checked)
            {
                assetListView.BeginUpdate();
                progressBar1.Value = 0;
                progressBar1.Maximum = totalAssetCount;

                string fileIDfmt = "D" + assetsfileList.Count.ToString().Length.ToString();

                foreach (var assetsFile in assetsfileList)
                {
                    StatusStripUpdate("Building asset list from " + Path.GetFileName(assetsFile.filePath));

                    var a_Stream = assetsFile.a_Stream;
                    var fileGen = assetsFile.fileGen;
                    //var m_version = assetsFile.m_version;
                    var version = assetsFile.version;
                    string fileID = assetsfileList.IndexOf(assetsFile).ToString(fileIDfmt);

                    //ListViewGroup assetGroup = new ListViewGroup(Path.GetFileName(assetsFile.filePath));


                    foreach (var asset in assetsFile.preloadTable.Values)
                    {
                        asset.uniqueID = fileID + asset.uniqueID;
                        a_Stream.Position = asset.Offset;

                        switch (asset.Type2)
                        {
                            case 1: //GameObject
                                {
                                    GameObject m_GameObject = new GameObject(asset);
                                    assetsFile.GameObjectList.Add(asset.m_PathID, m_GameObject);
                                    totalTreeNodes++;
                                    break;
                                }
                            case 4: //Transform
                                {
                                    Transform m_Transform = new Transform(asset);
                                    assetsFile.TransformList.Add(asset.m_PathID, m_Transform);
                                    break;
                                }
                            case 224: //RectTransform
                                {
                                    RectTransform m_Rect = new RectTransform(asset);
                                    assetsFile.TransformList.Add(asset.m_PathID, m_Rect.m_Transform);
                                    break;
                                }
                            //case 21: //Material
                            case 28: //Texture2D
                                {
                                    Texture2D m_Texture2D = new Texture2D(asset, false);

                                    asset.Text = m_Texture2D.m_Name;
                                    asset.exportSize = 128 + m_Texture2D.image_data_size;

                                    #region Get Info Text
                                    asset.InfoText = "Width: " + m_Texture2D.m_Width.ToString() + "\nHeight: " + m_Texture2D.m_Height.ToString() + "\nFormat: ";

                                    switch (m_Texture2D.m_TextureFormat)
                                    {
                                        case 1: asset.InfoText += "Alpha8"; break;
                                        case 2: asset.InfoText += "ARGB 4.4.4.4"; break;
                                        case 3: asset.InfoText += "BGR 8.8.8"; break;
                                        case 4: asset.InfoText += "GRAB 8.8.8.8"; break;
                                        case 5: asset.InfoText += "BGRA 8.8.8.8"; break;
                                        case 7: asset.InfoText += "RGB 5.6.5"; break;
                                        case 10: asset.InfoText += "RGB DXT1"; break;
                                        case 12: asset.InfoText += "ARGB DXT5"; break;
                                        case 13: asset.InfoText += "RGBA 4.4.4.4"; break;
                                        case 30: asset.InfoText += "PVRTC_RGB2"; asset.exportSize -= 76; break;
                                        case 31: asset.InfoText += "PVRTC_RGBA2"; asset.exportSize -= 76; break;
                                        case 32: asset.InfoText += "PVRTC_RGB4"; asset.exportSize = 52; break;
                                        case 33: asset.InfoText += "PVRTC_RGBA4"; asset.exportSize -= 76; break;
                                        case 34: asset.InfoText += "ETC_RGB4"; asset.exportSize -= 76; break;
                                        default: asset.InfoText += "unknown"; asset.exportSize -= 128; break;
                                    }

                                    switch (m_Texture2D.m_FilterMode)
                                    {
                                        case 0: asset.InfoText += "\nFilter Mode: Point "; break;
                                        case 1: asset.InfoText += "\nFilter Mode: Bilinear "; break;
                                        case 2: asset.InfoText += "\nFilter Mode: Trilinear "; break;

                                    }

                                    asset.InfoText += "\nAnisotropic level: " + m_Texture2D.m_Aniso.ToString() + "\nMip map bias: " + m_Texture2D.m_MipBias.ToString();

                                    switch (m_Texture2D.m_WrapMode)
                                    {
                                        case 0: asset.InfoText += "\nWrap mode: Repeat"; break;
                                        case 1: asset.InfoText += "\nWrap mode: Clamp"; break;
                                    }
                                    #endregion

                                    assetsFile.exportableAssets.Add(asset);
                                    break;
                                }
                            case 49: //TextAsset
                                {
                                    TextAsset m_TextAsset = new TextAsset(asset, false);

                                    asset.Text = m_TextAsset.m_Name;
                                    asset.exportSize = m_TextAsset.exportSize;
                                    assetsFile.exportableAssets.Add(asset);
                                    break;
                                }
                            case 83: //AudioClip
                                {
                                    AudioClip m_AudioClip = new AudioClip(asset, false);

                                    asset.Text = m_AudioClip.m_Name;
                                    asset.exportSize = (int)m_AudioClip.m_Size;
                                    assetsFile.exportableAssets.Add(asset);
                                    break;
                                }
                            case 48: //Shader
                            case 89: //CubeMap
                            case 128: //Font
                                {
                                    asset.Text = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                                    assetsFile.exportableAssets.Add(asset);
                                    break;
                                }
                            case 129: //PlayerSettings
                                {
                                    PlayerSettings plSet = new PlayerSettings(asset);
                                    productName = plSet.productName;
                                    base.Text = "Unity Studio - " + productName + " - " + assetsFile.m_Version + " - " + assetsFile.platformStr;
                                    break;
                                }

                        }

                        if (asset.Text == "") { asset.Text = asset.TypeString + " #" + asset.uniqueID; }
                        asset.SubItems.AddRange(new string[] { asset.TypeString, asset.exportSize.ToString() });

                        progressBar1.PerformStep();
                    }

                    exportableAssets.AddRange(assetsFile.exportableAssets);
                    //if (assetGroup.Items.Count > 0) { listView1.Groups.Add(assetGroup); }
                }

                if (base.Text == "Unity Studio" && assetsfileList.Count > 0)
                {
                    base.Text = "Unity Studio - no productName - " + assetsfileList[0].m_Version + " - " + assetsfileList[0].platformStr;
                }

                visibleAssets = exportableAssets;
                assetListView.VirtualListSize = visibleAssets.Count;

                //will only work if ListView is visible
                resizeAssetListColumns();

                assetListView.EndUpdate();
                progressBar1.Value = 0;
            }
            #endregion

            #region second loop - build tree structure
            if (!dontBuildHierarchyMenuItem.Checked)
            {
                sceneTreeView.BeginUpdate();
                progressBar1.Value = 0;
                progressBar1.Maximum = totalTreeNodes;

                foreach (var assetsFile in assetsfileList)
                {
                    StatusStripUpdate("Building tree structure from " + Path.GetFileName(assetsFile.filePath));
                    GameObject fileNode = new GameObject(null);
                    fileNode.Text = Path.GetFileName(assetsFile.filePath);
                    fileNode.m_Name = "RootNode";

                    foreach (var m_GameObject in assetsFile.GameObjectList.Values)
                    {
                        var parentNode = fileNode;

                        Transform m_Transform;
                        if (assetsfileList.TryGetTransform(m_GameObject.m_Transform, out m_Transform))
                        {
                            Transform m_Father;
                            if (assetsfileList.TryGetTransform(m_Transform.m_Father, out m_Father))
                            {
                                //GameObject Parent;
                                if (assetsfileList.TryGetGameObject(m_Father.m_GameObject, out parentNode))
                                {
                                    //parentNode = Parent;
                                }
                            }
                        }

                        parentNode.Nodes.Add(m_GameObject);
                        progressBar1.PerformStep();
                    }


                    if (fileNode.Nodes.Count == 0) { fileNode.Text += " (no children)"; }
                    sceneTreeView.Nodes.Add(fileNode);
                }
                sceneTreeView.EndUpdate();
                progressBar1.Value = 0;

                if (File.Exists(mainPath + "\\materials.json"))
                {
                    string matLine = "";
                    using (StreamReader reader = File.OpenText(mainPath + "\\materials.json"))
                    { matLine = reader.ReadToEnd(); }

                    jsonMats = new JavaScriptSerializer().Deserialize<Dictionary<string, Dictionary<string, string>>>(matLine);
                    //var jsonMats = new JavaScriptSerializer().DeserializeObject(matLine);
                }
            }
            #endregion

            #region build list of class strucutres
            if (buildClassStructuresMenuItem.Checked)
            {
                //group class structures by versionv
                foreach (var assetsFile in assetsfileList)
                {
                    SortedDictionary<int, ClassStrStruct> curVer;
                    if (AllClassStructures.TryGetValue(assetsFile.m_Version, out curVer))
                    {
                        foreach (var uClass in assetsFile.ClassStructures)
                        {
                            curVer[uClass.Key] = uClass.Value;
                        }
                    }
                    else { AllClassStructures.Add(assetsFile.m_Version, assetsFile.ClassStructures); }
                }

                classesListView.BeginUpdate();
                foreach (var version in AllClassStructures)
                {
                    ListViewGroup versionGroup = new ListViewGroup(version.Key);
                    classesListView.Groups.Add(versionGroup);

                    foreach (var uclass in version.Value)
                    {
                        uclass.Value.Group = versionGroup;
                        classesListView.Items.Add(uclass.Value);
                    }
                }
                classesListView.EndUpdate();
            }
            #endregion

            StatusStripUpdate("Finished loading " + assetsfileList.Count.ToString() + " files with " + (assetListView.Items.Count + sceneTreeView.Nodes.Count).ToString() + " exportable assets.");
            
            progressBar1.Value = 0;
            treeSearch.Select();
            TexEnv dsd = new TexEnv();
        }
示例#6
0
        private int ExportAsset(AssetPreloadData asset, string exportPath)
        {
            int exportCount = 0;
            
            switch (asset.Type2)
            {
                #region Texture2D
                case 28: //Texture2D
                    {
                        Texture2D m_Texture2D = new Texture2D(asset, true);
                        
                        string texPath = exportPath + "\\" + asset.Text;
                        if (uniqueNames.Checked) { texPath += " #" + asset.uniqueID; }
                        if (m_Texture2D.m_TextureFormat < 30) { texPath += ".dds"; }
                        else if (m_Texture2D.m_TextureFormat < 35) { texPath += ".pvr"; }
                        else { texPath += "_" + m_Texture2D.m_Width.ToString() + "x" + m_Texture2D.m_Height.ToString() + "." + m_Texture2D.m_TextureFormat.ToString() + ".tex"; }

                        if (File.Exists(texPath))
                        {
                            StatusStripUpdate("Texture file " + Path.GetFileName(texPath) + " already exists");
                        }
                        else
                        {
                            StatusStripUpdate("Exporting Texture2D: " + Path.GetFileName(texPath));
                            exportCount += 1;

                            switch (m_Texture2D.m_TextureFormat)
                            {
                                case 1: //Alpha8
                                case 2: //A4R4G4B4
                                case 3: //B8G8R8 //confirmed on X360, iOS //PS3 unsure
                                case 4: //G8R8A8B8 //confirmed on X360, iOS
                                case 5: //B8G8R8A8 //confirmed on X360, PS3, Web, iOS
                                case 7: //R5G6B5 //confirmed switched on X360; confirmed on iOS
                                case 10: //DXT1
                                case 12: //DXT5
                                case 13: //R4G4B4A4, iOS (only?)
                                    WriteDDS(texPath, m_Texture2D);
                                    break;
                                case 30: //PVRTC_RGB2
                                case 31: //PVRTC_RGBA2
                                case 32: //PVRTC_RGB4
                                case 33: //PVRTC_RGBA4
                                case 34: //ETC_RGB4
                                    WritePVR(texPath, m_Texture2D);
                                    break;
                                default:
                                    {
                                        using (BinaryWriter writer = new BinaryWriter(File.Open(texPath, FileMode.Create)))
                                        {
                                            writer.Write(m_Texture2D.image_data);
                                            writer.Close();
                                        }
                                        break;
                                    }
                            }
                        }
                        break;
                    }
                #endregion
                #region AudioClip
                case 83: //AudioClip
                    {
                        AudioClip m_AudioClip = new AudioClip(asset, true);
                        
                        string audPath = exportPath + "\\" + asset.Text;
                        if (uniqueNames.Checked) { audPath += " #" + asset.uniqueID; }
                        audPath += m_AudioClip.extension;

                        if (File.Exists(audPath))
                        {
                            StatusStripUpdate("Audio file " + Path.GetFileName(audPath) + " already exists");
                        }
                        else
                        {
                            StatusStripUpdate("Exporting AudioClip: " + Path.GetFileName(audPath));
                            exportCount += 1;
                            
                            using (BinaryWriter writer = new BinaryWriter(File.Open(audPath, FileMode.Create)))
                            {
                                writer.Write(m_AudioClip.m_AudioData);
                                writer.Close();
                            }

                        }
                        break;
                    }
                #endregion
                #region Shader & TextAsset
                case 48: //Shader
                case 49: //TextAsset
                    {
                        TextAsset m_TextAsset = new TextAsset(asset, true);

                        string textAssetPath = exportPath + "\\" + asset.Text;
                        if (uniqueNames.Checked) { textAssetPath += " #" + asset.uniqueID; }
                        textAssetPath += m_TextAsset.extension;

                        if (File.Exists(textAssetPath))
                        {
                            StatusStripUpdate("TextAsset file " + Path.GetFileName(textAssetPath) + " already exists");
                        }
                        else
                        {
                            StatusStripUpdate("Exporting TextAsset: " + Path.GetFileName(textAssetPath));
                            exportCount += 1;

                            using (BinaryWriter writer = new BinaryWriter(File.Open(textAssetPath, FileMode.Create)))
                            {
                                writer.Write(m_TextAsset.m_Script);
                                writer.Close();
                            }
                        }
                        break;
                    }
                #endregion
                #region Font
                case 128: //Font
                    {
                        unityFont m_Font = new unityFont(asset);

                        if (m_Font.m_FontData != null)
                        {
                            string fontPath = exportPath + "\\" + asset.Text;
                            if (uniqueNames.Checked) { fontPath += " #" + asset.uniqueID; }
                            fontPath += m_Font.extension;

                            if (File.Exists(fontPath))
                            {
                                StatusStripUpdate("Font file " + Path.GetFileName(fontPath) + " already exists");
                            }
                            else
                            {
                                StatusStripUpdate("Exporting Font: " + Path.GetFileName(fontPath));

                                using (BinaryWriter writer = new BinaryWriter(File.Open(fontPath, FileMode.Create)))
                                {
                                    writer.Write(m_Font.m_FontData);
                                    writer.Close();
                                }

                                exportCount += 1;
                            }
                        }
                        break;
                    }
                #endregion
                /*default:
                    {
                        string assetPath = exportPath + "\\" + asset.Name + "." + asset.TypeString;
                        byte[] assetData = new byte[asset.Size];
                        Stream.Read(assetData, 0, asset.Size);
                        using (BinaryWriter writer = new BinaryWriter(File.Open(assetPath, FileMode.Create)))
                        {
                            writer.Write(assetData);
                            writer.Close();
                        }
                        exportCount += 1;
                        break;
                    }*/
            }
            return exportCount;
        }
示例#7
0
        private void PreviewAsset(AssetPreloadData asset)
        {
            switch (asset.Type2)
            {
                #region Texture2D
                case 28: //Texture2D
                    {
                        Texture2D m_Texture2D = new Texture2D(asset, true);
                        
                        if (m_Texture2D.m_TextureFormat < 30)
                        {
                            byte[] imageBuffer = new byte[128 + m_Texture2D.image_data_size];

                            imageBuffer[0] = 0x44;
                            imageBuffer[1] = 0x44;
                            imageBuffer[2] = 0x53;
                            imageBuffer[3] = 0x20;
                            imageBuffer[4] = 0x7c;
                            
                            BitConverter.GetBytes(m_Texture2D.dwFlags).CopyTo(imageBuffer, 8);
                            BitConverter.GetBytes(m_Texture2D.m_Height).CopyTo(imageBuffer, 12);
                            BitConverter.GetBytes(m_Texture2D.m_Width).CopyTo(imageBuffer, 16);
                            BitConverter.GetBytes(m_Texture2D.dwPitchOrLinearSize).CopyTo(imageBuffer, 20);
                            BitConverter.GetBytes(m_Texture2D.dwMipMapCount).CopyTo(imageBuffer, 28);
                            BitConverter.GetBytes(m_Texture2D.dwSize).CopyTo(imageBuffer, 76);
                            BitConverter.GetBytes(m_Texture2D.dwFlags2).CopyTo(imageBuffer, 80);
                            BitConverter.GetBytes(m_Texture2D.dwFourCC).CopyTo(imageBuffer, 84);
                            BitConverter.GetBytes(m_Texture2D.dwRGBBitCount).CopyTo(imageBuffer, 88);
                            BitConverter.GetBytes(m_Texture2D.dwRBitMask).CopyTo(imageBuffer, 92);
                            BitConverter.GetBytes(m_Texture2D.dwGBitMask).CopyTo(imageBuffer, 96);
                            BitConverter.GetBytes(m_Texture2D.dwBBitMask).CopyTo(imageBuffer, 100);
                            BitConverter.GetBytes(m_Texture2D.dwABitMask).CopyTo(imageBuffer, 104);
                            BitConverter.GetBytes(m_Texture2D.dwCaps).CopyTo(imageBuffer, 108);
                            BitConverter.GetBytes(m_Texture2D.dwCaps2).CopyTo(imageBuffer, 112);
                            
                            m_Texture2D.image_data.CopyTo(imageBuffer, 128);

                            imageTexture = DDSDataToBMP(imageBuffer);
                            imageTexture.RotateFlip(RotateFlipType.RotateNoneFlipY);
                            previewPanel.BackgroundImage = imageTexture;
                            previewPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
                        }
                        else { StatusStripUpdate("Unsupported image for preview. Try to export."); }
                        break;
                    }
                #endregion
                #region AudioClip
                case 83: //AudioClip
                    {
                        AudioClip m_AudioClip = new AudioClip(asset, true);

                        //MemoryStream memoryStream = new MemoryStream(m_AudioData, true);
                        //System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(memoryStream);
                        //soundPlayer.Play();

                        FMOD.RESULT result;
                        FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();
                        
                        exinfo.cbsize = Marshal.SizeOf(exinfo);
                        exinfo.length = (uint)m_AudioClip.m_Size;

                        result = system.createSound(m_AudioClip.m_AudioData, (FMOD.MODE.OPENMEMORY | loopMode), ref exinfo, out sound);
                        if (ERRCHECK(result)) { break; }

                        result = sound.getLength(out FMODlenms, FMOD.TIMEUNIT.MS);
                        if ((result != FMOD.RESULT.OK) && (result != FMOD.RESULT.ERR_INVALID_HANDLE))
                        {
                            if (ERRCHECK(result)) { break; }
                        }

                        result = system.playSound(sound, null, false, out channel);
                        if (ERRCHECK(result)) { break; }

                        timer.Start();
                        FMODstatusLabel.Text = "Playing";
                        FMODpanel.Visible = true;

                        //result = channel.getChannelGroup(out channelGroup);
                        //if (ERRCHECK(result)) { break; }

                        result = channel.getFrequency(out FMODfrequency);
                        ERRCHECK(result);

                        FMODinfoLabel.Text = FMODfrequency.ToString() + " Hz";
                        break;
                    }
                #endregion
                #region Shader & TextAsset
                case 48:
                case 49:
                    {
                        TextAsset m_TextAsset = new TextAsset(asset, true);
                        
                        string m_Script_Text = UnicodeEncoding.UTF8.GetString(m_TextAsset.m_Script);
                        m_Script_Text = Regex.Replace(m_Script_Text, "(?<!\r)\n", "\r\n");
                        textPreviewBox.Text = m_Script_Text;
                        textPreviewBox.Visible = true;

                        break;
                    }
                #endregion
                #region Font
                case 128: //Font
                    {
                        unityFont m_Font = new unityFont(asset);
                        
                        if (m_Font.extension != ".otf" && m_Font.m_FontData != null)
                        {
                            IntPtr data = Marshal.AllocCoTaskMem(m_Font.m_FontData.Length);
                            Marshal.Copy(m_Font.m_FontData, 0, data, m_Font.m_FontData.Length);

                            System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
                            // We HAVE to do this to register the font to the system (Weird .NET bug !)
                            uint cFonts = 0;
                            AddFontMemResourceEx(data, (uint)m_Font.m_FontData.Length, IntPtr.Zero, ref cFonts);

                            pfc.AddMemoryFont(data, m_Font.m_FontData.Length);
                            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(data);

                            //textPreviewBox.Font = new Font(pfc.Families[0], 16, FontStyle.Regular);
                            //textPreviewBox.Text = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWYZ\r\n1234567890.:,;'\"(!?)+-*/=\r\nThe quick brown fox jumps over the lazy dog. 1234567890";
                            fontPreviewBox.SelectionStart = 0;
                            fontPreviewBox.SelectionLength = 80;
                            fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 16, FontStyle.Regular);
                            fontPreviewBox.SelectionStart = 81;
                            fontPreviewBox.SelectionLength = 56;
                            fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 12, FontStyle.Regular);
                            fontPreviewBox.SelectionStart = 138;
                            fontPreviewBox.SelectionLength = 56;
                            fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 18, FontStyle.Regular);
                            fontPreviewBox.SelectionStart = 195;
                            fontPreviewBox.SelectionLength = 56;
                            fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 24, FontStyle.Regular);
                            fontPreviewBox.SelectionStart = 252;
                            fontPreviewBox.SelectionLength = 56;
                            fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 36, FontStyle.Regular);
                            fontPreviewBox.SelectionStart = 309;
                            fontPreviewBox.SelectionLength = 56;
                            fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 48, FontStyle.Regular);
                            fontPreviewBox.SelectionStart = 366;
                            fontPreviewBox.SelectionLength = 56;
                            fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 60, FontStyle.Regular);
                            fontPreviewBox.SelectionStart = 423;
                            fontPreviewBox.SelectionLength = 55;
                            fontPreviewBox.SelectionFont = new Font(pfc.Families[0], 72, FontStyle.Regular);
                            fontPreviewBox.Visible = true;
                        }
                        else { StatusStripUpdate("Unsupported font for preview. Try to export."); }

                        break;
                    }
                #endregion
            }
        }
示例#8
0
        private void BuildAssetStrucutres()
        {
            #region first loop - read asset data & create list
            if (!dontLoadAssetsMenuItem.Checked)
            {
                assetListView.BeginUpdate();
                progressBar1.Value = 0;
                progressBar1.Maximum = totalAssetCount;

                string fileIDfmt = "D" + assetsfileList.Count.ToString().Length.ToString();

                foreach (var assetsFile in assetsfileList)
                {
                    StatusStripUpdate("Building asset list from " + Path.GetFileName(assetsFile.filePath));

                    string fileID = assetsfileList.IndexOf(assetsFile).ToString(fileIDfmt);

                    //ListViewGroup assetGroup = new ListViewGroup(Path.GetFileName(assetsFile.filePath));


                    foreach (var asset in assetsFile.preloadTable.Values)
                    {
                        asset.uniqueID = fileID + asset.uniqueID;

                        switch (asset.Type2)
                        {
                            case 1: //GameObject
                                {
                                    GameObject m_GameObject = new GameObject(asset);
                                    assetsFile.GameObjectList.Add(asset.m_PathID, m_GameObject);
                                    totalTreeNodes++;
                                    break;
                                }
                            case 4: //Transform
                                {
                                    Transform m_Transform = new Transform(asset);
                                    assetsFile.TransformList.Add(asset.m_PathID, m_Transform);
                                    break;
                                }
                            case 224: //RectTransform
                                {
                                    RectTransform m_Rect = new RectTransform(asset);
                                    assetsFile.TransformList.Add(asset.m_PathID, m_Rect.m_Transform);
                                    break;
                                }
                            //case 21: //Material
                            case 28: //Texture2D
                                {
                                    Texture2D m_Texture2D = new Texture2D(asset, false);
                                    assetsFile.exportableAssets.Add(asset);
                                    break;
                                }
                            case 48: //Shader
                            case 49: //TextAsset
                                {
                                    TextAsset m_TextAsset = new TextAsset(asset, false);
                                    assetsFile.exportableAssets.Add(asset);
                                    break;
                                }
                            case 83: //AudioClip
                                {
                                    AudioClip m_AudioClip = new AudioClip(asset, false);
                                    assetsFile.exportableAssets.Add(asset);
                                    break;
                                }
                            //case 89: //CubeMap
                            case 128: //Font
                                {
                                    unityFont m_Font = new unityFont(asset, false);
                                    assetsFile.exportableAssets.Add(asset);
                                    break;
                                }
                            case 129: //PlayerSettings
                                {
                                    PlayerSettings plSet = new PlayerSettings(asset);
                                    productName = plSet.productName;
                                    base.Text = "Unity Studio - " + productName + " - " + assetsFile.m_Version + " - " + assetsFile.platformStr;
                                    break;
                                }
                            case 0:
                                break;

                        }

                        progressBar1.PerformStep();
                    }

                    exportableAssets.AddRange(assetsFile.exportableAssets);
                    //if (assetGroup.Items.Count > 0) { listView1.Groups.Add(assetGroup); }
                }

                if (base.Text == "Unity Studio" && assetsfileList.Count > 0)
                {
                    base.Text = "Unity Studio - no productName - " + assetsfileList[0].m_Version + " - " + assetsfileList[0].platformStr;
                }

                visibleAssets = exportableAssets;
                assetListView.VirtualListSize = visibleAssets.Count;

                //will only work if ListView is visible
                resizeAssetListColumns();

                assetListView.EndUpdate();
                progressBar1.Value = 0;
            }
            #endregion

            #region second loop - build tree structure
            if (!dontBuildHierarchyMenuItem.Checked)
            {
                sceneTreeView.BeginUpdate();
                progressBar1.Value = 0;
                progressBar1.Maximum = totalTreeNodes;

                foreach (var assetsFile in assetsfileList)
                {
                    StatusStripUpdate("Building tree structure from " + Path.GetFileName(assetsFile.filePath));
                    GameObject fileNode = new GameObject(null);
                    fileNode.Text = Path.GetFileName(assetsFile.filePath);
                    fileNode.m_Name = "RootNode";

                    foreach (var m_GameObject in assetsFile.GameObjectList.Values)
                    {
                        var parentNode = fileNode;

                        Transform m_Transform;
                        if (assetsfileList.TryGetTransform(m_GameObject.m_Transform, out m_Transform))
                        {
                            Transform m_Father;
                            if (assetsfileList.TryGetTransform(m_Transform.m_Father, out m_Father))
                            {
                                //GameObject Parent;
                                if (assetsfileList.TryGetGameObject(m_Father.m_GameObject, out parentNode))
                                {
                                    //parentNode = Parent;
                                }
                            }
                        }

                        parentNode.Nodes.Add(m_GameObject);
                        progressBar1.PerformStep();
                    }


                    if (fileNode.Nodes.Count == 0) { fileNode.Text += " (no children)"; }
                    sceneTreeView.Nodes.Add(fileNode);
                }
                sceneTreeView.EndUpdate();
                progressBar1.Value = 0;

                if (File.Exists(mainPath + "\\materials.json"))
                {
                    string matLine = "";
                    using (StreamReader reader = File.OpenText(mainPath + "\\materials.json"))
                    { matLine = reader.ReadToEnd(); }

                    jsonMats = new JavaScriptSerializer().Deserialize<Dictionary<string, Dictionary<string, string>>>(matLine);
                    //var jsonMats = new JavaScriptSerializer().DeserializeObject(matLine);
                }
            }
            #endregion

            #region build list of class strucutres
            if (buildClassStructuresMenuItem.Checked)
            {
                //group class structures by versionv
                foreach (var assetsFile in assetsfileList)
                {
                    SortedDictionary<int, ClassStrStruct> curVer;
                    if (AllClassStructures.TryGetValue(assetsFile.m_Version, out curVer))
                    {
                        foreach (var uClass in assetsFile.ClassStructures)
                        {
                            curVer[uClass.Key] = uClass.Value;
                        }
                    }
                    else { AllClassStructures.Add(assetsFile.m_Version, assetsFile.ClassStructures); }
                }

                classesListView.BeginUpdate();
                foreach (var version in AllClassStructures)
                {
                    ListViewGroup versionGroup = new ListViewGroup(version.Key);
                    classesListView.Groups.Add(versionGroup);

                    foreach (var uclass in version.Value)
                    {
                        uclass.Value.Group = versionGroup;
                        classesListView.Items.Add(uclass.Value);
                    }
                }
                classesListView.EndUpdate();
            }
            #endregion

            StatusStripUpdate("Finished loading " + assetsfileList.Count.ToString() + " files with " + (assetListView.Items.Count + sceneTreeView.Nodes.Count).ToString() + " exportable assets.");
            
            progressBar1.Value = 0;
            treeSearch.Select();
            
            saveFolderDialog1.InitialDirectory = mainPath;
        }
示例#9
0
 private void ExportAudioClip(AudioClip m_AudioClip, string exportFilename)
 {
     using (BinaryWriter writer = new BinaryWriter(File.Open(exportFilename, FileMode.Create)))
     {
         writer.Write(m_AudioClip.m_AudioData);
         writer.Close();
     }
 }
示例#10
0
        private void BuildAssetStrucutres()
        {
            #region first loop - read asset data & create list
            StatusStripUpdate("Building asset list...");
            assetListView.BeginUpdate();

            string fileIDfmt = "D" + assetsfileList.Count.ToString().Length.ToString();

            foreach (var assetsFile in assetsfileList)
            {
                var a_Stream = assetsFile.a_Stream;
                var fileGen = assetsFile.fileGen;
                //var m_version = assetsFile.m_version;
                var version = assetsFile.version;
                string fileID = "1" + assetsfileList.IndexOf(assetsFile).ToString(fileIDfmt);

                //ListViewGroup assetGroup = new ListViewGroup(Path.GetFileName(assetsFile.filePath));

                foreach (var asset in assetsFile.preloadTable.Values)
                {
                    asset.uniqueID = fileID + asset.uniqueID;
                    a_Stream.Position = asset.Offset;

                    switch (asset.Type2)
                    {
                        case 1: //GameObject
                            {
                                GameObject m_GameObject = new GameObject(asset);

                                //asset.Text = m_GameObject.m_Name;
                                asset.specificIndex = assetsFile.GameObjectList.Count;
                                assetsFile.GameObjectList.Add(m_GameObject);
                                break;
                            }
                        case 4: //Transform
                            {
                                Transform m_Transform = new Transform(asset);

                                asset.specificIndex = assetsFile.TransformList.Count;
                                assetsFile.TransformList.Add(m_Transform);
                                break;
                            }
                        case 224: //RectTransform
                            {
                                RectTransform m_Rect = new RectTransform(asset);

                                asset.specificIndex = assetsFile.TransformList.Count;
                                assetsFile.TransformList.Add(m_Rect.m_Transform);
                                break;
                            }
                        //case 21: //Material
                        case 28: //Texture2D
                            {
                                Texture2D m_Texture2D = new Texture2D(asset, false);

                                asset.Text = m_Texture2D.m_Name;
                                asset.exportSize = 128 + m_Texture2D.image_data_size;

                                #region Get Info Text
                                asset.InfoText = "Width: " + m_Texture2D.m_Width.ToString() + "\nHeight: " + m_Texture2D.m_Height.ToString() + "\nFormat: ";

                                switch (m_Texture2D.m_TextureFormat)
                                {
                                    case 1: asset.InfoText += "Alpha8"; break;
                                    case 2: asset.InfoText += "ARGB 4.4.4.4"; break;
                                    case 3: asset.InfoText += "BGR 8.8.8"; break;
                                    case 4: asset.InfoText += "GRAB 8.8.8.8"; break;
                                    case 5: asset.InfoText += "BGRA 8.8.8.8"; break;
                                    case 7: asset.InfoText += "RGB 5.6.5"; break;
                                    case 10: asset.InfoText += "RGB DXT1"; break;
                                    case 12: asset.InfoText += "ARGB DXT5"; break;
                                    case 13: asset.InfoText += "RGBA 4.4.4.4"; break;
                                    case 30: asset.InfoText += "PVRTC_RGB2"; asset.exportSize -= 76; break;
                                    case 31: asset.InfoText += "PVRTC_RGBA2"; asset.exportSize -= 76; break;
                                    case 32: asset.InfoText += "PVRTC_RGB4"; asset.exportSize = 52; break;
                                    case 33: asset.InfoText += "PVRTC_RGBA4"; asset.exportSize -= 76; break;
                                    case 34: asset.InfoText += "ETC_RGB4"; asset.exportSize -= 76; break;
                                    default: asset.InfoText += "unknown"; asset.exportSize -= 128; break;
                                }

                                switch (m_Texture2D.m_FilterMode)
                                {
                                    case 0: asset.InfoText += "\nFilter Mode: Point "; break;
                                    case 1: asset.InfoText += "\nFilter Mode: Bilinear "; break;
                                    case 2: asset.InfoText += "\nFilter Mode: Trilinear "; break;

                                }

                                asset.InfoText += "\nAnisotropic level: " + m_Texture2D.m_Aniso.ToString() + "\nMip map bias: " + m_Texture2D.m_MipBias.ToString();

                                switch (m_Texture2D.m_WrapMode)
                                {
                                    case 0: asset.InfoText += "\nWrap mode: Repeat"; break;
                                    case 1: asset.InfoText += "\nWrap mode: Clamp"; break;
                                }
                                #endregion

                                assetsFile.exportableAssets.Add(asset);
                                break;
                            }
                        case 49: //TextAsset
                            {
                                TextAsset m_TextAsset = new TextAsset(asset, false);

                                asset.Text = m_TextAsset.m_Name;
                                asset.exportSize = m_TextAsset.exportSize;
                                assetsFile.exportableAssets.Add(asset);
                                break;
                            }
                        case 83: //AudioClip
                            {
                                AudioClip m_AudioClip = new AudioClip(asset, false);

                                asset.Text = m_AudioClip.m_Name;
                                asset.exportSize = (int)m_AudioClip.m_Size;
                                assetsFile.exportableAssets.Add(asset);
                                break;
                            }
                        case 48: //Shader
                        case 89: //CubeMap
                        case 128: //Font
                            {
                                asset.Text = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                                assetsFile.exportableAssets.Add(asset);
                                break;
                            }
                        case 129: //PlayerSettings
                            {
                                PlayerSettings plSet = new PlayerSettings(asset);
                                productName = plSet.productName;
                                base.Text = "Unity Studio - " + productName + " - " + assetsFile.m_Version ;
                                break;
                            }

                    }

                    if (asset.Text == "") { asset.Text = asset.TypeString + " #" + asset.uniqueID; }
                    asset.SubItems.AddRange(new string[] { asset.TypeString, asset.exportSize.ToString() });
                }

                exportableAssets.AddRange(assetsFile.exportableAssets);
                //if (assetGroup.Items.Count > 0) { listView1.Groups.Add(assetGroup); }
            }

            visibleAssets = exportableAssets;
            assetListView.VirtualListSize = visibleAssets.Count;

            assetListView.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
            assetListView.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
            resizeNameColumn();

            assetListView.EndUpdate();
            #endregion

            #region second loop - build tree structure
            StatusStripUpdate("Building tree structure...");
            sceneTreeView.BeginUpdate();
            foreach (var assetsFile in assetsfileList)
            {
                GameObject fileNode = new GameObject(null);
                fileNode.Text = Path.GetFileName(assetsFile.filePath);

                foreach (var m_GameObject in assetsFile.GameObjectList)
                {
                    var parentNode = fileNode;

                    Transform m_Transform;
                    if (assetsfileList.TryGetTransform(m_GameObject.m_Transform, out m_Transform))
                    {
                        Transform m_Father;
                        if (assetsfileList.TryGetTransform(m_Transform.m_Father, out m_Father))
                        {
                            //GameObject Parent;
                            if (assetsfileList.TryGetGameObject(m_Father.m_GameObject, out parentNode))
                            {
                                //parentNode = Parent;
                            }
                        }
                    }

                    parentNode.Nodes.Add(m_GameObject);
                }

                if (fileNode.Nodes.Count == 0) { fileNode.Text += " (no children)"; }
                sceneTreeView.Nodes.Add(fileNode);
            }
            sceneTreeView.EndUpdate();
            #endregion

            if (File.Exists(mainPath + "\\materials.json"))
            {
                string matLine = "";
                using (StreamReader reader = File.OpenText(mainPath + "\\materials.json"))
                { matLine = reader.ReadToEnd(); }

                jsonMats = new JavaScriptSerializer().Deserialize<Dictionary<string, Dictionary<string, string>>>(matLine);
                //var jsonMats = new JavaScriptSerializer().DeserializeObject(matLine);
            }

            StatusStripUpdate("Finished loading " + assetsfileList.Count.ToString() + " files with " + (assetListView.Items.Count + sceneTreeView.Nodes.Count).ToString() + " exportable assets.");

            progressBar1.Value = 0;
            treeSearch.Select();
            TexEnv dsd = new TexEnv();
        }