using System.Runtime.CompilerServices;
using UnityEngine.SceneManagement;

namespace Giant.Resource {

   /// <summary>
   /// 资源加载统一调用此类
   /// </summary>
    public static class ResourceHelper
    {
        /// <summary>
        /// 同步加载资源
        /// </summary>
        /// <param name="strAssetPath"></param>
        /// <param name="strAssetName"></param>
        /// <param name="strSuffix"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
        public static UnityEngine.Object LoadResourceSync(string strAssetPath, string strAssetName, string strSuffix, System.Type t = null)
        {
            return IResourceLoader.Instance.LoadAssetSync(strAssetPath, strAssetName, strSuffix, false, t);
        }

        /// <summary>
        /// 异步加载资源 回调方式
        /// </summary>
        /// <param name="strAssetPath"></param>
        /// <param name="strAssetName"></param>
        /// <param name="strSuffix"></param>
        /// <param name="callback"></param>
        /// <param name="t"></param>
        [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
        public static void LoadResourceAsync(string strAssetPath, string strAssetName, string strSuffix, LoadCallback callback = null, System.Type t = null)
        {
            IResourceLoader.Instance.LoadAssetAsync(strAssetPath, strAssetName, strSuffix, callback, false, t);
        }

        /// <summary>
        /// 异步加载资源 返回值方式
        /// </summary>
        /// <param name="strAssetPath"></param>
        /// <param name="strAssetName"></param>
        /// <param name="strSuffix"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
        public static ResourceLoadAsync AsyncLoadResource(string strAssetPath, string strAssetName, string strSuffix, System.Type t = null) {
            return IResourceLoader.Instance.LoadAssetAsync(strAssetPath, strAssetName, strSuffix, false, t);
        }

        /// <summary>
        /// 同步加载shader
        /// </summary>
        /// <param name="strAssetPath"></param>
        /// <param name="strAssetName"></param>
        /// <returns></returns>
        [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
        public static UnityEngine.Object LoadShaderSync(string strAssetPath, string strAssetName)
        {
            return IResourceLoader.Instance.LoadAssetSync(strAssetPath, strAssetName, IResourceLoader.strShaderSuffix, true);
        }

        /// <summary>
        /// 异步加载shader
        /// </summary>
        /// <param name="strAssetPath"></param>
        /// <param name="strAssetName"></param>
        /// <param name="callback"></param>
        [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
        public static void LoadShaderAsync(string strAssetPath, string strAssetName, LoadCallback callback = null)
        {
            IResourceLoader.Instance.LoadAssetAsync(strAssetPath, strAssetName, IResourceLoader.strShaderSuffix, callback, true);
        }

        /// <summary>
        /// 同步加载prefab
        /// </summary>
        /// <param name="strAssetPath"></param>
        /// <param name="strAssetName"></param>
        /// <returns></returns>
        [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
        public static UnityEngine.Object LoadPrefabSync(string strAssetPath, string strAssetName)
        {
            return IResourceLoader.Instance.LoadAssetSync(strAssetPath, strAssetName, IResourceLoader.strPrefabSuffix);
        }

        //异步加载prefab
        [MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
        public static void LoadPrefabAsync(string strAssetPath, string strAssetName, LoadCallback callback)
        {
            IResourceLoader.Instance.LoadAssetAsync(strAssetPath, strAssetName, IResourceLoader.strPrefabSuffix, callback);
        }

        //卸载场景
        public static void UnLoadScene(string scenepath)
        {
            IResourceLoader.Instance.UnLoadScene(scenepath);
        }

        public static void UnOutLoadScene(string sceneName)
        {
            IResourceLoader.Instance.UnOutLoadScene(sceneName);
        }

        /// <summary>
        /// 加载场景
        /// </summary>
        /// <param name="scenepath"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public static ResourceLoadAsync LoadSceneAsync(string scenepath, LoadSceneMode mode)
        {
            return IResourceLoader.Instance.LoadSceneAsync(scenepath, mode);
        }


        public static SceneLoadAsync LoadOutSceneAsync(string sceneName, LoadSceneMode mode)
        {
            return IResourceLoader.Instance.LoadOutSceneAsync(sceneName, mode);
        }

        public static void UnLoadOutSceneAB(string sceneName)
        {
            string scenepath = "outscenes/" + sceneName;
            Giant.Common.VString strPath = Giant.Common.VString.From(scenepath, Giant.Common.AllocType.Tmp);
            Giant.Resource.AssetBundleManager.Instance.UnLoadAssetBundle(strPath);
        }
    }

}