/// <summary> /// 穿上装备 /// </summary> /// <param name="id">需要穿上的装备id</param> /// <returns></returns> public bool Dress(string id) { ObjectInfo info = ObjectsInfo.instance.GetObjectInfoById(id); //穿戴必须是装备 if (info.type != ObjectType.Equip) { return(false); } //人物是剑士,但是装备是魔法师 if (playerStatus.heroType == HeroType.Swordman) { if (info.applicationType == ApplicationType.Magician) { return(false); } } if (playerStatus.heroType == HeroType.Magician) { if (info.applicationType == ApplicationType.Swordman) { return(false); } } //判断装备要放在哪个格子下面 GameObject parent = null; switch (info.dressType) { case DressType.Headgear: parent = headgear; break; case DressType.Armor: parent = armor; break; case DressType.LeftHand: parent = leftHand; break; case DressType.RightHand: parent = rightHand; break; case DressType.Shoe: parent = shoe; break; case DressType.Accessory: parent = accessory; break; } EquipmentItem item = parent.GetComponentInChildren <EquipmentItem>(); //如果不为空,代表已经装备类同类型装备 if (item != null) { //把当前的物品添加到背包,装备栏的物品更换为新的装备 Inventory.instance.AddItemToBag(item.id); item.SetIconName(info); } else { GameObject itemGo = parent.AddChild(equipmentItem); itemGo.transform.localPosition = Vector3.zero; itemGo.GetComponent <EquipmentItem>().SetIconName(info); itemGo.GetComponent <UISprite>().depth = parent.GetComponent <UISprite>().depth + 1; } UpdateProperty(); return(true); }