Пример #1
0
        public void ImportAllJsonToAsset(string inputAssetsPath, string jsonDirectory, string outputAssetsPath)
        {
            using (AssetsFile file = AssetsFile.Open(inputAssetsPath))
            {
                var assetSerializer = new UnitySerializer(file);

                foreach (DataType dType in types)
                {
                    AssetInfo info     = file.GetAssetByName(dType.AssetName);
                    string    jsonPath = Path.Combine(jsonDirectory, $"{dType.AssetName}.json");
                    LogCallback?.Invoke(dType.AssetName);

                    var obj        = skylessSerializer.DeserializeJson(dType.TypeName, jsonPath);
                    var binaryData = skylessSerializer.SerializeBinary(dType.TypeName, obj);

                    var textAsset = new TextAsset();
                    textAsset.m_Name = dType.AssetName;
                    textAsset.m_Data = binaryData;

                    var assetData = assetSerializer.Serialize(textAsset);

                    file.ReplaceAsset(info.pathID, assetData);
                }

                file.Save(outputAssetsPath);
            }
        }
Пример #2
0
        public void ExportAllToJson(string resourceAssetsPath, string outputDirectory)
        {
            using (AssetsFile file = AssetsFile.Open(resourceAssetsPath))
            {
                var assetSerializer = new UnitySerializer(file);

                foreach (DataType dType in types)
                {
                    LogCallback?.Invoke(dType.AssetName);
                    AssetInfo info = file.GetAssetByName(dType.AssetName);

                    var textAsset = assetSerializer.Deserialize <TextAsset>(info);
                    var obj       = skylessSerializer.DeserializeBinary(dType.TypeName, textAsset.m_Data);

                    string jsonPath = Path.Combine(outputDirectory, $"{dType.AssetName}.json");
                    skylessSerializer.SerializeJson(jsonPath, obj);
                }
            }
        }
Пример #3
0
        private static void PatchSDF(string path)
        {
            string backupPath = path + ".bak";
            string tempPath   = path + ".tmp";

            using (AssetsFile f = AssetsFile.Open(path))
            {
                UnitySerializer   serializer = new UnitySerializer(f);
                TMP_FontAsset_3_0 newFont    = serializer.Deserialize <TMP_FontAsset_3_0>(Properties.Resources.FontDef);

                long patchedFontPathId = -1;

                foreach (var assetName in replaceFontNames)
                {
                    AssetInfo fontAsset = f.GetAssetByName(assetName);
                    if (fontAsset == null)
                    {
                        throw new AssetNotFoundException(assetName);
                    }
                    patchedFontPathId = fontAsset.pathID;
                    TMP_FontAsset_3_0 oldFont = serializer.Deserialize <TMP_FontAsset_3_0>(fontAsset);

                    newFont.m_Script        = oldFont.m_Script;
                    newFont.material        = oldFont.material;
                    newFont.atlas           = oldFont.atlas;
                    newFont.m_AtlasTextures = oldFont.m_AtlasTextures;

                    f.ReplaceAsset(fontAsset.pathID, serializer.Serialize(newFont));

                    int imageSize = newFont.m_AtlasWidth;

                    var atlas = serializer.Deserialize <Texture2D_2020_2_1_f1>(f.assets[oldFont.m_AtlasTextures[0].m_PathID]);
                    atlas.m_Width             = imageSize;
                    atlas.m_Height            = imageSize;
                    atlas.m_CompleteImageSize = imageSize * imageSize;
                    atlas.m_StreamData.offset = 0;
                    atlas.m_StreamData.size   = (uint)(imageSize * imageSize);
                    atlas.m_StreamData.path   = FONT_TEXTURE_FILENAME;

                    atlas.imageData = new byte[0];

                    f.ReplaceAsset(oldFont.m_AtlasTextures[0].m_PathID, serializer.Serialize(atlas));
                }

                foreach (var assetName in addFallbackFontNames)
                {
                    AssetInfo         fontAsset = f.GetAssetByName(assetName);
                    TMP_FontAsset_3_0 font      = serializer.Deserialize <TMP_FontAsset_3_0>(fontAsset);

                    font.m_FallbackFontAssetTable = new[] { new PPtr()
                                                            {
                                                                m_FileID = 0, m_PathID = patchedFontPathId
                                                            } };
                    font.fallbackFontAssets = new[] { new PPtr()
                                                      {
                                                          m_FileID = 0, m_PathID = patchedFontPathId
                                                      } };

                    f.ReplaceAsset(fontAsset.pathID, serializer.Serialize(font));
                }

                f.Save(tempPath);
            }

            if (File.Exists(backupPath))
            {
                File.Delete(backupPath);
            }
            File.Move(path, backupPath);
            File.Move(tempPath, path);
        }