UGUI--背包系统之四--------Item
来源:互联网 发布:知乎的运营模式 编辑:程序博客网 时间:2024/05/19 13:58
using UnityEngine;using System.Collections;using UnityEngine.UI;public class Item : MonoBehaviour{ public ItemBase itemBase { get; set; } public int Amount { get; set; } private Image image; private Image Image { get { if (image == null) { image = GetComponent<Image>(); } return image; } } private Text text; private Text Text { get { if (text == null) { text = GetComponentInChildren<Text>(); } return text; } } private float smoothing = 5; private float targetScale = 1; private Vector3 AnimScale = new Vector3(1.3f, 1.3f, 1.3f); void Update() { if (transform.localScale.x != targetScale) { float scale = Mathf.Lerp(transform.localScale.x, targetScale, smoothing * Time.deltaTime); transform.localScale = new Vector3(scale, scale, scale); } } public void SetIcon(ItemBase itemBase, int amount = 1) { transform.localScale = AnimScale; this.itemBase = itemBase; this.Amount = amount; //更新UI Image.sprite = Resources.Load<Sprite>("Items/" + itemBase.Icon); if (Amount > 1) Text.text = Amount.ToString(); else Text.text = ""; } #region 控制物品数量的方法 public void AddAmount(int amount = 1) { transform.localScale = AnimScale; this.Amount += amount; Text.text = Amount.ToString(); } public void ReduceAmount(int amount = 1) { transform.localScale = AnimScale; this.Amount -= amount; if (Amount > 1) Text.text = Amount.ToString(); else Text.text = ""; } public void SetAmount(int amount) { transform.localScale = AnimScale; this.Amount = amount; if (Amount > 1) Text.text = Amount.ToString(); else Text.text = ""; } #endregion #region 给pickItem用方法 public void Show() { gameObject.SetActive(true); } public void Hide() { gameObject.SetActive(false); } public void SetLocalPostion(Vector3 pos) { transform.localPosition = pos; } #endregion}
0 0
- UGUI--背包系统之四--------Item
- UGUI--背包系统之二--------Inventory
- UGUI--背包系统之三--------Slot
- UGUI--背包系统之五--------Tootip
- 基于Unity3D(UGUI)的背包系统<四>完结篇
- UGUI--背包系统
- 【UGUI】背包系统
- UGUI背包系统(初级)
- UGUI--背包系统之一-------InventoryManager
- UGUI背包系统(中)
- UGUI背包系统(下)
- Unity3D自学笔记——UGUI背包系统(四)角色物品数据建立
- UGUI的背包系统(上)
- Unity3D——UGUI实现背包系统
- UGUI(四)事件系统的封装
- UGUI(四)事件系统的封装
- UGUI背包实现详解之二——UGUI组件如何搭配使用做出背包
- 【Unity】基于MVC模式的背包系统 UGUI实现
- java基础总结
- c++ 天气预报源代码
- Android基础——框架模式MVP在安卓中的实践
- 解决通过NuGet更新第三方包时提示不兼容的问题
- Leetcode 57 Insert Interval
- UGUI--背包系统之四--------Item
- Spring Boot 入门
- 在Android Studio里使用lambda表达式
- 拷贝文件夹到手机内存或者手机内存卡
- UGUI--背包系统之五--------Tootip
- 自定义的类后台数据data file的流程
- SQLServer:带条件的插入语句
- 第八周OJ项目-求值
- unity接入unity Ads详细流程