using Fort23.UTool;

#if !COMBAT_SERVER


namespace Core.AssetLoadTool.Asset
{
    public class BundleAssetLoadTask : AssetLoadTaskBasic
    {
        protected BundleLoadBasic _bundleLoadTask;

     
        protected override void StartLoadAsset<T>()
        {
            BundleLoadBasic bundleLoadBasic= AssetBundleLoadManager.Instance.AddBundleTask(_assetInfo.bundle,
                delegate(BundleLoadBasic bundleLoad, object data)
                {
                    if (bundleLoad == null)
                    {
                        CallErrorBack();
                        return;
                    }
                    if (!_assetInfo.bundle.Equals(bundleLoad.bundleName))
                    {
                        LogTool.Error(bundleLoad.bundleName + "budnle名和加载名不同" + _assetInfo.bundle);
                    }

                    this._bundleLoadTask = bundleLoad;
                    try
                    {
                        T objAsset = bundleLoad.LoadAsset<T>(_assetInfo.name);
                        if (objAsset == null)
                        {
                            LogTool.Error(_assetInfo.name + "资源加载失败" + _assetInfo.bundle);
                            CallErrorBack();
                            return;
                        }
                        LoadFinish<T>(objAsset);
                    }
                    catch (System.Exception e)
                    {
                        LogTool.Error(_assetInfo.name + "资源加载失败" + _assetInfo.bundle + "  " + e.Message);
                    }
                },this);
          
        }

        protected override void ProDispose()
        {
            if (_bundleLoadTask != null)
            {
                _bundleLoadTask.RemoveAsset(_assetInfo.name);
                _bundleLoadTask.RemoveOwnTask(this);
                _bundleLoadTask = null;
            }
        }
    }
}
#endif