Пример #1
0
        /// <summary>
        /// Save to disk the DynamicAtlas.
        /// </summary>
        /// <param name="atlas">DynamicAtlas.</param>
        /// <param name="info">Custom FileInfo.</param>
        /// <returns>Return FileInfo (Path and Name of saved atlas).</returns>
        public static FileInfo Save(DynamicAtlas atlas, FileInfo info = null)
        {
            if (info == null)
            {
                info = new FileInfo(atlas.Texture.name);
            }

            if (Directory.Exists(info.Path) == false)
            {
                Directory.CreateDirectory(info.Path);
            }

            if (atlas.IsApplied == false)
            {
                atlas.Apply();
            }

            byte[] bytes = atlas.Texture.EncodeToPNG();
            string json  = JsonUtility.ToJson(atlas);

            File.WriteAllBytes(info.PathTexture, bytes);
            File.WriteAllText(info.PathData, json);

            return(info);
        }
Пример #2
0
        /// <summary>
        /// Load from disk the DynamicAtlas.
        /// </summary>
        /// <param name="info">FileInfo.</param>
        /// <returns>Return DynamicAtlas.</returns>
        public static DynamicAtlas Load(FileInfo info)
        {
            if (File.Exists(info.PathTexture) == false || File.Exists(info.PathData) == false)
            {
                return(null);
            }

            byte[] bytes = File.ReadAllBytes(info.PathTexture);
            string json  = File.ReadAllText(info.PathData);

            DynamicAtlas atlas = JsonUtility.FromJson <DynamicAtlas>(json);

            atlas.Texture = new Texture2D(0, 0, TextureFormat.RGBA32, false);
            atlas.Texture.LoadImage(bytes);
            atlas.Texture.name = info.Name;

            return(atlas);
        }