Skip to content

Commit

Permalink
add 在lua中动态替换图片的例子
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoqingqing committed Jun 15, 2021
1 parent b052176 commit 4a06413
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion KSFramework/Assets/Code/XLuaCustomExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static List<Type> AddNameSpaceClass<T>(string namespaceName)
typeof(UnityEngine.Events.UnityAction<string>),
typeof(System.Collections.IEnumerator),
typeof(System.Action<Transform,int>),
//typeof(KEngine.SpriteLoader.CSpriteLoaderDelegate),
typeof(KEngine.KSpriteAtlasLoader.CKSpriteAtlasLoaderDelegate),
typeof(System.Action<KEngine.UI.UIController, object[]>),
typeof(UnityAction<string,string>),
};
Expand Down
3 changes: 3 additions & 0 deletions KSFramework/Product/Lua/Init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ UIModule = CS.KEngine.UI.UIModule
SceneLoader = CS.KEngine.SceneLoader
---@type KEngine.LoaderMode
LoaderMode = CS.KEngine.LoaderMode
---@type KEngine.KSpriteAtlasLoader
KSpriteAtlasLoader = CS.KEngine.KSpriteAtlasLoader

---@type AppSettings.BillboardSettings
BillboardSettings = CS.AppSettings.BillboardSettings
---@type AppSettings.GameConfigSettings
Expand Down
19 changes: 18 additions & 1 deletion KSFramework/Product/Lua/UI/UIRoleInfo/UIRoleInfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local UIBase = import('UI/UIBase')
---@type UIRoleInfo
local UIRoleInfo = {}
extends(UIRoleInfo, UIBase)

local atlasLoader
-- create a ui instance
function UIRoleInfo.New(controller)
local newUI = new(UIRoleInfo)
Expand All @@ -17,10 +17,27 @@ function UIRoleInfo:OnInit(controller)
UIModule.Instance:CloseWindow("UIRoleInfo")
UIModule.Instance:DestroyWindow("UIRoleInfo")
end)
Tools.SetButton(self.btn_img,function()
print("change sprite from atlas")
atlasLoader = KSpriteAtlasLoader.Load("uiatlas/atlas_common", "btn_win_close", function(isOk, loadSprite)
if (isOk) then
self.img.sprite = loadSprite;
self.img:SetNativeSize();
print("图片从图集加载完成");
end
end);
end)
end

function UIRoleInfo:OnOpen()

end

function UIRoleInfo:OnClose()
print("release loader")
if atlasLoader then
atlasLoader:Release(true);
end
end

return UIRoleInfo

0 comments on commit 4a06413

Please sign in to comment.