108 lines
2.6 KiB
Lua
108 lines
2.6 KiB
Lua
|
PlayerTitle = {}
|
||
|
local this=PlayerTitle
|
||
|
local mapNpcOp = "PlayerTitle"
|
||
|
|
||
|
function PlayerTitle:New(gameObject)
|
||
|
local b = {}
|
||
|
b.gameObject = gameObject
|
||
|
b.transform = gameObject.transform
|
||
|
setmetatable(b, { __index = PlayerTitle })
|
||
|
return b
|
||
|
end
|
||
|
--初始化组件(用于子类重写)
|
||
|
function PlayerTitle:InitComponent()
|
||
|
self.layer = 0
|
||
|
self.canvas = self.gameObject:GetComponent("Canvas")
|
||
|
end
|
||
|
|
||
|
--绑定事件(用于子类重写)
|
||
|
function PlayerTitle:BindEvent()
|
||
|
|
||
|
end
|
||
|
|
||
|
--添加事件监听(用于子类重写)
|
||
|
function PlayerTitle:AddListener()
|
||
|
|
||
|
end
|
||
|
|
||
|
--移除事件监听(用于子类重写)
|
||
|
function PlayerTitle:RemoveListener()
|
||
|
|
||
|
end
|
||
|
|
||
|
--界面打开时调用(用于子类重写)
|
||
|
function PlayerTitle:OnOpen(itemId, position, scale, layer)
|
||
|
if itemId then
|
||
|
self:SetShow(itemId, position, scale, layer)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function PlayerTitle:SetShow(itemId, position, scale, effectScale, layer)
|
||
|
self:ClearTitle()
|
||
|
|
||
|
local curPlayerRole = ConfigManager.GetConfigData(ConfigName.PlayerRole,itemId)
|
||
|
local curArtResourcesConfig = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig,curPlayerRole.LiveAnimName)
|
||
|
self.curTitleName = curArtResourcesConfig.Name
|
||
|
self.titleLive = poolManager:LoadAsset(self.curTitleName, PoolManager.AssetType.GameObject)
|
||
|
self.titleLive.transform:SetParent(self.canvas.transform)
|
||
|
|
||
|
if position then
|
||
|
self:SetPostion(position)
|
||
|
end
|
||
|
if scale then
|
||
|
self:SetScale(scale)
|
||
|
end
|
||
|
if effectScale then
|
||
|
self:SetEffectScale(effectScale)
|
||
|
end
|
||
|
if layer then
|
||
|
self:SetLayer(layer)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function PlayerTitle:SetPostion(position)
|
||
|
if self.titleLive then
|
||
|
self.titleLive.transform.localPosition = position
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
function PlayerTitle:SetScale(scale)
|
||
|
if self.titleLive then
|
||
|
self.titleLive.transform.localScale = Vector3.one * scale
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function PlayerTitle:SetEffectScale(effectScale)
|
||
|
if self.titleLive then
|
||
|
Util.SetParticleScale(self.titleLive, effectScale)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function PlayerTitle:SetLayer(layer)
|
||
|
local _layer = layer + 10
|
||
|
if self.titleLive then
|
||
|
Util.AddParticleSortLayer(self.titleLive, _layer - self.layer)
|
||
|
end
|
||
|
if self.canvas then
|
||
|
self.canvas.overrideSorting = true
|
||
|
self.canvas.sortingOrder = _layer
|
||
|
end
|
||
|
self.layer = _layer
|
||
|
end
|
||
|
|
||
|
function PlayerTitle:ClearTitle()
|
||
|
if self.titleLive then
|
||
|
destroy(self.titleLive)
|
||
|
end
|
||
|
self.titleLive = nil
|
||
|
self.curTitleName = nil
|
||
|
self.layer = 0
|
||
|
end
|
||
|
|
||
|
--界面销毁时调用(用于子类重写)
|
||
|
function PlayerTitle:OnClose()
|
||
|
self:ClearTitle()
|
||
|
end
|
||
|
|
||
|
return PlayerTitle
|