private GameObject setInfo(roleInfo pInfo, int orderUIID) { //加载图片 string fileName = csPicPath + pInfo.picName; Texture2D texture1 = (Texture2D)Resources.Load(csPicPath + pInfo.picName) as Texture2D; //创建UI UnityEngine.Object infoObj = Resources.Load("Prefab/UI/" + csRoleInfo); GameObject tmpObj = GameObject.Instantiate(infoObj, viewPortLst) as GameObject; //Image tmpImage = tmpObj.GetComponent<Image>(); //tmpImage.sprite = Sprite.Create(texture1, new Rect(0, 0, texture1.width, texture1.height), new Vector2(0.5f, 0.5f)); //hp显示及背景默认隐藏 roleInfoUI tmpInfoUI = tmpObj.GetComponent <roleInfoUI>(); tmpInfoUI.hpSlider.value = pInfo.hp * 100.0f / pInfo.maxHp; tmpInfoUI.backImage.gameObject.SetActive(false); tmpInfoUI.picIcon.sprite = Sprite.Create(texture1, new Rect(0, 0, texture1.width, texture1.height), new Vector2(0.5f, 0.5f)); tmpInfoUI.roleID = pInfo.roleID; pInfo.infoUI = tmpInfoUI; // uiRole.Add(pInfo); //int order = uiRole.Count - 1; tmpInfoUI.orderUIID = orderUIID; //点击事件绑定 Button tmpBtn = tmpObj.GetComponent <Button>(); tmpBtn.onClick.AddListener(delegate() { this.OnClick(orderUIID); }); return(tmpObj); }
//确定选择的怪物 public void OKBtnClick() { if (calBackEvent != null) { roleInfoUI tmpInfo = uiRole[oldRoleIndex].infoUI; calBackEvent(tmpInfo.roleID); } UIclose(); }
//设置选中 private void setSel(int orderUIID, bool isSel) { roleInfoUI tmpInfo = uiRole[orderUIID].infoUI; tmpInfo.backImage.gameObject.SetActive(isSel); }