当前位置: 首页 > news >正文

洛阳网站开发学做彩票网站

洛阳网站开发,学做彩票网站,app制作团队,手机设计房子的软件3d下载Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考 此代码仅为较上一P有所改变的代码 【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili UI_itemSlot.cs using System.Collections; using System.Collections.Gen…

 Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考
此代码仅为较上一P有所改变的代码

【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili

UI_itemSlot.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;public class UI_itemSlot : MonoBehaviour
{[SerializeField] private Image itemImage;[SerializeField] private TextMeshProUGUI itemText;public InventoryItem item;public void UpdateSlots(InventoryItem _newItem){item = _newItem;itemImage.color = Color.white;if (item != null){itemImage.sprite = item.data.icon;if (item.stackSize > 1){itemText.text = item.stackSize.ToString();}else{itemText.text = "";}}}}
Inventory.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Inventory : MonoBehaviour
{public static Inventory instance;public List<InventoryItem> inventoryItems;//inventoryItems类型的列表public Dictionary<ItemData, InventoryItem> inventoryDictianory;//以ItemData为Key寻找InventoryItem的字典[Header("Inventory UI")][SerializeField] private Transform inventorySlotParent;private UI_itemSlot[] itemSlot;//UI Slot的数组private void Awake(){if (instance == null)instance = this;elseDestroy(gameObject);//防止多次创建Inventory}public void Start(){inventoryItems = new List<InventoryItem>();inventoryDictianory = new Dictionary<ItemData, InventoryItem>();itemSlot = inventorySlotParent.GetComponentsInChildren<UI_itemSlot>();//拿到的方式有点绕,显示拿到Canvas 里的 Inventory 然后通过GetComponentsInChildren拿到其下的使用UISlot}private void UpdateSlotUI(){for(int i = 0;i < inventoryItems.Count;i++ ){itemSlot[i].UpdateSlots(inventoryItems[i]);}}public void AddItem(ItemData _item)//将物体存入Inventory的函数{if(inventoryDictianory.TryGetValue(_item,out InventoryItem value)){value.AddStack();}//字典的使用,通过ItemData类型的数据找到InventoryItem里的与之对应的同样类型的数据else//初始时由于没有相同类型的物体,故调用else是为了初始化库存,使其中含有一个基本的值{InventoryItem newItem = new InventoryItem(_item);inventoryItems.Add(newItem);//填进列表里只有一次inventoryDictianory.Add(_item, newItem);//同上}UpdateSlotUI();}public void RemoveItem(ItemData _item)//将物体剔除Inventory的函数{if(inventoryDictianory.TryGetValue(_item,out InventoryItem value)){if (value.stackSize <= 1){inventoryItems.Remove(value);inventoryDictianory.Remove(_item);}elsevalue.RemoveStack();}UpdateSlotUI();}}
ItemObject.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ItemObject : MonoBehaviour
{private SpriteRenderer sr;[SerializeField] private ItemData ItemData;private void OnValidate()//https://blog.csdn.net/paserity/article/details/130014259//大抵就是在Unity加载脚本或检查器中的值更改时调用。实时更新资产文件,比如材质、shader{GetComponent<SpriteRenderer>().sprite = ItemData.icon;gameObject.name = ItemData.name;}//private void Start()//{//    sr = GetComponent<SpriteRenderer>();//    sr.sprite = ItemData.icon;//}private void OnTriggerEnter2D(Collider2D collision){if(collision.GetComponent<Player>()!= null){Inventory.instance.AddItem(ItemData);Destroy(gameObject);}}}

http://www.hyszgw.com/news/72412.html

相关文章:

  • 专业的手机网站建设公司请人制作一个app多少钱
  • 网站免费正能量直接进入检察官网站的架设
  • 宜兴公司做网站网站营销方案模板
  • 怎么自己做企业网站wordpress 汉化 主题
  • 企业网站的新闻资讯版块有哪些体验营销策划方案
  • 云南网站开发培训机构排行免费wordpress 主题
  • 旅游网站技术方案中国做网站知名的公司
  • 防火门 东莞网站建设校园门户网站解决方案
  • 几百块钱可以做网站吗施工企业合规风险识别与管理
  • 北海 做网站 英文小刘网站建设
  • 国内跨境电商建站系统wordpress菜单页面定位
  • 全屏 单页网站平台交易网
  • 酷站网站网页设计创建网站的基本流程
  • 防水网站的外链如何找制作网站专业公司哪家好
  • 专门做设计的网站有哪些seo优化培训机构
  • 凡科建站怎么用wordpress cosy
  • 杭州网站建设 博采网络有限公司windows优化大师可以卸载吗
  • 重庆网站推广建网站需要多少费用
  • 文化公司网站源码wordpress SORA 主题
  • 电商 网站模板网站建设服务费一年多少钱
  • 国际网站怎么做优化wordpress 4.5.2 漏洞
  • 网站开发技术人员怎么接单秦皇岛网站建设哪里有
  • 自己做手机版网站制作康巴什网站建设
  • 百度网站链接提交页面家电维修做网站生意怎么样
  • 网站运营维护中需要用到什么服务器企业网站优化服务主要围绕什么
  • 网站代理制作企业网址怎么制作
  • 枣庄学习建设网站培训网络专题的设计策划方案
  • 网站上做旅游卖家要学什么软件wordpress摘要seo
  • 网站管理怎么做造价员可以做兼职的网站
  • 龙岗公司网站龙岗商城网站建设哪家便宜