实现的功能:鼠标中键点击,随机获取装备名称,鼠标移到装备上,自动弹出装备的详细信息,移开自动消失,并且实现了拖拽功能(拖到区域外,默认删除,拖到有装备的默认交换)
首先第一步是 创建数据类,装备分类,有些属性是共有的,所以创建一个子类,然后不同的装备分别继承它
子类代码如下
using UnityEngine;
using System.Collections;
//共有的数据类
public class Item {
public int ID{ get; private set;}
public string Name{ get; private set;}
public string Description{ get; private set;}
public int BUYPrice{ get; private set;}
public int SELLPrice{ get; private set;}
public string Icon{ get; private set;}
public string ItemType{ get; protected set;}//道具分类用字符串或者枚举都可以,protected保证子类可以设置它
public Item(int id,string name,string description,int buyprice,int sellprice,string icon){
this.ID = id;
this.Name = name;
this.Description = description;
this.BUYPrice = buyprice;
this.SELLPrice = sellprice;
this.Icon = icon;
}
}
这里我分成了三类装备:武器,血瓶,防具
using UnityEngine;
using System.Collections;
public class Weapon : Item {
public int gongjili{ get; private set;}
public Weapon(int id,string name,string description,int buyprice,int sell