miduo_client/Assets/ManagedResources/~Lua/UITools/TapContent.lua

86 lines
2.2 KiB
Lua

---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- DateTime: 2018/6/26 0026 下午 16:28
--- 简易页签容器(不管理页签布局,组件自行管理)
TapContent = {}
function TapContent:New()
local tc = {};
setmetatable(tc, { __index = TapContent });
return tc;
end
--初始化
function TapContent:Init(root, callback,check)
self.tapCount = 0;
self.tapList = {};
self.root = root;
self.callback = callback;
self.check = check;
self:InitPanel();
self:BindEvent();
end
--初始化面板
function TapContent:InitPanel()
local count = self.root.transform.childCount;
for i = 1, count do
local child = self.root.transform:GetChild(i - 1);
local tapToggle = {};
if child then
local toggle = child:GetComponent("Toggle");
if toggle then
self.tapCount = self.tapCount + 1;
tapToggle.toggle = toggle;
table.insert(self.tapList, tapToggle)
end
end
end
end
--绑定事件
function TapContent:BindEvent()
for i = 1, self.tapCount do
local uiToggle = self.tapList[i].toggle.gameObject:GetComponent("UIToggle")
uiToggle:SetCheck(self.check);
Util.AddToggle(self.tapList[i].toggle.gameObject,
function(isOn)
if(isOn)then
self:ClickEvent();
end
end);
end
end
function TapContent:ToggleEvent(name)
for i = 1, self.tapCount do
local tap = self.tapList[i];
if tap.toggle.name == name then
tap.toggle.isOn = true;
self:ClickEvent();
else
tap.toggle.isOn = false;
end
end
end
--触发事件
function TapContent:ClickEvent()
for i = 1, self.tapCount do
local tap = self.tapList[i];
local targetGraphic = tap.toggle.targetGraphic;
local graphic = tap.toggle.graphic;
if targetGraphic then
targetGraphic.gameObject:SetActive(not tap.toggle.isOn);
end
if graphic then
graphic.gameObject:SetActive(tap.toggle.isOn);
end
if tap.toggle.isOn and self.callback then
self.callback(tap.toggle.name);
end
end
end