예제 #1
0
        // Use to serialize an existing set of sprites in your mod.
        // Create a list of sprite names (case sensitive by the way) you want put into an atlas and this will output the atlas texture and JSON txt dump of the new sprite collection.
        // Note you may get exceptions if you don't give it a large enough atlas size to work with. I have been using the same defaultsize, Xres, and Yres.
        // Someone who better understands these fields could probably create better defaults but that's what worked for me.
        public static void SerializeSpriteCollection(string CollectionName, List <string> spriteNames, int Xres, int Yres, string pathOverride = null)
        {
            if (!ExpandSettings.spritesBundlePresent)
            {
                ETGModConsole.Log("[ExpandTheGungeon] Unserialized sprite textures stored in optional asset bundle but it is missing! Ensure you have it setup properly!");
                return;
            }
            GameObject m_TempObject = new GameObject(CollectionName);

            newCollection = GenerateNewSpriteCollection(m_TempObject);
            AtlasPacker   = new RuntimeAtlasPacker(Xres, Yres);
            AddSpriteToObject(m_TempObject, ExpandAssets.LoadSpriteAsset <Texture2D>(spriteNames[0]));
            if (spriteNames.Count > 0)
            {
                for (int i = 1; i < spriteNames.Count; i++)
                {
                    AddSpriteToCollection(ExpandAssets.LoadSpriteAsset <Texture2D>(spriteNames[i]), newCollection);
                }
            }
            DumpSpriteCollection(newCollection, pathOverride);
            if (!string.IsNullOrEmpty(pathOverride))
            {
                SaveStringToFile(JsonUtility.ToJson(newCollection), pathOverride, CollectionName + "Collection" + ".txt");
            }
            else
            {
                SaveStringToFile(JsonUtility.ToJson(newCollection), ETGMod.ResourcesDirectory, CollectionName + "Collection" + ".txt");
            }
            newCollection = null;
            AtlasPacker   = null;
        }
예제 #2
0
파일: Dump.cs 프로젝트: thswogur00/ETGMod
            public static void DumpPacker(RuntimeAtlasPacker packer, string name)
            {
                string dir = Path.Combine(ResourcesDirectory, ("DUMPpacker_" + name).Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar));

                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }
                Directory.CreateDirectory(dir);

                for (int i = 0; i < packer.Pages.Count; i++)
                {
                    RuntimeAtlasPage page     = packer.Pages[i];
                    string           diskPath = Path.Combine(dir, i + ".png");
                    File.WriteAllBytes(diskPath, page.Texture.EncodeToPNG());
                }
            }