using XGame.Editor.Asset;
using UnityEditor;
using UnityEngine;

namespace XGame.Editor.Build.AssetBundles
{
    /// <summary>
    /// 备份用Manifest文件
    /// </summary>
    public class AssetBundleBackupManifest : ScriptableObject
    {
        #region static
        public static string ManifestPath  => $"{PathDefine.ConfigsRelative}AssetBundleBackupManifest.asset";
        public static AssetBundleBackupManifest Load()
        {
            return AssetDatabase.LoadAssetAtPath<AssetBundleBackupManifest>(ManifestPath);
        }
        public static void Save(AssetBundleBackupInfo[] backupInfos, bool refresh)
        {
            var manifest = Load();
            if (manifest == null)
            {
                manifest = ScriptableObject.CreateInstance<AssetBundleBackupManifest>();
                AssetDatabase.CreateAsset(manifest, ManifestPath);
            }
            manifest.bundleInfos = backupInfos;
            EditorUtility.SetDirty(manifest);
            if (refresh)
            {
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        }
        #endregion


        public AssetBundleBackupInfo[] bundleInfos;
    }
}
