public override void Awake(GameObject go) { propItem = this.transform.Find("Storehouse/Scroll View/Viewport/Content/Item").gameObject; propItem.SetActive(false); itemHeight = propItem.GetComponent <RectTransform>().rect.height; btnItem = this.transform.Find("Storehouse/Scroll View/Viewport/Content/Btn").gameObject.AddComponent <aSongUI_PropListItem>(); btnItem.gameObject.SetActive(false); btnItem.transform.Find("PutOn").GetComponent <Button>().onClick.AddListener(BackpackListButton_PutOn); btnItem.transform.Find("Discard").GetComponent <Button>().onClick.AddListener(Discard); usingItem = this.transform.Find("Storehouse/Scroll View/Viewport/Content/Using").gameObject.AddComponent <aSongUI_PropListItem>(); usingItem.gameObject.SetActive(false); usingItem.transform.Find("PutOn").GetComponent <Button>().onClick.AddListener(BackpackListButton_PutOn); content = this.transform.Find("Storehouse/Scroll View/Viewport/Content").GetComponent <RectTransform>(); weightText = transform.Find("Storehouse/Instruction/Weight").GetComponent <Text>(); transform.Find("Storehouse/Instruction/Back").GetComponent <Button>().onClick.AddListener(() => { TTUIPage.ClosePage <aSongUI_Backpack>(); }); leftWeapon = transform.Find("Weapons/LeftWeapon").gameObject.AddComponent <aSongUI_BackpackWeapon>(); rightWeapon = transform.Find("Weapons/RightWeapon").gameObject.AddComponent <aSongUI_BackpackWeapon>(); leftWeapon.Init(); rightWeapon.Init(); }
/// <summary> /// 按钮:装备 /// </summary> void BackpackListButton_PutOn() { aSongUI_PropListItem item = choosedItem; if (item.data != null) { //PickupProp(item.data.propID); switch (item.data.type) { case PropType.bomb: break; case PropType.bullet: break; case PropType.cartridgeClip: case PropType.gunHandle: case PropType.gunstock: case PropType.muzzle: case PropType.telescope: PutOnParts(item.data); break; default: break; } } }
/// <summary> /// 隐藏按钮Item /// </summary> void HideBtnItem() { choosedItem = null; btnItem.gameObject.SetActive(false); if (propItems.Contains(btnItem)) { propItems.Remove(btnItem); } }
//点击按钮后,我们需要拿起武器或者收起武器 public void OnClickSkillItem() { aSongUI_PropListItem item = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.GetComponent <aSongUI_PropListItem>(); Debug.Log("Clicked name = " + UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name); //Debug.Log("propID = " + item.data.propID); Debug.Log("name = " + item.data.name.ToString()); if (item.data != null) { PickupProp(item.data.propID); } }
/// <summary> /// 显示按钮Item /// </summary> /// <param name="_item">当前选中的item</param> void ShowBtnItem(aSongUI_PropListItem _item) { choosedItem = _item; if (choosedItem.data.type == PropType.health) { } btnItem.gameObject.SetActive(true); if (propItems.Contains(btnItem)) { propItems.Remove(btnItem); } propItems.Insert(propItems.IndexOf(choosedItem) + 1, btnItem); }
/// <summary> /// 道具按键响应事件:显示还是隐藏BtnItem /// </summary> void BackpackListButtonCliked() { aSongUI_PropListItem item = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.GetComponent <aSongUI_PropListItem>(); if (choosedItem != item) { ShowBtnItem(item); } else { HideBtnItem(); } RefreshBackpackScrow(); }
private void GetPropItemFromPool(aSong_PlayerData.Prop prop) { if (propItemsPool.Count <= 0) { return; } aSongUI_PropListItem item = propItemsPool[0]; propItemsPool.Remove(item); propItems.Add(item); item.gameObject.SetActive(true); item.Refresh(prop); item.transform.localPosition = Vector3.up * -item.GetComponent <RectTransform>().rect.height *(propItems.Count - 1); return; }
private void CreatePropItem(aSong_PlayerData.Prop prop) { GameObject go = GameObject.Instantiate(propItem) as GameObject; go.transform.SetParent(propItem.transform.parent); go.transform.localScale = Vector3.one; go.SetActive(true); aSongUI_PropListItem item = go.AddComponent <aSongUI_PropListItem>(); item.Refresh(prop); propItems.Add(item); item.transform.localPosition = Vector3.up * -item.GetComponent <RectTransform>().rect.height *(propItems.Count - 1); Debug.Log("CreatePropItem"); //add click btn go.AddComponent <Button>().onClick.AddListener(aSongUI_Controller.Instance.OnClickSkillItem); }