public void OnPointerDown(PointerEventData eventData) //按下第一帧 { //根据ID显示信息 switch (SelfData.iD / 1000) { case 1: WeaponsItem weaItem = SelfData as WeaponsItem; ShowData(weaItem.name, new Color(1, 0, 0), weaItem.description, 0, "Attack", weaItem.attack.ToString()); GameObject.Find("Violent").GetComponent <Text>().text = string.Format("{0:P0}", weaItem.violent); break; case 2: ClothingItem cloItem = SelfData as ClothingItem; ShowData(cloItem.name, new Color(1, 1, 0), cloItem.description, 1, "Defense", cloItem.defense.ToString()); break; case 3: FoodsItem fooItem = SelfData as FoodsItem; ShowData(fooItem.name, new Color(0, 1, 0), fooItem.description, 2, "Cure", fooItem.cure.ToString()); break; case 4: PropItem proItem = SelfData as PropItem; ShowData(proItem.name, new Color(0, 0, 1), proItem.description, 3, "", ""); break; } FrameSwitch(); }
void ShowData() //显示信息 { //名字和描述显示当前物品的信息 GameObject.Find("NameText").GetComponent <Text>().text = selfItem.name; GameObject.Find("DescriptionText").GetComponent <Text>().text = selfItem.description; switch (selfItem.type) //根据物品类型显示自身独有的信息 { case GoodsType.Weapon: WeaponsItem weaponData = selfItem as WeaponsItem; //selfItem是Item类型,没有攻击力的字段,所以要进行转换 ShowSelfData("攻击力:", weaponData.attack.ToString(), "暴击率:", string.Format("{0:P0}", weaponData.violent)); break; case GoodsType.Clothing: ClothingItem clothingData = selfItem as ClothingItem; ShowSelfData("物理防御:", clothingData.physicalDefense.ToString(), "魔法防御:", clothingData.magicDefense.ToString()); break; case GoodsType.Prop: PropItem propData = selfItem as PropItem; ShowSelfData("血量回复:", propData.addHP.ToString(), "法力回复:", propData.addMP.ToString()); break; } }