using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Giant.Resource {

    public abstract class IResourceLoader
    {
        public static string streamingAssetsPath = Application.streamingAssetsPath;

#if UNITY_EDITOR
        //public static string persistentDataPath = Path.Combine(Application.dataPath, "../PersistentData/");
        public static string persistentDataPath = Application.streamingAssetsPath;
#else
    public static string persistentDataPath = Application.persistentDataPath;
#endif

        /// <summary>
        /// 设置为true,将不使用persistent目录下资源，使用StreamAssets目录下资源
        /// AssetBundle资源时使用,
        /// </summary>
        public static bool donotUsePersistentFolderResource = false;

        public static string abmf = "abasset";
        public static string abpath = "abasset/";

        public static string strAsset = "AssetBundles/"; //ExporterCfg.GetMe().AssetFolderName + "/";//"asset/";

        protected static string AssetPath = "Assets/" + strAsset;//"Assets/asset/";
        public static string strAssetFolder = "Assets/" + strAsset; //"assets/asset/";

        // public static string strUIAssetFolder = "assets/asset/ui";

        //资源类型
        public const string strAssetSuffix = ".asset";
        //public const string strYAMLSuffix = ".yaml";
        public const string strAnimSuffix = ".controller";
        public static string strBytesSuffix = ".bytes";
        public const string strPrefabSuffix = ".prefab";
        public static string strShaderSuffix = ".shader";
        public static string strSpriteSuffix = ".png";
        public static string strVideoSuffix = ".mp4";
        public static string strCsvSuffix = ".csv";
        public const string strMatSuffix = ".mat";
        public static string strTgaSuffix = ".tga";
        public static string strFbxSuffix = ".fbx";
        public static string strFontSuffix = ".otf";

        static private IResourceLoader m_instance = null;
        static public IResourceLoader Instance
        {
            get
            {
                if (m_instance == null)
                {
#if UNITY_EDITOR
                    if (!AssetBundleManager.UseAssetBundle)
                    {
                        m_instance = new EditorResourceLoader();  
                    }
                    else
#endif
                    {
                        m_instance = new ABResourceLoader();
                    }
                    
                    //CreateInstance("X2Engine.ResourceLoader");
                }
                return m_instance;
            }
        }

        public abstract UnityEngine.Object LoadAssetSync(string strAssetPath, string strAssetName, string strSuffix, bool bShader = false, System.Type t = null);
        public abstract void LoadAssetAsync(string strAssetPath, string strAssetName, string strSuffix, LoadCallback callback = null, bool bShader = false, System.Type t = null);
        public abstract ResourceLoadAsync LoadAssetAsync(string strAssetPath, string strAssetName, string strSuffix, bool bShader = false, System.Type t = null);

        //加载场景
        public abstract ResourceLoadAsync LoadSceneAsync(string scenepath, LoadSceneMode mode);
        //卸载场景
        public abstract void UnLoadScene(string scenepath);

        //加载外部打包场景
        public abstract SceneLoadAsync LoadOutSceneAsync(string sceneName, LoadSceneMode mode);

        //卸载外部打包场景
        public abstract void UnOutLoadScene(string sceneName);
    }

}