up
This commit is contained in:
53
Assets/trCRM/upgradeRes4Dev/priority/lua/db/DBTextures.lua
Normal file
53
Assets/trCRM/upgradeRes4Dev/priority/lua/db/DBTextures.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
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
|
||||
Reference in New Issue
Block a user