【sploader】翻译资源加载优化
parent
49fcaadf00
commit
d9640a660c
|
|
@ -15,7 +15,7 @@ function BasePanel:CreateUI(gameObject)
|
|||
self.transform = gameObject.transform
|
||||
self.canvas = self.gameObject:GetComponent("Canvas")
|
||||
self.openNum = 0
|
||||
self.SpriteList = {}
|
||||
self.lspLoader = SpriteLoader.New()
|
||||
if self.Awake ~= nil then
|
||||
MyPCall(
|
||||
function()
|
||||
|
|
@ -118,8 +118,11 @@ end
|
|||
|
||||
--UI销毁时由UIManager调用(子类不要重写此方法)
|
||||
function BasePanel:DestroyUI()
|
||||
self:UnLoadSprite()
|
||||
self:OnDestroy()
|
||||
if self.lspLoader then
|
||||
self.lspLoader:Destroy()
|
||||
self.lspLoader = nil
|
||||
end
|
||||
Game.GlobalEvent:DispatchEvent(GameEvent.UI.OnDestroy, self.uiConfig.id, self)
|
||||
end
|
||||
|
||||
|
|
@ -174,24 +177,3 @@ end
|
|||
--界面销毁时调用(用于子类重写)
|
||||
function BasePanel:OnDestroy()
|
||||
end
|
||||
|
||||
function BasePanel:LoadSprite(name)
|
||||
local transName = GetTranslateSpriteName(name)
|
||||
local sp = resMgr:LoadSpriteAsset(name)
|
||||
if sp then
|
||||
if not self.SpriteList[sp.name] then
|
||||
self.SpriteList[sp.name] = 0
|
||||
end
|
||||
self.SpriteList[sp.name] = self.SpriteList[sp.name] + 1
|
||||
return sp
|
||||
end
|
||||
end
|
||||
|
||||
-- 根据界面加载的数量卸载相应数量的资源
|
||||
function BasePanel:UnLoadSprite()
|
||||
for name, count in pairs(self.SpriteList) do
|
||||
for i = 1, count do
|
||||
resMgr:UnLoadAsset(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ local function createPanel(uiConfig, parent)
|
|||
recTransform.anchoredPosition3D = Vector3.New(0, 0, 0)
|
||||
recTransform.sizeDelta = Vector2.New(0, 0)
|
||||
transform.localRotation = Quaternion.identity
|
||||
UIManager.DoLanguageCheck(gameObject)
|
||||
return gameObject
|
||||
end
|
||||
|
||||
|
|
@ -35,6 +34,8 @@ function this.Open(config,parent,...)
|
|||
playUIAnimsOnStart(gameObject)
|
||||
end
|
||||
local sub = view:New(gameObject)
|
||||
sub.lspLoader = SpriteLoader.New()
|
||||
UIManager.DoLanguageCheck(sub.lspLoader, gameObject)
|
||||
sub.assetName = config.assetName
|
||||
if sub.Awake then
|
||||
sub:Awake()
|
||||
|
|
@ -67,6 +68,10 @@ function this.Close(sub)
|
|||
if sub.OnClose then
|
||||
sub:OnClose()
|
||||
end
|
||||
if sub.lspLoader then
|
||||
sub.lspLoader:Destroy()
|
||||
sub.lspLoader = nil
|
||||
end
|
||||
resMgr:UnLoadAsset(sub.assetName)
|
||||
LogError("sub UI close: "..sub.assetName)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -378,9 +378,13 @@ function UIManager.GetPanel(id, isSync, func, ...)
|
|||
if isSync then
|
||||
local gameObject = this.CreatePanel(uiConfig, rootNode)
|
||||
panel:CreateUI(gameObject)
|
||||
-- 多语言处理
|
||||
this.DoLanguageCheck(panel.lspLoader, gameObject)
|
||||
else
|
||||
this.CreatePanelAsync(uiConfig, rootNode, function (gameObject)
|
||||
panel:CreateUI(gameObject)
|
||||
-- 多语言处理
|
||||
this.DoLanguageCheck(panel.lspLoader, gameObject)
|
||||
SetSortingOrder(uiConfig, panel, isStackPanel,unpack(args, 1, table.maxn(args)))
|
||||
if func then
|
||||
func(panel)
|
||||
|
|
@ -612,8 +616,6 @@ function UIManager.CreatePanel(uiConfig, parent)
|
|||
recTransform.anchoredPosition3D = Vector3.New(0, 0, 0)
|
||||
recTransform.sizeDelta = Vector2.New(0, 0)
|
||||
transform.localRotation = Quaternion.identity
|
||||
-- 多语言处理
|
||||
this.DoLanguageCheck(gameObject)
|
||||
return gameObject
|
||||
end
|
||||
|
||||
|
|
@ -636,9 +638,6 @@ function UIManager.CreatePanelAsync(uiConfig, parent, func)
|
|||
recTransform.anchoredPosition3D = Vector3.New(0, 0, 0)
|
||||
recTransform.sizeDelta = Vector2.New(0, 0)
|
||||
transform.localRotation = Quaternion.identity
|
||||
-- 多语言处理
|
||||
this.DoLanguageCheck(gameObject)
|
||||
|
||||
if func then
|
||||
func(gameObject)
|
||||
end
|
||||
|
|
@ -651,7 +650,10 @@ local ExceptPrefabList = {
|
|||
"GMPanel"
|
||||
}
|
||||
-- 根据语言对界面显示进行修改
|
||||
function UIManager.DoLanguageCheck(gameObject)
|
||||
function UIManager.DoLanguageCheck(spLoader, gameObject)
|
||||
if not spLoader then
|
||||
return
|
||||
end
|
||||
-- 判断是否需要翻译
|
||||
if table.indexof(ExceptPrefabList, gameObject.name) then
|
||||
return
|
||||
|
|
@ -670,7 +672,7 @@ function UIManager.DoLanguageCheck(gameObject)
|
|||
if imageArr[i].sprite then
|
||||
local imgStr=imageArr[i].sprite.name
|
||||
if string.sub(imgStr,-3)=="_zh" then
|
||||
imageArr[i].sprite=Util.LoadSprite(imgStr)
|
||||
imageArr[i].sprite = spLoader:LoadSprite(imgStr)
|
||||
Log("资源名称:"..imgStr)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -894,8 +894,10 @@ function this.SetGuidePause(isPause)
|
|||
this.isGuidePause = isPause
|
||||
end
|
||||
|
||||
|
||||
|
||||
this.spLoader = nil
|
||||
function this.SetSpLoader(spLoader)
|
||||
this.spLoader = spLoader
|
||||
end
|
||||
function this.LoadAsset(path, battleSorting)
|
||||
--- 播放音效
|
||||
local audioData = FEAConfig.GetAudioData(path)
|
||||
|
|
@ -904,7 +906,7 @@ function this.LoadAsset(path, battleSorting)
|
|||
end
|
||||
--
|
||||
local go = poolManager:LoadAsset(path, PoolManager.AssetType.GameObject)
|
||||
UIManager.DoLanguageCheck(go)
|
||||
UIManager.DoLanguageCheck(this.spLoader, go)
|
||||
local layer = tonumber(go.name) or 0
|
||||
battleSorting = battleSorting or BattleManager.GetBattleSorting()
|
||||
Util.AddParticleSortLayer(go, battleSorting - layer)
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ end
|
|||
|
||||
function this:InitComponent(root, go)
|
||||
this.spLoader = SpriteLoader.New()
|
||||
BattleManager.SetSpLoader(this.spLoader)
|
||||
-- body
|
||||
this.root = root
|
||||
this.gameObject = go.gameObject
|
||||
|
|
@ -923,6 +924,8 @@ end
|
|||
--界面销毁时调用(用于子类重写)
|
||||
function this:OnDestroy()
|
||||
this.spLoader:Destroy()
|
||||
BattleManager.SetSpLoader(nil)
|
||||
|
||||
SubUIManager.Close(this.ElementalResonanceView)
|
||||
SubUIManager.Close(this.ElementalResonanceView2)
|
||||
BattlePool.Destroy()
|
||||
|
|
|
|||
|
|
@ -397,7 +397,7 @@ function FightPointPassMainPanel:OnShow()
|
|||
isCounting = false
|
||||
-- 加载地图数据
|
||||
coroutine.start(function()
|
||||
coroutine.wait(0.01)
|
||||
-- coroutine.wait(0.01)
|
||||
if UIManager.IsOpen(UIName.FightPointPassMainPanel) then
|
||||
fightMap:Init()
|
||||
hasMap = true
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ function RoleListPanel:InitComponent()
|
|||
|
||||
this.BtnBack = Util.GetGameObject(self.transform, "rightUp/btnBack")
|
||||
this.cardPre = poolManager:LoadAsset("card", PoolManager.AssetType.GameObject)
|
||||
UIManager.DoLanguageCheck(this.cardPre)
|
||||
UIManager.DoLanguageCheck(this.spLoader, this.cardPre)
|
||||
this.cardPre.transform:SetParent(self.transform)
|
||||
this.cardPre:GetComponent("RectTransform").localScale = Vector3.New(1,1,1)
|
||||
this.btnPrant = Util.GetGameObject(self.gameObject, "Tabs")
|
||||
|
|
|
|||
|
|
@ -183,12 +183,13 @@ namespace ResMgr
|
|||
ResData resData = null;
|
||||
if (resFailedMap.TryGetValue(name, out resData))
|
||||
{
|
||||
Debug.LogError("LoadAsset:" + name + ", resFailedMap");
|
||||
return null;
|
||||
}
|
||||
if (resMap.TryGetValue(name, out resData))
|
||||
{
|
||||
resData.RefCount++;
|
||||
//Debug.LogWarning("LoadAsset:" + name + ", Count:" + resData.RefCount);
|
||||
Debug.Log("LoadAsset add:" + name + ", Count:" + resData.RefCount);
|
||||
asset = resData.Asset as T;
|
||||
}
|
||||
else
|
||||
|
|
@ -203,7 +204,7 @@ namespace ResMgr
|
|||
resData = resDataPool.Get();
|
||||
resData.Name = name;
|
||||
resData.RefCount++;
|
||||
//Debug.LogWarning("LoadAsset:" + name + ", Count:" + resData.RefCount);
|
||||
Debug.Log("LoadAsset new:" + name + ", Count:" + resData.RefCount);
|
||||
resMap.Add(name, resData);
|
||||
asset = loader.LoadAsset<T>(name);
|
||||
resData.LoadSuccess(loader, asset);
|
||||
|
|
@ -340,6 +341,10 @@ namespace ResMgr
|
|||
//Debug.LogWarning("UnLoadAsset:" + name + ", Count:" + resData.RefCount);
|
||||
if (resData.RefCount <= 0)
|
||||
{
|
||||
if (resData.RefCount == 0)
|
||||
{
|
||||
Debug.LogWarning("UnLoadAsset:" + name + ", Count:" + resData.RefCount);
|
||||
}
|
||||
resMap.Remove(name);
|
||||
resData.UnLoad();
|
||||
resDataPool.Release(resData);
|
||||
|
|
@ -359,6 +364,10 @@ namespace ResMgr
|
|||
//Debug.LogWarning("UnLoadAsset:" + name + ", Count:" + resData.RefCount);
|
||||
if (resData.RefCount <= 0)
|
||||
{
|
||||
if (resData.RefCount == 0)
|
||||
{
|
||||
Debug.LogWarning("UnLoadAsset:" + name + ", Count:" + resData.RefCount);
|
||||
}
|
||||
resMap.Remove(name);
|
||||
resData.UnLoad();
|
||||
resDataPool.Release(resData);
|
||||
|
|
@ -379,6 +388,8 @@ namespace ResMgr
|
|||
resData = list[i];
|
||||
if (!resData.IsFinish) continue;
|
||||
if (resData.RefCount != 0) continue;
|
||||
|
||||
Debug.LogWarning("UnLoadAsset:" + resData.Name + ", unUse");
|
||||
resMap.Remove(resData.Name);
|
||||
resData.UnLoad();
|
||||
resDataPool.Release(resData);
|
||||
|
|
|
|||
Loading…
Reference in New Issue