public void GetItem(int id, int num = 1) { if (transform.childCount == 1) { SingleObjInfo info = ObjManager.Instance.GetObjectInfo(id); GameObject item = Instantiate(itemPrefab); item.transform.SetParent(this.transform); item.transform.localPosition = Vector3.zero; item.GetComponent <ItemManager>().id = id; item.GetComponent <ItemManager>().UpdateIcon(info); this.id = id; this.number += num; numText.text = number.ToString(); numText.gameObject.SetActive(true); return; } //if (transform.childCount > 1) //{ // if (id == transform.GetChild(1).GetComponent<ItemManager>().id) // { // number+=num; // numText.text = number.ToString(); // numText.gameObject.SetActive(true); // } // return; //} }
public void UpdateInfos(SingleObjInfo info) { UpdatePos(); nameText.text = "名称:" + info.name; if (info.objType == ObjType.Drug) { if (info.id % 1000 == 3) { addText.text = "+Mp:" + info.mp; } else { addText.text = "+Hp:" + info.hp; } applicationText.text = "职业:通用"; } else if (info.objType == ObjType.Equip) { if (info.equipType == EquipType.Headgear) { addText.text = "+Defence:" + info.defence; } else if (info.equipType == EquipType.Armor) { addText.text = "+Defence:" + info.defence; } else if (info.equipType == EquipType.RightHand) { addText.text = "+Attack:" + info.attack; } else if (info.equipType == EquipType.LeftHand) { addText.text = "+Defence:" + info.defence; } else if (info.equipType == EquipType.Shoe) { addText.text = "+Speed:" + info.speed; } else if (info.equipType == EquipType.Accessory) { addText.text = "+Defence:" + info.defence; } if (info.applicationType == ApplicationType.Common) { applicationText.text = "职业:通用"; } else if (info.applicationType == ApplicationType.Magician) { applicationText.text = "职业:魔法师"; } else if (info.applicationType == ApplicationType.Swordman) { applicationText.text = "职业:战士"; } } sellPriceText.text = "出售价:" + info.price_sell; buyPriceText.text = "购买价:" + info.price_buy; }
public void ReplaceEquip(SingleObjInfo info, EquipGrid equipGrid) { SingleObjInfo tempInfo = equipGrid.transform.GetChild(0).GetComponent <EquipItem>().info; equipGrid.ReduceProperties(tempInfo); Destroy(equipGrid.transform.GetChild(0).gameObject); equipGrid.GetEquip(info); UIBagManager.Instance.GetItem(tempInfo.id); }
public void GetEquip(SingleObjInfo info) { GameObject equipItem = Instantiate(EquipItemPre); equipItem.transform.SetParent(this.transform); equipItem.GetComponent <Image>().sprite = Resources.Load <Sprite>(@"RPG\GUI\Icon\" + info.icon_name); equipItem.GetComponent <EquipItem>().info = info; equipItem.transform.localPosition = Vector3.zero; AddProperties(info); }
public void OnPointerEnter(PointerEventData eventData) { if (TempItemManager.Instance.isFollow == false && this.transform.childCount > 1) { SingleObjInfo info = ObjManager.Instance.GetObjectInfo(id); if (info != null) { UpdateInfo.Instance.UpdateInfos(info); } } }
public void OnOKClick() { int number = System.Int32.Parse(BuyNumText.text); if (number > 0) { SingleObjInfo info = ObjManager.Instance.GetObjectInfo(Id); if (!PlayerStatus.Instance.ReduceCoin(info.price_buy, number, Id)) { ShowHint(); Invoke("HideHintAndDialogs", 2); } } InputDialogs.SetActive(false); }
public void ReduceProperties(SingleObjInfo info) { EquipType equipType = info.equipType; switch (equipType) { case EquipType.Headgear: PlayerStatus.Instance.ReduceAttack(info.attack); PlayerStatus.Instance.ReduceDefence(info.defence); PlayerStatus.Instance.ReduceSpeed(info.speed); break; case EquipType.Armor: PlayerStatus.Instance.ReduceAttack(info.attack); PlayerStatus.Instance.ReduceDefence(info.defence); PlayerStatus.Instance.ReduceSpeed(info.speed); break; case EquipType.RightHand: PlayerStatus.Instance.ReduceAttack(info.attack); PlayerStatus.Instance.ReduceDefence(info.defence); PlayerStatus.Instance.ReduceSpeed(info.speed); break; case EquipType.LeftHand: PlayerStatus.Instance.ReduceAttack(info.attack); PlayerStatus.Instance.ReduceDefence(info.defence); PlayerStatus.Instance.ReduceSpeed(info.speed); break; case EquipType.Shoe: PlayerStatus.Instance.ReduceAttack(info.attack); PlayerStatus.Instance.ReduceDefence(info.defence); PlayerStatus.Instance.ReduceSpeed(info.speed); break; case EquipType.Accessory: PlayerStatus.Instance.ReduceAttack(info.attack); PlayerStatus.Instance.ReduceDefence(info.defence); PlayerStatus.Instance.ReduceSpeed(info.speed); break; } UIStatus.Instacne.UpdateOriginalProperties(); }
public void UpdateItem(SingleObjInfo info) { this.info = info; Icon.sprite = Resources.Load <Sprite>(@"RPG\GUI\Icon\" + info.icon_name); Name.text = info.name; Price.text = info.price_buy.ToString(); if (info.objType == ObjType.Equip) { Describe.text = "+" + info.defence + "Defence"; switch (info.equipType) { case EquipType.Shoe: Describe.text = "+" + info.speed + "Speed"; break; case EquipType.RightHand: Describe.text = "+" + info.attack + "Attack"; break; } } }
public void UpdateIcon(SingleObjInfo info) { this.GetComponent <Image>().sprite = Resources.Load <Sprite>(@"RPG\GUI\Icon\" + info.icon_name); //Texture2D texture = (Texture2D)Resources.Load(@"RPG\GUI\Icon\" + info.icon_name); //GetComponent<Image>().sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); }
public void OnPointerClick(PointerEventData eventData) { if (eventData.button == PointerEventData.InputButton.Left) { if (TempItemManager.Instance.isFollow == false && transform.childCount > 1) { audio.Play(); TempItemManager.Instance.isFollow = true; TempItemManager.Instance.LastClickedGrid = this.gameObject; TempItemManager.Instance.UpdateIcon(transform.GetChild(1).GetComponent <Image>().sprite, this.number, this.id); Destroy(transform.GetChild(1).gameObject); numText.gameObject.SetActive(false); return; } if (TempItemManager.Instance.isFollow == true && transform.childCount == 1) { audio.Play(); TempItemManager.Instance.isFollow = false; TempItemManager.Instance.ResetPos(); GameObject item = Instantiate(itemPrefab); item.transform.SetParent(this.transform); item.transform.localPosition = Vector3.zero; item.GetComponent <Image>().sprite = TempItemManager.Instance.GetComponent <Image>().sprite; this.number = TempItemManager.Instance.number; numText.text = number.ToString(); numText.gameObject.SetActive(true); this.id = TempItemManager.Instance.id; return; } if (TempItemManager.Instance.isFollow == true && transform.childCount > 1) { audio.Play(); TempItemManager.Instance.isFollow = false; TempItemManager.Instance.ResetPos(); Sprite tempSprite = transform.GetChild(1).GetComponent <Image>().sprite; int tempNum = this.number; transform.GetChild(1).GetComponent <Image>().sprite = TempItemManager.Instance.GetComponent <Image>().sprite; int tempId = this.id; this.number = TempItemManager.Instance.number; this.id = TempItemManager.Instance.id; numText.text = number.ToString(); numText.gameObject.SetActive(true); GameObject item = Instantiate(itemPrefab); item.transform.SetParent(TempItemManager.Instance.LastClickedGrid.transform); item.transform.localPosition = Vector3.zero; item.GetComponent <Image>().sprite = tempSprite; TempItemManager.Instance.LastClickedGrid.transform.GetComponent <GridManager>().number = tempNum; TempItemManager.Instance.LastClickedGrid.transform.GetComponent <GridManager>().id = tempId; TempItemManager.Instance.LastClickedGrid.transform.GetComponent <GridManager>().numText.text = TempItemManager.Instance.LastClickedGrid.transform.GetComponent <GridManager>().number.ToString(); TempItemManager.Instance.LastClickedGrid.transform.GetComponent <GridManager>().numText.gameObject.SetActive(true); return; } } else if (eventData.button == PointerEventData.InputButton.Right) { SingleObjInfo info = ObjManager.Instance.GetObjectInfo(id); if (info.objType == ObjType.Equip) { if (info.applicationType == PlayerStatus.Instance.playerType || info.applicationType == ApplicationType.Common) { if (transform.childCount > 1) { UIEquipPanel.Instance.GetEquip(info); ReduceItem(); } } } else if (info.objType == ObjType.Drug) { if (transform.childCount > 1) { if (info.id == 1001 || info.id == 1002) { PlayerStatus.Instance.AddHp(info.hp); } else if (info.id == 1003) { PlayerStatus.Instance.AddMp(info.mp); } ReduceItem(); } } } }
public void GetEquip(SingleObjInfo info) { if (info.applicationType == PlayerStatus.Instance.playerType || info.applicationType == ApplicationType.Common) { EquipType equipType = info.equipType; switch (equipType) { case EquipType.Headgear: if (Headgear.transform.childCount == 0) { Headgear.GetEquip(info); } else { ReplaceEquip(info, Headgear); } break; case EquipType.Armor: if (Armor.transform.childCount == 0) { Armor.GetEquip(info); } else { ReplaceEquip(info, Armor); } break; case EquipType.RightHand: if (RightHand.transform.childCount == 0) { RightHand.GetEquip(info); } else { ReplaceEquip(info, RightHand); } break; case EquipType.LeftHand: if (LeftHand.transform.childCount == 0) { LeftHand.GetEquip(info); } else { ReplaceEquip(info, LeftHand); } break; case EquipType.Shoe: if (Shoe.transform.childCount == 0) { Shoe.GetEquip(info); } else { ReplaceEquip(info, Shoe); } break; case EquipType.Accessory: if (Accessory.transform.childCount == 0) { Accessory.GetEquip(info); } else { ReplaceEquip(info, Accessory); } break; } } }
private void ReadInfo() { string text = objInfoText.text; string[] oneInfo = text.Split('\n'); foreach (string str in oneInfo) { SingleObjInfo info = new SingleObjInfo(); string[] properties = str.Split(','); int id = int.Parse(properties[0]); string name = properties[1]; string icon_name = properties[2]; string objType = properties[3]; ObjType type = ObjType.Drug; switch (objType) { case "Drug": type = ObjType.Drug; break; case "Equip": type = ObjType.Equip; break; case "Material": type = ObjType.Material; break; } info.id = id; info.name = name; info.icon_name = icon_name; info.objType = type; if (type == ObjType.Drug) { int hp = int.Parse(properties[4]); int mp = int.Parse(properties[5]); int price_sell = int.Parse(properties[6]); int price_buy = int.Parse(properties[7]); info.hp = hp; info.mp = mp; info.price_sell = price_sell; info.price_buy = price_buy; } else if (type == ObjType.Equip) { info.attack = int.Parse(properties[4]); info.defence = int.Parse(properties[5]); info.speed = int.Parse(properties[6]); info.price_sell = int.Parse(properties[9]); info.price_buy = int.Parse(properties[10]); string equipType = properties[7]; switch (equipType) { case "Headgear": info.equipType = EquipType.Headgear; break; case "Armor": info.equipType = EquipType.Armor; break; case "RightHand": info.equipType = EquipType.RightHand; break; case "LeftHand": info.equipType = EquipType.LeftHand; break; case "Shoe": info.equipType = EquipType.Shoe; break; case "Accessory": info.equipType = EquipType.Accessory; break; } string applicationType = properties[8]; switch (applicationType) { case "Magician": info.applicationType = ApplicationType.Magician; break; case "Swordman": info.applicationType = ApplicationType.Swordman; break; case "Common": info.applicationType = ApplicationType.Common; break; } } objInfo.Add(id, info); } }