--基础组件类
|
|
BaseComponent = BaseComponent or BaseClass(EventDispatcher)
|
|
local BaseComponent = BaseComponent
|
|
function BaseComponent:__init(parent_transform)
|
|
self.parent_transform = parent_transform
|
|
end
|
|
|
|
function BaseComponent:CreateGameObject(uiType,uiName)
|
|
self.gameObject = UiFactory.createChild(self.parent_transform,uiType,uiName or uiType)
|
|
if self.gameObject then
|
|
self.transform = self.gameObject.transform
|
|
self.cache_findChild = self.transform.Find
|
|
self:LoadSuccess()
|
|
if self.pos_x and self.pos_y then
|
|
self:SetPosition(self.pos_x,self.pos_y)
|
|
end
|
|
end
|
|
end
|
|
--[[
|
|
获取子对象的transform
|
|
特别注意此方法是从根节点开始搜寻子对象 所以要写全路径 比如:"input/Text"
|
|
]]
|
|
function BaseComponent:GetChild(name)
|
|
if self.cache_findChild and self.transform then
|
|
return self.cache_findChild(self.transform,name)
|
|
end
|
|
end
|
|
|
|
--在子类中继承
|
|
function BaseComponent:LoadSuccess()
|
|
end
|
|
|
|
function BaseComponent:SetVisible(b)
|
|
self.gameObject:SetActive(b)
|
|
end
|
|
|
|
function BaseComponent:GetVisible()
|
|
return self.gameObject.activeSelf
|
|
end
|
|
|
|
function BaseComponent:SetPosition(x, y)
|
|
if self.transform then
|
|
self.transform.anchoredPosition = Vector2(x, y)
|
|
else
|
|
self.pos_x,self.pos_y = x,y
|
|
end
|
|
end
|
|
|
|
function BaseComponent:GetPosition()
|
|
return self.transform.localPosition
|
|
end
|
|
|
|
function BaseComponent:__delete()
|
|
self._use_delete_method = true
|
|
|
|
if self.gameObject then
|
|
destroy(self.gameObject)
|
|
self.gameObject = nil
|
|
end
|
|
end
|
|
|
|
function BaseComponent:GetChildren( names )
|
|
GetChildren(self, names)
|
|
end
|