54 lines
1.2 KiB
Lua
54 lines
1.2 KiB
Lua
|
|
DBTextures = {}
|
||
|
|
local db = {}
|
||
|
|
|
||
|
|
function DBTextures.init()
|
||
|
|
InvokeEx.cancelInvoke(DBTextures.releaseTimeout)
|
||
|
|
InvokeEx.invoke(DBTextures.releaseTimeout, 60)
|
||
|
|
end
|
||
|
|
|
||
|
|
function DBTextures.clean()
|
||
|
|
InvokeEx.cancelInvoke(DBTextures.releaseTimeout)
|
||
|
|
for k, v in ipairs(db) do
|
||
|
|
GameObject.DestroyImmediate(v)
|
||
|
|
end
|
||
|
|
db = {}
|
||
|
|
end
|
||
|
|
|
||
|
|
function DBTextures.releaseTimeout()
|
||
|
|
for k, v in ipairs(db) do
|
||
|
|
if DateEx.nowMS - v.lastUseTime > 300000 then
|
||
|
|
GameObject.DestroyImmediate(v.texture)
|
||
|
|
db[k] = nil
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
---@return UnityEngine.UnityWebRequest
|
||
|
|
function DBTextures.getByUrl(url, callback, orgs)
|
||
|
|
local tt = db[url]
|
||
|
|
if tt then
|
||
|
|
tt.lastUseTime = DateEx.nowMS
|
||
|
|
db[url] = tt
|
||
|
|
Utl.doCallback(callback, tt.texture, orgs)
|
||
|
|
return nil
|
||
|
|
end
|
||
|
|
|
||
|
|
local request =
|
||
|
|
WWWEx.get(
|
||
|
|
url,
|
||
|
|
nil,
|
||
|
|
CLAssetType.texture,
|
||
|
|
function(content)
|
||
|
|
db[url] = {texture = content, lastUseTime = DateEx.nowMS}
|
||
|
|
Utl.doCallback(callback, content, orgs)
|
||
|
|
end,
|
||
|
|
nil,
|
||
|
|
orgs,
|
||
|
|
true,
|
||
|
|
1
|
||
|
|
)
|
||
|
|
return request
|
||
|
|
end
|
||
|
|
|
||
|
|
return DBTextures
|