コード例 #1
0
        /// <summary>
        /// calls the Aseprite application which then should output a png with all sprites and a corresponding JSON
        /// </summary>
        /// <returns></returns>
        private static bool CreateSpriteAtlasAndMetaFile(AnimationImportJob job)
        {
            char   delimiter  = '\"';
            string parameters = "--data " + delimiter + job.name + ".json" + delimiter + " --sheet " + delimiter + job.name + ".png" + delimiter + " --sheet-pack --list-tags --format json-array " + delimiter + job.fileName + delimiter;

            if (!string.IsNullOrEmpty(job.additionalCommandLineArguments))
            {
                parameters = job.additionalCommandLineArguments + " " + parameters;
            }

            bool success = CallAsepriteCLI(AnimationImporter.Instance.asepritePath, job.assetDirectory, parameters) == 0;

            // move png and json file to subfolder
            if (success && job.directoryPathForSprites != job.assetDirectory)
            {
                // create subdirectory
                if (!Directory.Exists(job.directoryPathForSprites))
                {
                    Directory.CreateDirectory(job.directoryPathForSprites);
                }

                string target = job.directoryPathForSprites + "/" + job.name + ".json";
                if (File.Exists(target))
                {
                    File.Delete(target);
                }
                File.Move(job.assetDirectory + "/" + job.name + ".json", target);

                target = job.directoryPathForSprites + "/" + job.name + ".png";
                if (File.Exists(target))
                {
                    File.Delete(target);
                }
                File.Move(job.assetDirectory + "/" + job.name + ".png", target);
            }

            return(success);
        }
コード例 #2
0
        // ================================================================================
        //  Private methods
        // --------------------------------------------------------------------------------

        // parses a JSON file and creates the raw data for ImportedAnimationSheet from it
        private static ImportedAnimationSheet CreateAnimationSheetFromMetaData(AnimationImportJob job, AnimationImporterSharedConfig config)
        {
            string    textAssetFilename = job.DirectoryPathForSprites + "/" + job.Name + ".json";
            TextAsset textAsset         = AssetDatabase.LoadAssetAtPath <TextAsset>(textAssetFilename);

            if (textAsset != null)
            {
                JsonObject             jsonObject     = JsonObject.Parse(textAsset.ToString());
                ImportedAnimationSheet animationSheet = GetAnimationInfo(jsonObject);

                if (animationSheet == null)
                {
                    return(null);
                }

                if (!animationSheet.HasAnimations)
                {
                    Debug.LogWarning("No Animations found in Aseprite file. Use Aseprite Tags to assign names to Animations.");
                }

                animationSheet.PreviousImportSettings = job.PreviousImportSettings;

                animationSheet.SetNonLoopingAnimations(config.AnimationNamesThatDoNotLoop);

                // Delete JSON file afterwards
                AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(textAsset));

                return(animationSheet);
            }
            else
            {
                Debug.LogWarning("Problem with JSON file: " + textAssetFilename);
            }

            return(null);
        }
コード例 #3
0
        /// <summary>
        /// calls the Aseprite application which then should output a png with all sprites and a corresponding JSON
        /// </summary>
        /// <returns></returns>
        private static bool CreateSpriteAtlasAndMetaFile(AnimationImportJob job, out Texture2D img, out JSONObject metadata)
        {
            job.SetProgress(0, "Invoking Aseprite CLI...");
            img      = null;
            metadata = null;
            char   delimiter  = '\"';
            string parameters = "--data " + delimiter + job.name + ".json" + delimiter + " --sheet " + delimiter + job.name + ".png" + delimiter + " --sheet-pack --list-tags --format json-array " + delimiter + job.fileName + delimiter;

            if (!string.IsNullOrEmpty(job.additionalCommandLineArguments))
            {
                parameters = job.additionalCommandLineArguments + " " + parameters;
            }

            bool success = CallAsepriteCLI(AnimationImporter.Instance.asepritePath, job.assetDirectory, parameters) == 0;

            job.SetProgress(0.1f, "Loading Back CLI results...");

            // don't do stupid shit here, just load stuff from disk then delete them!
            // // move png and json file to subfolder
            if (success && job.directoryPathForSprites != job.assetDirectory)
            {
                // create subdirectory
                if (!Directory.Exists(job.directoryPathForSprites))
                {
                    Directory.CreateDirectory(job.directoryPathForSprites);
                }

                string jsonSource = job.assetDirectory + "/" + job.name + ".json";
                if (File.Exists(jsonSource))
                {
                    using (var jsonFile = File.OpenText(jsonSource)) {
                        metadata = JSONObject.Parse(jsonFile.ReadToEnd());
                    }
                    File.Delete(jsonSource);
                }
                else
                {
                    Debug.LogWarning("Calling Aseprite resulted in no json data file. Wrong Aseprite version?");
                    return(false);
                }

                // check and copy png file
                string pngSource = job.assetDirectory + "/" + job.name + ".png";
                if (File.Exists(pngSource))
                {
                    using (var pngFile = File.OpenRead(pngSource)) {
                        var buffer = new byte[pngFile.Length];
                        pngFile.Read(buffer, 0, (int)pngFile.Length);
                        img = new Texture2D(1, 1, TextureFormat.RGBA32, false);
                        ImageConversion.LoadImage(img, buffer, false);
                        img.name = job.name;
                    }
                    File.Delete(pngSource);
                }
                else
                {
                    Debug.LogWarning("Calling Aseprite resulted in no png Image file. Wrong Aseprite version?");
                    return(false);
                }
            }

            return(success);
        }
コード例 #4
0
        /// <summary>
        /// calls the Aseprite application which then should output a png with all sprites and a corresponding JSON
        /// </summary>
        /// <returns></returns>
        private static bool CreateSpriteAtlasAndMetaFile(AnimationImportJob job, bool trim)
        {
            const char delimiter  = '\"';
            string     parameters = "--data " + delimiter + job.name + ".json" + delimiter + " --sheet " + delimiter + job.name + ".png" + delimiter + " --sheet-pack --list-tags --format json-array " + delimiter + job.fileName + delimiter;

            if (trim)
            {
                parameters += " --trim";
            }

            if (!string.IsNullOrEmpty(job.additionalCommandLineArguments))
            {
                parameters = job.additionalCommandLineArguments + " " + parameters;
            }

            bool success = CallAsepriteCLI(AnimationImporter.Instance.asepritePath, job.assetDirectory, parameters) == 0;

            // move png and json file to subfolder
            if (success && job.directoryPathForSprites != job.assetDirectory)
            {
                // create subdirectory
                if (!Directory.Exists(job.directoryPathForSprites))
                {
                    Directory.CreateDirectory(job.directoryPathForSprites);
                }

                // check and copy json file
                string jsonSource = job.assetDirectory + "/" + job.name + ".json";
                string jsonTarget = job.directoryPathForSprites + "/" + job.name + ".json";
                if (File.Exists(jsonSource))
                {
                    if (File.Exists(jsonTarget))
                    {
                        File.Delete(jsonTarget);
                    }
                    File.Move(jsonSource, jsonTarget);
                }
                else
                {
                    Debug.LogWarning("Calling Aseprite resulted in no json data file. Wrong Aseprite version?");
                    return(false);
                }

                // check and copy png file
                string pngSource = job.assetDirectory + "/" + job.name + ".png";
                string pngTarget = job.directoryPathForSprites + "/" + job.name + ".png";
                if (File.Exists(pngSource))
                {
                    if (File.Exists(pngTarget))
                    {
                        File.Delete(pngTarget);
                    }
                    File.Move(pngSource, pngTarget);
                }
                else
                {
                    Debug.LogWarning("Calling Aseprite resulted in no png Image file. Wrong Aseprite version?");
                    return(false);
                }
            }

            return(success);
        }