BagPanel
BagPanel = {}
BagPanel.panelObj = nil
BagPanel.btnClose = nil
BagPanel.togEquip = nil
BagPanel.togItem = nil
BagPanel.togGem = nil
BagPanel.svBag = nil
BagPanel.Content = nil
BagPanel.items = {}
BagPanel.nowType = -1
function BagPanel:Init()
if self.panelObj == nil then
self.panelObj = ABMgr:LoadRes("ui", "BagPanel", typeof(GameObject))
self.panelObj.transform:SetParent(Canvas, false)
self.btnClose = self.panelObj.transform:Find("btnClose"):GetComponent(typeof(Button))
local group = self.panelObj.transform:Find("Group")
self.togEquip = group:Find("togEquip"):GetComponent(typeof(Toggle))
self.togItem = group:Find("togItem"):GetComponent(typeof(Toggle))
self.togGem = group:Find("togGem"):GetComponent(typeof(Toggle))
self.svBag = self.panelObj.transform:Find("svBag"):GetComponent(typeof(ScrollRect))
self.Content = self.svBag.transform:Find("Viewport"):Find("Content")
self.btnClose.onClick:AddListener(function()
self:HideMe()
end)
self.togEquip.onValueChanged:AddListener(function(value)
if value == true then
self:ChangeType(1)
end
end)
self.togItem.onValueChanged:AddListener(function(value)
if value == true then
self:ChangeType(2)
end
end)
self.togGem.onValueChanged:AddListener(function(value)
if value == true then
self:ChangeType(3)
end
end)
end
end
function BagPanel:ShowMe()
self:Init()
self.panelObj:SetActive(true)
if self.nowType == -1 then
self:ChangeType(1)
end
end
function BagPanel:HideMe()
self.panelObj:SetActive(false)
end
function BagPanel:ChangeType(type)
if self.nowType == type then
return
end
for i = 1, #self.items do
self.items[i]:Destroy()
end
self.items = {}
local nowItems = nil
if type == 1 then
nowItems = PlayerData.equips
elseif type == 2 then
nowItems = PlayerData.items
else
nowItems = PlayerData.gems
end
for i = 1, #nowItems do
local grid = ItemGrid:new()
grid:Init(self.Content, (i-1)%4*175, math.floor((i-1)/4)*175)
grid:InitData(nowItems[i])
table.insert(self.items, grid)
end
end
ItemGrid
Object:subClass("ItemGrid")
ItemGrid.obj = nil
ItemGrid.imgIcon = nil
ItemGrid.Text = nil
function ItemGrid:Init(father, posX, posY)
self.obj = ABMgr:LoadRes("ui", "ItemGrid");
self.obj.transform:SetParent(father, false)
self.obj.transform.localPosition = Vector3(posX, posY, 0)
self.imgIcon = self.obj.transform:Find("imgIcon"):GetComponent(typeof(Image))
self.Text = self.obj .transform:Find("Text"):GetComponent(typeof(Text))
end
function ItemGrid:InitData(data)
local itemData = ItemData[data.id]
local strs = string.split(itemData.icon, "_")
local spriteAtlas = ABMgr:LoadRes("ui", strs[1], typeof(SpriteAtlas))
self.imgIcon.sprite = spriteAtlas:GetSprite(strs[2])
self.Text.text = data.num
end
function ItemGrid:Destroy()
GameObject.Destroy(self.obj)
self.obj = nil
end
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步