Beispiel #1
0
        // parses a JSON file and creates the raw data for ImportedAnimationSheet from it
        private ImportedAnimationSheet CreateAnimationSheetFromJSON(string basePath, string name, PreviousImportSettings previousImportSettings)
        {
            string    textAssetFilename = GetJSONAssetFilename(basePath, name);
            TextAsset textAsset         = AssetDatabase.LoadAssetAtPath <TextAsset>(textAssetFilename);

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

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

                animationSheet.previousImportSettings = previousImportSettings;

                animationSheet.name     = name;
                animationSheet.basePath = basePath;

                animationSheet.SetNonLoopingAnimations(sharedData.animationNamesThatDoNotLoop);

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

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

            return(null);
        }
Beispiel #2
0
        private ImportedAnimationInfo ImportJSONAndCreateAnimations(string basePath, string name)
        {
            string imagePath = basePath;

            if (_saveSpritesToSubfolder)
            {
                imagePath += "/Sprites";
            }

            string    imageAssetFilename = imagePath + "/" + name + ".png";
            string    textAssetFilename  = imagePath + "/" + name + ".json";
            TextAsset textAsset          = AssetDatabase.LoadAssetAtPath <TextAsset>(textAssetFilename);

            if (textAsset != null)
            {
                // parse the JSON file
                JSONObject            jsonObject    = JSONObject.Parse(textAsset.ToString());
                ImportedAnimationInfo animationInfo = AsepriteImporter.GetAnimationInfo(jsonObject);

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

                animationInfo.basePath             = basePath;
                animationInfo.name                 = name;
                animationInfo.nonLoopingAnimations = _animationNamesThatDoNotLoop;

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

                CreateSprites(animationInfo, imageAssetFilename);

                CreateAnimations(animationInfo, imageAssetFilename);

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

            return(null);
        }