void OnClick() { if (mouse == 0) //鼠标左键 { nameLabel.text = this.Name; toughenLabel.text = "强化: " + this.ToughenLevel; levelLabel.text = "等级: " + this.Level; starLevelLabel.text = "品质: " + this.StarLevel; intelLabel.text = "智力: " + this.Intel; strengthLabel.text = "力量: " + this.Strength; matkLabel.text = "魔法攻击力: " + this.Matk; patkLabel.text = "物理攻击力: " + this.Patk; descLabel.text = this.Desc; tween.PlayForward(); } if (mouse == 1)//鼠标右键 { itemdbTmp = new InventoryItemDB(); //1.根据当前物品的信息找到PlayerProperty组件中的对应Sprite switch (this.Type) { case (int)EquipType.HELMET: //2.头盔 playerProperty = GameObject.Find("UI Root/PlayerProperty/HelmSprite").GetComponent <InventoryItemProperty>(); SetProperties(this, itemdbTmp); //将背包中的物品信息存储到临时变量 this.SetProperties(playerProperty); // this.IsDressed = 0; //装备脱下,IsDressed设置为0 playerProperty.SetProperties(itemdbTmp); // //交换--图片的显示 playerSprite = playerProperty.GetComponent <UISprite>(); knapsackSprite = transform.GetComponent <UISprite>(); playerSprite.spriteName = playerProperty.SpriteName; knapsackSprite.spriteName = this.SpriteName; break; case (int)EquipType.CLOTH: //3.衣服 playerProperty = GameObject.Find("UI Root/PlayerProperty/ClothSprite").GetComponent <InventoryItemProperty>(); SetProperties(this, itemdbTmp); //将背包中的物品信息存储到临时变量 this.SetProperties(playerProperty); // this.IsDressed = 0; //装备脱下,IsDressed设置为0 playerProperty.SetProperties(itemdbTmp); // //交换--图片的显示 playerSprite = playerProperty.GetComponent <UISprite>(); knapsackSprite = transform.GetComponent <UISprite>(); playerSprite.spriteName = playerProperty.SpriteName; knapsackSprite.spriteName = this.SpriteName; break; case (int)EquipType.WING: //4.翅膀 playerProperty = GameObject.Find("UI Root/PlayerProperty/WingSprite").GetComponent <InventoryItemProperty>(); SetProperties(this, itemdbTmp); //将背包中的物品信息存储到临时变量 this.SetProperties(playerProperty); // this.IsDressed = 0; //装备脱下,IsDressed设置为0 playerProperty.SetProperties(itemdbTmp); // //交换--图片的显示 playerSprite = playerProperty.GetComponent <UISprite>(); knapsackSprite = transform.GetComponent <UISprite>(); playerSprite.spriteName = playerProperty.SpriteName; knapsackSprite.spriteName = this.SpriteName; break; case (int)EquipType.SHOES: //5.鞋子 playerProperty = GameObject.Find("UI Root/PlayerProperty/ShoesSprite").GetComponent <InventoryItemProperty>(); SetProperties(this, itemdbTmp); //将背包中的物品信息存储到临时变量 this.SetProperties(playerProperty); // this.IsDressed = 0; //装备脱下,IsDressed设置为0 playerProperty.SetProperties(itemdbTmp); // //交换--图片的显示 playerSprite = playerProperty.GetComponent <UISprite>(); knapsackSprite = transform.GetComponent <UISprite>(); playerSprite.spriteName = playerProperty.SpriteName; knapsackSprite.spriteName = this.SpriteName; break; case (int)EquipType.WEAPON: //6.武器 playerProperty = GameObject.Find("UI Root/PlayerProperty/WeaponSprite").GetComponent <InventoryItemProperty>(); SetProperties(this, itemdbTmp); //将背包中的物品信息存储到临时变量 this.SetProperties(playerProperty); // this.IsDressed = 0; //装备脱下,IsDressed设置为0 playerProperty.SetProperties(itemdbTmp); // //交换--图片的显示 playerSprite = playerProperty.GetComponent <UISprite>(); knapsackSprite = transform.GetComponent <UISprite>(); playerSprite.spriteName = playerProperty.SpriteName; knapsackSprite.spriteName = this.SpriteName; break; case (int)EquipType.BRACELET: //7.手镯 playerProperty = GameObject.Find("UI Root/PlayerProperty/BraceletSprite").GetComponent <InventoryItemProperty>(); SetProperties(this, itemdbTmp); //将背包中的物品信息存储到临时变量 this.SetProperties(playerProperty); // this.IsDressed = 0; //装备脱下,IsDressed设置为0 playerProperty.SetProperties(itemdbTmp); // //交换--图片的显示 playerSprite = playerProperty.GetComponent <UISprite>(); knapsackSprite = transform.GetComponent <UISprite>(); playerSprite.spriteName = playerProperty.SpriteName; knapsackSprite.spriteName = this.SpriteName; break; case (int)EquipType.NECKLACE: //8.项链 playerProperty = GameObject.Find("UI Root/PlayerProperty/NecklaceSprite").GetComponent <InventoryItemProperty>(); SetProperties(this, itemdbTmp); //将背包中的物品信息存储到临时变量 this.SetProperties(playerProperty); // this.IsDressed = 0; //装备脱下,IsDressed设置为0 playerProperty.SetProperties(itemdbTmp); // //交换--图片的显示 playerSprite = playerProperty.GetComponent <UISprite>(); knapsackSprite = transform.GetComponent <UISprite>(); playerSprite.spriteName = playerProperty.SpriteName; knapsackSprite.spriteName = this.SpriteName; break; case (int)EquipType.RING: //9.戒指 playerProperty = GameObject.Find("UI Root/PlayerProperty/RingSprite").GetComponent <InventoryItemProperty>(); SetProperties(this, itemdbTmp); //将背包中的物品信息存储到临时变量 this.SetProperties(playerProperty); // this.IsDressed = 0; //装备脱下,IsDressed设置为0 playerProperty.SetProperties(itemdbTmp); // //交换--图片的显示 playerSprite = playerProperty.GetComponent <UISprite>(); knapsackSprite = transform.GetComponent <UISprite>(); playerSprite.spriteName = playerProperty.SpriteName; knapsackSprite.spriteName = this.SpriteName; break; default: break; } //2.与数据库同步 InventoryItemDB itdb_player = CreateInventoryItem(playerProperty); InventoryItemDB itdb_knapsack = CreateInventoryItem(this); List <InventoryItemDB> list = new List <InventoryItemDB>(); list.Add(itdb_player); list.Add(itdb_knapsack); Dictionary <byte, object> parameters = new Dictionary <byte, object>(); string json = JsonMapper.ToJson(list); parameters.Add((byte)ParameterCode.SubCode, SubCode.UpdateInventoryItems); parameters.Add((byte)ParameterCode.InventoryItemList, json); InventoryItemController.Instance.SendRequest(OperationCode.InventoryItem, parameters); } }
//在Unity客户端展示角色的装备和角色属性 public void DisplayInventoryItems(List <InventoryItemDB> itdbList) { InventoryItemProperty property = null; foreach (InventoryItemDB itdb in itdbList) { if (itdb.Type >= (int)EquipType.HELMET) //1.如果是装备 { if (itdb.IsDressed > 0) //已穿戴 { switch (itdb.Type) { case (byte)EquipType.HELMET: //穿戴头盔 helmSprite.spriteName = itdb.SpriteName; property = helmSprite.GetComponent <InventoryItemProperty>(); property.SetProperties(itdb); break; case (byte)EquipType.CLOTH: //穿戴盔甲 clothSprite.spriteName = itdb.SpriteName; property = clothSprite.GetComponent <InventoryItemProperty>(); property.SetProperties(itdb); break; case (byte)EquipType.WING: //穿戴翅膀 wingSprite.spriteName = itdb.SpriteName; property = wingSprite.GetComponent <InventoryItemProperty>(); property.SetProperties(itdb); break; case (byte)EquipType.SHOES: //穿戴鞋子 shoesSprite.spriteName = itdb.SpriteName; property = shoesSprite.GetComponent <InventoryItemProperty>(); property.SetProperties(itdb); break; case (byte)EquipType.WEAPON: //穿戴武器 weaponSprite.spriteName = itdb.SpriteName; property = weaponSprite.GetComponent <InventoryItemProperty>(); property.SetProperties(itdb); break; case (byte)EquipType.BRACELET: //穿戴手镯 braceletSprite.spriteName = itdb.SpriteName; property = braceletSprite.GetComponent <InventoryItemProperty>(); property.SetProperties(itdb); break; case (byte)EquipType.NECKLACE: //穿戴项链 necklaceSprite.spriteName = itdb.SpriteName; property = necklaceSprite.GetComponent <InventoryItemProperty>(); property.SetProperties(itdb); break; case (byte)EquipType.RING: //穿戴戒指 ringSprite.spriteName = itdb.SpriteName; property = ringSprite.GetComponent <InventoryItemProperty>(); property.SetProperties(itdb); break; default: break; } } else//如果没穿戴,则在背包的装备栏中展示 { if (itdb.Type >= (int)EquipType.HELMET) { //先判断该格子是否为空,空则显示当前物品,不为空则遍历下一个格子 UISprite sprite = null; sprite = equipInventoryItems.transform.Find("item" + equipCount).GetComponent <UISprite>(); inventoryItemProperty = sprite.GetComponent <InventoryItemProperty>(); //给inventoryItemProperty设置物品属性 inventoryItemProperty.SetProperties(itdb); if (sprite != null && sprite.spriteName == defaultItemSprite) { //当前格子为空 sprite.spriteName = itdb.SpriteName; } equipCount++; } else if (itdb.Type == (int)EquipType.MEDICINE) //2.如果是药品 { UISprite sprite = null; sprite = equipInventoryItems.transform.Find("item" + medicineCount).GetComponent <UISprite>(); inventoryItemProperty = sprite.GetComponent <InventoryItemProperty>(); //给inventoryItemProperty设置物品属性 inventoryItemProperty.SetProperties(itdb); if (sprite != null && sprite.spriteName == defaultItemSprite) { //当前格子为空 sprite.spriteName = itdb.SpriteName; } medicineCount++; } else if (itdb.Type == (int)EquipType.MATERIAL) //3.如果是材料 { UISprite sprite = null; sprite = equipInventoryItems.transform.Find("item" + materialCount).GetComponent <UISprite>(); inventoryItemProperty = sprite.GetComponent <InventoryItemProperty>(); //给inventoryItemProperty设置物品属性 inventoryItemProperty.SetProperties(itdb); if (sprite != null && sprite.spriteName == defaultItemSprite) { //当前格子为空 sprite.spriteName = itdb.SpriteName; } materialCount++; } else //4.其他类型的物品 { } } } } }