public static SpriteAtlas CreateOrUpdateAtlas(
            AtlasGeneratorSettings generatorSettings,
            AtlasGeneratorAtlasSettings atlasSettings,
            AtlasGeneratorRule rule,
            string assetPath)
        {
            // Set atlas
            SpriteAtlas atlas;
            var         pathToAtlas = rule.ParseAtlasReplacement(assetPath);

            pathToAtlas = rule.GetFullPathToAtlas(pathToAtlas);

            var newAtlas = false;

            if (string.IsNullOrWhiteSpace(pathToAtlas))
            {
                Log(LogType.Warning, $"Asset {assetPath} wasn't packed because its rule has no atlas path");
                return(null);
            }

            var appliedSettings = rule.applyCustomSettings ? rule.atlasSettings : atlasSettings.defaultAtlasSettings;

            if (!TryGetAtlas(pathToAtlas, out atlas))
            {
                atlas    = CreateAtlas(pathToAtlas, appliedSettings);
                newAtlas = true;
            }

            // Set atlas settings from template if necessary
            if (!newAtlas && ((rule.applyCustomSettings && rule.atlasSettingsApplicationMode == AtlasSettingsApplicationMode.AlwaysOverwriteAtlasSettings) ||
                              atlasSettings.atlasSettingseApplicationMode == AtlasSettingsApplicationMode.AlwaysOverwriteAtlasSettings))
            {
                atlas.ApplySettings(appliedSettings);
            }

            var packedAsset  = new[] { AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath) };
            var packedAssets = atlas.GetPackables();

            if (!packedAssets.Contains(packedAsset[0]))
            {
                atlas.Add(packedAsset);
            }

            return(atlas);
        }
        public static bool LoadSettings(out AtlasGeneratorSettings generatorSettings, out AtlasGeneratorAtlasSettings atlasSettings)
        {
            generatorSettings = AtlasGeneratorSettings.Asset;
            atlasSettings     = AtlasGeneratorAtlasSettings.Asset;

            if (generatorSettings == null)
            {
                Log(LogType.Error, "Generator settings file not found");
                return(false);
            }

            if (atlasSettings == null)
            {
                Log(LogType.Error, "Atlas settings file not found.");
                return(false);
            }

            return(true);
        }