----- 灵兽宝阁选择神兽 ----- local this = {} --传入父脚本模块 local parent --传入特效层级 local SpiritAnimalSummonConfig = ConfigManager.GetConfig(ConfigName.SpiritAnimalSummon) local sortingOrder=0 local itemsGrid = {}--item重复利用 local itemViewGrid = {} local itemGoGrid = {} local ActData=nil local curMonsterId = nil local oldMonsterId = nil local curIndex = nil function this:InitComponent(gameObject) this.spLoader = SpriteLoader.New() this.titleText=Util.GetGameObject(gameObject,"TitleText"):GetComponent("Text") this.tip=Util.GetGameObject(gameObject,"tip"):GetComponent("Text") this.root = Util.GetGameObject(gameObject, "Root") this.itemPre = Util.GetGameObject(gameObject, "itemPre") this.confirm = Util.GetGameObject(gameObject, "ConfirmBtn") this.cancel = Util.GetGameObject(gameObject, "CancelBtn") end function this:BindEvent() Util.AddClick(this.confirm,function() if curMonsterId == oldMonsterId then parent:ClosePanel() return end NetManager.ChengeMonsterChooseRequest(ActData.activityId,curIndex,function () parent:ClosePanel() end) end) Util.AddClick(this.cancel,function() parent:ClosePanel() end) end function this:AddListener() end function this:RemoveListener() end function this:OnShow(_parent,...) parent=_parent sortingOrder = _parent.sortingOrder --不定参中包含的不定参 _args[1]为面板类型 _args[2]之后(包括)为打开面板后传入的不定参 local _args = {...} ActData = _args[1] oldMonsterId = _args[2] curMonsterId = _args[2] this.titleText.text=Language[11565] this.tip.text = Language[11566] LogYellow("ActData.ActivityId:"..ActData.activityId) local monsterData = ConfigManager.GetAllConfigsDataByKey(ConfigName.SpiritAnimalSummon,"ActivityID",ActData.activityId) if not itemsGrid then itemsGrid = {} itemViewGrid = {} itemGoGrid = {} end for k,v in ipairs(itemsGrid) do v.gameObject:SetActive(false) end for k,v in ipairs(itemViewGrid) do v.gameObject:SetActive(false) end for i = 1, #monsterData do local item = itemsGrid[i] if not item then item = newObject(this.itemPre) item.name = "itemPre_"..i item.transform:SetParent(this.root.transform) item.transform.localScale = Vector3.one item.transform.localPosition = Vector3.zero itemsGrid[i] = item end item.gameObject:SetActive(true) this:SetSingleMonster(item,i,monsterData[i]) end end function this:SetSingleMonster(item,i,data) local icon = Util.GetGameObject(item,"icon") local btn = Util.GetGameObject(item,"btn") local btnGo = Util.GetGameObject(item,"btn/Go") itemGoGrid[i] = btnGo if not itemViewGrid[i] then itemViewGrid[i] = SubUIManager.Open(SubUIConfig.ItemView,icon.transform) end itemViewGrid[i].gameObject:SetActive(true) itemViewGrid[i]:OnOpen(false, {data.FocusID,0},1.5,false,false,false,sortingOrder) if curMonsterId == data.FocusID then btnGo:SetActive(true) curIndex = i else btnGo:SetActive(false) end Util.AddOnceClick(btn,function () for i = 1, #itemGoGrid do if itemGoGrid[i].activeSelf then itemGoGrid[i]:SetActive(false) end end curIndex = i curMonsterId = data.FocusID btnGo:SetActive(true) end) end function this:OnClose() end function this:OnDestroy() this.spLoader:Destroy() itemsGrid = {}--item重复利用 itemViewGrid = {} itemGoGrid = {} end return this