项目记录25--unity-tolua框架 View02---BasePanel.lua

还在,还在。。。。。每天晚上找点时间写点点,多了也不想学究竟是什么心理啊。写完看电影去。今天写两个算超完成了BaseUI.lua,UIManager.lua(完善中这个)



local BasePanel = class("BasePanel",require("Base.BaseUI"))


function BasePanel:ctor(panelName)
--加载prefab
local uiTransform = self:_loadPanel(panelName)
--调用父类
BasePanel.super.ctor(self,panelName,uiTransform)
--初始化
self:_BaseInit()
--开始默认是隐藏
self:Hide()
end


function BasePanel:_BaseInit(  )
self:_RegisterComponents()
self:_Init()
self:_RegisterEvents()
end


--[[
加载prefab
]]
function BasePanel:_loadPanel(panelName)
if panelName == nil then
return
end
local path = PREFABS_PATH..panelName
--安装路径加载prefabe: 区分开发时期和发布时期
local tempObj = UnityEngine.Resources.Load(path)
local obj = UnityEngine.Object.Instantiate(tempObj) 
--设置它父类是UI_ROOT
obj.transform:SetParent(UIManager:Instance()._uiRoot.transform)
local rectTransform = obj:GetComponent(typeof(UnityEngine.RectTransform))
rectTransform.localScale = Vector3.New(1,1,1)
rectTransform.localPosition = Vector3.New(0,0,0)
r eturn obj.transform
end
--[[


]]
function BasePanel:Show()
BasePanel.super.Show(self)
UIManager:Instance():AddPanel(self)
self._uiTransform:SetAsLastSibling() --设置最前
end


--关闭UIPanel 非 Hide
function BasePanel:Close()
UIManager:Instance():RemovePanel(self)
--发出一个关闭的命令
self:Dispatcher(CLOSE_PANEL_EVENT)
BasePanel.super.Close(self)
end


return BasePanel

你可能感兴趣的:(项目记录25--unity-tolua框架 View02---BasePanel.lua)