角色换装及属性动态改变
同样利用了Attribute设计,其实角色这里已经很简单了
效果图
白属性
装备剑, 攻击力+10
装备匕首,攻击力+8
装备三级匕首,攻击加24
同样角色属性的改变是通过之前写的PlayerStatus进行赋值
大致示意图
思路
通过装备按钮,更改PlayerStatus的装备属性,并重新计算角色总属性,然后触发PlayerStatus的换装事件,通知角色属性面板刷新。
弹出框修改
同样,界面绑定都从ItemStaus取值,在装备按钮事件中首先改变PlayerStatus的对应属性,这里是Weapon
public class UIItemToolTip : UIScene {
private Image m_Icon;
private Text m_NameText;
private Text m_LvText;
private Text m_TypeText;
private Text m_DescriptionText;
private Text m_AttributeText;
private Text m_BtnDressOnText;
private Text m_BtnDropText;
private Text m_RedPriceText;
private Text m_BluePriceText;
private UISceneWidget m_BtnClose;
private UISceneWidget m_BtnDressOn;
private UISceneWidget m_BtnDrop;
private ItemStatus m_ItemStatus;
private PlayerStatus m_PlayerStatus;
void Awake()
{
this.m_Icon = UIHelper.FindChild<Image>(transform, "imgIcon/Image");
this.m_NameText = UIHelper.FindChild<Text>(transform, "txtName");
this.m_LvText = UIHelper.FindChild<Text>(transform, "txtLv");
this.m_TypeText = UIHelper.FindChild<Text>(transform, "txtType");
this.m_DescriptionText = UIHelper.FindChild<Text>(transform, "txtDescription");
this.m_AttributeText = UIHelper.FindChild<Text>(transform, "imgAttribute/txtAttribute");
this.m_BtnDressOnText = UIHelper.FindChild<Text>(transform, "btnDressOn/Text");
this.m_BtnDropText = UIHelper.FindChild<Text>(transform, "btnDrop/Text");
this.m_BluePriceText = UIHelper.FindChild<Text>(transform, "txtBluePrice");
this.m_RedPriceText = UIHelper.FindChild<Text>(transform, "txtRedPrice");
GameObject player = GameObject.FindGameObjectWithTag("Player");
this.m_PlayerStatus = player.GetComponent<PlayerStatus>();
}
protected override void Start()
{
base.Start();
m_BtnClose = this.GetWidget("btnClose");
if(m_BtnClose != null)
m_BtnClose.PointerClick += BtnClosePointerClick;
m_BtnDressOn = this.GetWidget("btnDressOn");
if(m_BtnDressOn != null)
m_BtnDressOn.PointerClick += BtnDressOnPointerClick;
m_BtnDrop = this.GetWidget("btnDrop");
if(m_BtnDrop != null)
m_BtnDrop.PointerClick += BtnDropPointerClick;
}
public void Show(ItemStatus itemStatus, bool isLeft)
{
this.SetVisible(true);
this.m_ItemStatus = itemStatus;
this.m_Icon.overrideSprite = Resources.Load<Sprite>(m_ItemStatus.IconPath);
this.m_NameText.text = m_ItemStatus.ItemName;
this.m_DescriptionText.text = m_ItemStatus.Description;
this.m_LvText.text = string.Format("等级: {0}", m_ItemStatus.Lv);
this.m_TypeText.text = m_ItemStatus.ItemTypeString;
this<