// Res public LegendCupPrizeItem CreateLegendCupPrizeItem(RectTransform container) { GameObject newItem = m_legendCupPrizeItemRes.InstanceMainRes(); LegendCupPrizeItem result = null; if (newItem) { result = newItem.GetComponent <LegendCupPrizeItem>(); if (result) { result.SetContainer(container); } else { m_legendCupPrizeItemRes.DestroyInstanceRes(ref newItem); } } return(result); }
public void OnShowPrizePopupWnd(UPrizePopupData data) { if (data.nPrizeIdList == null) { return; } int nPrizeCount = data.nPrizeIdList.Count; // 动态改变UI大小 //// 方案1水平排列 //RectTransform rectParent = this.gameObject.transform as RectTransform; //RectTransform rectItem = PrizeTemplate.transform as RectTransform; //float fNeedWidth = (nPrizeCount + 1) * rectItem.sizeDelta.x; //Vector2 vecParentSize = rectParent.sizeDelta; //vecParentSize.x = Mathf.Max(500.0f, fNeedWidth); //rectParent.sizeDelta = vecParentSize; // 方案2竖直排列 //RectTransform rectParent = this.gameObject.transform as RectTransform; //RectTransform rectItem = PrizeTemplate.transform as RectTransform; //Vector2 vecParentSize = rectParent.sizeDelta; //vecParentSize.y = ((nPrizeCount - 1) / 4 + 1) * rectItem.sizeDelta.y + 212;// 4个Item一行 //rectParent.sizeDelta = vecParentSize; // 设置基础 PrizeTitle.text = data.strPrizeTitle; PrizeDescription.text = data.strPrizeDesc; PrizeDescription.gameObject.SetActive(!String.IsNullOrEmpty(data.strPrizeDesc)); ConfirmBtnDesc.text = ULocalizationService.Instance.Get("UIView", "Common", "ConfirmBtn"); // 设置奖励Item int nChildCount = PrizeFrame.childCount; for (int i = nChildCount - 1; i >= 0; i--) { Transform trans = PrizeFrame.GetChild(i); if (trans) { var temp = trans.gameObject; ResNode.DestroyRes(ref temp); } } // 普通奖励 if (data.nPrizeIdList != null) { for (int i = 0; i < nPrizeCount && data.nPrizeIdList[i] > 0; i++) { GameObject prizeObj = ResNode.InstantiateRes(PrizeTemplate); if (!prizeObj) { return; } RectTransform prizeRect = prizeObj.transform as RectTransform; if (!prizeRect) { return; } prizeRect.SetParent(PrizeFrame, false); LegendCupPrizeItem prizeItem = prizeObj.GetComponent <LegendCupPrizeItem>(); if (!prizeItem) { return; } prizeItem.SetData(data.nPrizeIdList[i]); } } // 天赋奖励 if (data.nTalentIDList != null) { int nHeroID = data.nHeroID; for (int j = 0; j < data.nTalentIDList.Count; ++j) { GameObject prizeObj = ResNode.InstantiateRes(PrizeTemplate); if (!prizeObj) { return; } RectTransform prizeRect = prizeObj.transform as RectTransform; if (!prizeRect) { return; } prizeRect.SetParent(PrizeFrame, false); LegendCupPrizeItem prizeItem = prizeObj.GetComponent <LegendCupPrizeItem>(); if (!prizeItem) { return; } int nTalentID = data.nTalentIDList[j]; SSchemeHeroTalentConfig talentConfig = HeroTalentConfigPage.Instance.GetHeroTalentConfig(nHeroID, nTalentID); prizeItem.SetData(talentConfig); } } // 金币、经验奖励 if (data.nMoneyCount > 0) { GameObject prizeObj = ResNode.InstantiateRes(PrizeTemplate); if (!prizeObj) { return; } RectTransform prizeRect = prizeObj.transform as RectTransform; if (!prizeRect) { return; } prizeRect.SetParent(PrizeFrame, false); LegendCupPrizeItem prizeItem = prizeObj.GetComponent <LegendCupPrizeItem>(); if (!prizeItem) { return; } prizeItem.SetData(data.nMoneyCount, ECupPrizeType.ECPT_Gold); } if (data.nExpCount > 0) { GameObject prizeObj = ResNode.InstantiateRes(PrizeTemplate); if (!prizeObj) { return; } RectTransform prizeRect = prizeObj.transform as RectTransform; if (!prizeRect) { return; } prizeRect.SetParent(PrizeFrame, false); LegendCupPrizeItem prizeItem = prizeObj.GetComponent <LegendCupPrizeItem>(); if (!prizeItem) { return; } prizeItem.SetData(data.nExpCount, ECupPrizeType.ECPT_Exp); } PrizeTemplate.SetActive(false); }