Unity之黑暗之光按教程学习第十二天

           今天我们来完成商人武器系统,这个和前面的商店药品系统比较相像,很多NGUI和脚本非常相像。


public class ShopWeapon : MonoBehaviour {

		public static ShopWeapon _instance;
		private TweenPosition tween;

		public int [] WeaponIdArray;
		public UIGrid grid;
		public GameObject WeaponItem;

		private bool isShow = false;

		private GameObject numberDialog;
		private UIInput numberInput;

		private int buyId;

		
		private void Awake ()
		{
				_instance = this;
				tween = this.GetComponent<TweenPosition> ();
				numberDialog = transform.Find ("Panel/NumberDialog").gameObject;
				numberInput = transform.Find ("Panel/NumberDialog/NumberInput").GetComponent<UIInput> ();
				numberDialog.SetActive (false);

		}

		[System.Obsolete]
		private void Start ()
		{
				InitWeaponShop ();
		}

		public void TransformStatus ()
		{
				if (isShow) {
						tween.PlayReverse (); isShow = false;
				} else {
						tween.PlayForward (); isShow = true;
				}
		}


		public void OnCloseButtonClick ()
		{
				TransformStatus ();
		}

		[System.Obsolete]
		void InitWeaponShop ()
		{//初始化武器商店信息
				foreach (int id in WeaponIdArray) {
						GameObject ItemGo = NGUITools.AddChild (grid.gameObject, WeaponItem);
						grid.AddChild (ItemGo.transform);
						ItemGo.GetComponent<WeaponItem> ().SetId (id);

				}
		}


		public void OnOkButtonClick ()
		{
				int count = int.Parse (numberInput.value);
				if(count > 0) {
						int price = ObjectsInfo._instance.GetObjectInfoById (buyId).price_buy;
						int total_price = price * count;
						bool success = Inventory._instance.GetCoin (total_price);
						if (success) {
								Inventory._instance.GetId (buyId, count);

						}
				}

				buyId = 0;
				numberInput.value = "0";
				numberDialog.SetActive (false);

		}

		public void OnBuyClick (int id)
		{
				buyId = id;
				numberDialog.SetActive (true);
				numberInput.value = "0";

		}

		public void OnClick ()
		{
				numberDialog.SetActive (false);

		}

}

public class WeaponItem : MonoBehaviour {

		private int id;
		private ObjectInfo info;

		private UISprite icon_sprite;
		private UILabel name_Label;
		private UILabel effect_Label;
		private UILabel Pricesell_Label;

		private void Awake ()
		{
				icon_sprite = transform.Find ("icon").GetComponent<UISprite> ();
				name_Label = transform.Find ("name").GetComponent<UILabel> ();
				effect_Label = transform.Find ("effect").GetComponent<UILabel> ();
				Pricesell_Label = transform.Find ("price_sell").GetComponent<UILabel> ();
		}
		//通过调用这个方法更新装备显示
		public void SetId (int id)
		{
				this.id = id;
				info = ObjectsInfo._instance.GetObjectInfoById (id);

				icon_sprite.spriteName = info.icon_name;
				name_Label.text = info.name;
				if(info.Attack > 0) {
						effect_Label.text = "+伤害 " + info.Attack;
				}else if(info.Def > 0) {
						effect_Label.text = "+防御 " + info.Def;
				} else if(info.Speed > 0){
						effect_Label.text = "+速度 " + info.Speed;
				}

				Pricesell_Label.text = info.price_sell.ToString ();
		}


		public void OnBuyButtonClick ()
		{
				ShopWeapon._instance.OnBuyClick (id);
		}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李曼竹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值