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

namespace TFramework
{
    public class LoadResHandle<T> : IReference
    {
        /// <summary>
        /// 资源加载模式
        /// </summary>
        public ResLoadMode LoadMode;

        /// <summary>
        /// Resource资源路径
        /// </summary>
        public string ResourcePath;

        /// <summary>
        /// AssetBundle包名
        /// </summary>
        public string AssetBundleName;

        /// <summary>
        /// 资源相对路径（用于AB包及Editor模式）
        /// </summary>
        public string AssetPath;

        /// <summary>
        /// 加载中事件
        /// </summary>
        public TAction<float> OnLoading;

        /// <summary>
        /// 加载完成事件
        /// </summary>
        public TAction<T> OnLoadOver;

        public LoadResHandle()
        {

        }

        public LoadResHandle(ResLoadMode resLoadMode, string resourePath, string assetbundleName, string assetPath, TAction<float> onLoading = null, TAction<T> onLoadOver = null)
        {
            LoadMode = resLoadMode;
            ResourcePath = resourePath;
            AssetBundleName = assetbundleName;
            AssetPath = assetPath;
            OnLoading = onLoading;
            OnLoadOver = onLoadOver;
        }

        /// <summary>
        /// Resource模式加载
        /// </summary>
        /// <param name="resourePath"></param>
        /// <param name="onLoading"></param>
        /// <param name="onLoadOver"></param>
        public LoadResHandle(string resourePath, TAction<float> onLoading = null, TAction<T> onLoadOver = null)
        {
            LoadMode = ResLoadMode.Resourece;
            ResourcePath = resourePath;
            AssetPath = resourePath;
            OnLoading = onLoading;
            OnLoadOver = onLoadOver;
        }

        /// <summary>
        /// AB包模式加载
        /// </summary>
        /// <param name="assetbundleName"></param>
        /// <param name="assetPath"></param>
        /// <param name="onLoading"></param>
        /// <param name="onLoadOver"></param>
        public LoadResHandle(string assetbundleName, string assetPath, TAction<float> onLoading = null, TAction<T> onLoadOver = null)
        {
            LoadMode = ResLoadMode.AssetBundle;
            AssetBundleName = assetbundleName;
            AssetPath = assetPath;
            OnLoading = onLoading;
            OnLoadOver = onLoadOver;
        }

        public LoadResHandle(UIResourceAttribute attribute, TAction<float> onLoading = null, TAction<T> onLoadOver = null)
        {
            LoadMode = attribute.LoadMode;
            ResourcePath = attribute.ResourcePath;
            AssetBundleName = attribute.AssetBundleName;
            AssetPath = attribute.AssetPath;
            OnLoading = onLoading;
            OnLoadOver = onLoadOver;
        }

        public void Reset()
        {
            OnLoading = null;
            OnLoadOver = null;
            ResourcePath = string.Empty;
            AssetBundleName = string.Empty;
            AssetPath = string.Empty;
        }
    }
}
