using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CreateAssetMenu(fileName ="ExporterCfg", menuName ="create exportercfg")]
public class ExporterCfg : ScriptableObject
{
    //源目录
    public string AssetFolderName = "asset";
    public string AssetFolderPathLower
    {
        get
        {
            return ("assets/" + AssetFolderName + "/").ToLower();
        }
    }

    public bool ExportToStreamingAsset = true;
    //输出目录
    private string _rpath = "";
    public string ResultPath
    {
        set
        {
            _rpath = value;
        }
        get
        {
            if (ExportToStreamingAsset)
            {
                return Application.streamingAssetsPath + "/AssetBundles/";
            }
            else
            {
                if (string.IsNullOrEmpty(_rpath))
                {
                    _rpath = Giant.Common.PathUtility.StandardPath(System.IO.Path.Combine(Application.dataPath, "../AssetBundles/"));
                    _rpath = Giant.Common.PathUtility.SimplifiedPath(_rpath);
                }
                return _rpath;
            }
            
        }
    }

    public List<string> ignorestuffixes = new List<string>();
    public List<string> ignorefiles = new List<string>();
    public List<string> scenes = new List<string>();

    public static string FileName = "ExporterCfg";
    public static ExporterCfg instance = null;
    public static ExporterCfg GetMe() {
        if (null == instance)
        {
            instance = Resources.Load<ExporterCfg>(FileName);
            if (instance == null) {
                instance = ScriptableObject.CreateInstance<ExporterCfg>();
            }
        }

        return instance;
    }

    public AssetBundleInputType assetbundleInputType;

    public bool incrementalAB = false;
         
    /// <summary>
    /// 如果资源被多个AB包依赖，且本身不归属于任意AB包，就给它统一分配一个包名，避免多份内存占用
    /// </summary>
    public bool autoAssignBundleName = true;
    public bool clearfolder = false;

    /// <summary>
    /// 打包结束是否删除Mainifest
    /// </summary>
    public bool deleteManifestAfter = false;



    public BuildTarget lastBuildTarget = BuildTarget.StandaloneWindows64;
    [System.NonSerialized]
    public BuildAssetBundleOptions lastBuildOptions = BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle
                    | BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension | BuildAssetBundleOptions.DisableLoadAssetByFileName;


    public void Save()
    {
        EditorUtility.ClearProgressBar();
        EditorUtility.SetDirty(this);
        AssetDatabase.SaveAssets();
    }
}

public enum AssetBundleInputType
{
    Random,
    AssetBundleBrowser,
    Custom
}
