local WhiteResManager = {}


---- 游戏资源白名单
local GAME_RES_WHITE_LIST = {
    -- ui
    GConst.ATLAS_PATH.COMMON,
    GConst.ATLAS_PATH.ACT_COMMON,
    -- icon
    GConst.ATLAS_PATH.ICON_SKILL,
    GConst.ATLAS_PATH.ICON_SKILL_BIG,
    GConst.ATLAS_PATH.ICON_SKILL_ROGUE,
    GConst.ATLAS_PATH.ICON_ITEM,
    GConst.ATLAS_PATH.ICON_HERO,
    GConst.ATLAS_PATH.ICON_HERO_2,
    GConst.ATLAS_PATH.ICON_BUFF,
    GConst.ATLAS_PATH.ICON_TASK,
    GConst.ATLAS_PATH.ICON_AVATAR,
    GConst.ATLAS_PATH.ICON_EQUIP,
}

---- 预加载游戏资源
function WhiteResManager:gamePreLoad(progressCallback, readyCallback)
    self.loaded = true
    local totalCount = #GAME_RES_WHITE_LIST
    local readyCount = 0
    local progress = 0

    self.progressCallback = progressCallback
    self.readyCallback = readyCallback

    local function preloadRes(resPath)
        ResourceManager:loadOriginAssetAsync(resPath, GConst.TYPEOF_UNITY_CLASS.OBJECT, function(assetsPath, asset)
            readyCount = readyCount + 1
            progress = readyCount / totalCount

            if self.progressCallback then
                self.progressCallback(progress)
            end

            if readyCount == totalCount then
                if self.readyCallback then
                    self.readyCallback()
                end
                self.progressCallback = nil
                self.readyCallback = nil
            end
        end)
    end

    for _, resPath in ipairs(GAME_RES_WHITE_LIST) do
        preloadRes(resPath)
    end
end

function WhiteResManager:clearCallback()
    self.progressCallback = nil
    self.readyCallback = nil
end

function WhiteResManager:isLoaded()
    return self.loaded
end

return WhiteResManager