UNITY->(width*height)style Inventory 雨点打透心脏的1/2处 2023-06-26 12:19 37阅读 0赞 项目过后对项目功能进行记录,(width\*height)风格背包实现细节,包含对物体的存放,装备,替换,对未知装备的鉴定,物体前缀的获取,项目类型为tcg+rpg,背包的作用主要为游戏中的物品的获取存放,卡牌的获取管理,对可叠加物品的存放,(width\*height)的目的为对物品的存放管理,其效果如下![www.wityx.com][] 1. 基础物品 (width\*height) 物品的创建通过ScriptObject进行创建,根据物品类型设计相关的尺寸(width\*height),利用deepcopy创建实体存放如背包,项目的物品管理通过一个独立的类 ItemDatabase进行管理,在玩家获取一个新物品(未鉴定),通过一个随机生成类来产生词缀和属性 本项目物品的生成通过deepcopy生成物品并添加进itemdatabse,Itemdatabase的作用对游戏物品资产的管理以及生成,有利于未知装备的生成,在对商品商管理上,添加未知随机的装备可以为游戏的物品提高游戏性 public static ItemClass DeepCopy(ItemClass obj) { GameObject oj = obj.worldObject; //ItemClass is item base class ItemClass i = (ItemClass)Process(obj); i.worldObject = oj; return i; } static object Process(object obj) { if(obj==null) return null; Type type=obj.GetType(); if(type.IsValueType || type==typeof(string)) { return obj; } else if(type.IsArray) { Type elementType=Type.GetType( type.FullName.Replace("[]",string.Empty)); var array=obj as Array; Array copied=Array.CreateInstance(elementType,array.Length); for(int i=0; i<array.Length; i++) { copied.SetValue(Process(array.GetValue(i)),i); } return Convert.ChangeType(copied,obj.GetType()); } else if(type.IsClass) { object toret=Activator.CreateInstance(obj.GetType()); FieldInfo[] fields=type.GetFields(BindingFlags.Public| BindingFlags.NonPublic|BindingFlags.Instance); foreach(FieldInfo field in fields) { object fieldValue=field.GetValue(obj); if(fieldValue==null) continue; field.SetValue(toret, Process(fieldValue)); } return toret; } else throw new ArgumentException("Unknown type"); } 2.生成slot并将物品存放进slot(width\*height) 在物品添加进背包时,根据几个条件进行判断 1.slot是否能填充进去 在物品添加进背包栏,需要检测物品尺寸是否越过背包限制并物品之间是否存在重叠,重叠状态一般在物品编辑器中设置(通常为药水...),当不可叠加物品存在重叠状态中,获取状态颜色并提示状态 //检测边界以及叠加状态 public bool CheckItemFit(ItemClass item, InventorySlot slot, bool skipLastCheck) { //Run through all the slots that the item occupies for(int i = 0; i < item.height; i++) { for(int j = 0; j < item.width; j++) { //Check if the slot exists if(slot.itemStartNumber + inventoryWidth * i + j >= items.Count) { return false; } //Check to see if the first slot is located at the edge of the inventory for(int k = 0; k < item.height; k++) { if(slot.itemStartNumber + inventoryWidth * k + j != slot.itemStartNumber + inventoryWidth * k) { if(((slot.itemStartNumber + inventoryWidth * i + j ) % inventoryWidth == 0) && item.width != 1) { return false; } } } //Last check is only used sometimes //Checks to see if there's already something in the slots if(!skipLastCheck) { if(items[slot.itemStartNumber + inventoryWidth * i + j].itemStartNumber != slot.itemStartNumber + inventoryWidth * i + j) { return false; } } else { List<int> counter = new List<int>(); for(int l = 0; l < item.height; l++) { for(int m = 0; m < item.width; m++) { if((slot.itemStartNumber + inventoryWidth * (item.height - 1) + (item.width - 1)) < items.Count - 1 && items[slot.itemStartNumber + inventoryWidth * l + m].itemStartNumber != slot.itemStartNumber && items[slot.itemStartNumber + inventoryWidth * l + m].item.itemName != "" && !counter.Contains(items[slot.itemStartNumber + inventoryWidth * l + m].itemStartNumber)) { counter.Add(items[slot.itemStartNumber + inventoryWidth * l + m].itemStartNumber); } } } if(counter.Count > 1) { //return false if there's more than one item return false; } else if(counter.Count == 1) { return true; } } } } return true; } 当物品状态为可添加时,添加进slot,根据width\*height尺寸进行添加 for(int l = 0; l < item.height; l++) { for(int m = 0; m < item.width; m++) { //First we add the items to the slots the it fills and set their slots to clear items[i + inventoryWidth * l + m].item = DeepCopy(item); items[i + inventoryWidth * l + m].itemStartNumber = i; items[i + inventoryWidth * l + m].GetComponent<Image>().color = Color.clear; items[i + inventoryWidth * l + m].stacksizeText.gameObject.SetActive(false); //If it's the first index of the added item if(items.IndexOf(items[i + inventoryWidth * l + m]) == i) { SetSlotImageSprite(items[i + inventoryWidth * l + m], item.icon); items[i + inventoryWidth * l + m].itemFrame.gameObject.SetActive(true); items[i + inventoryWidth * l + m].itemFrame.GetComponent<CanvasGroup>().interactable = true; items[i + inventoryWidth * l + m].itemFrame.GetComponent<CanvasGroup>().blocksRaycasts = true; items[i + inventoryWidth * l + m].GetComponent<CanvasGroup>().blocksRaycasts = true; items[i + inventoryWidth * l + m].itemFrame.rectTransform.sizeDelta = new Vector2(item.width * slotIconSize, item.height * slotIconSize); //If the item is stackable if(item.stackable) { items[i + inventoryWidth * l + m].stacksizeText.gameObject.SetActive(true); items[i + inventoryWidth * l + m].stacksizeText.text = item.stackSize.ToString(); } //The item is unidentified if(item.unidentified) { items[i + inventoryWidth * l + m].itemImage.color = Color.red; items[i + inventoryWidth * l + m].unidentified.gameObject.SetActive(true); } } } } 2.物品是否存在物品 当物品存在物品时,需要对存在物品的占用尺寸进行判断(int slot=indexof(item)),当slot存在物品时,遍历slot.count 获取空栏位并存放,另外一种情况是当玩家处于dragging状态时,可以对物品进行替换,存放在物品的方式一般为 Items[slot.itemStartNumber + inventoryWidth * l + m].item.variables [www.wityx.com]: https://img2018.cnblogs.com/blog/1020915/202001/1020915-20200101113800971-220331356.png
相关 Ansible — Inventory 清单文件 目录 文章目录 目录 Inventory 清单文件 Groups 与 Hosts 对象 嵌套 Groups Hostna Dear 丶/ 2023年10月03日 07:47/ 0 赞/ 94 阅读
相关 Ansible(十五)-- ansible 中的变量(四) 内置变量 ansible_version hostvars inventory_hostname 等 ansible 中的内置变量 一、内置变量ansible\_version 二、内置变量hostvars 三、内置变量inventory\_hostna 梦里梦外;/ 2023年07月18日 14:28/ 0 赞/ 100 阅读
相关 UNITY->(width*height)style Inventory 项目过后对项目功能进行记录,(width\height)风格背包实现细节,包含对物体的存放,装备,替换,对未知装备的鉴定,物体前缀的获取,项目类型为tcg+rpg,背包的作用主 雨点打透心脏的1/2处/ 2023年06月26日 12:19/ 0 赞/ 38 阅读
相关 43 inventory文件 Ansible可同时操作属于一个组的多台主机,是通过inventory文件配置来实现的,组与主机的关系也是由inventory来定义的。默认inventory文件路 ╰半橙微兮°/ 2022年09月14日 09:23/ 0 赞/ 224 阅读
相关 [INS-32035]Unable to create a new central Inventory at the specified location 安装OGG报错 ![在这里插入图片描述][59d07e54d720421e8c7051afa8a536c9.png] [59d07e54d720421e8c7051afa 向右看齐/ 2022年09月10日 13:11/ 0 赞/ 85 阅读
相关 PDQ Inventory 19 Enterprise with crack (Windows) PDQ Inventory(PDQ 清单)19.3.83.0 请访问原文链接:[https://sysin.org/blog/pdq-inventory-19/][https 桃扇骨/ 2022年08月28日 00:52/ 0 赞/ 30 阅读
相关 解决OCS Inventory安装后的警告 OCS Inventory安装完成后,进入界面[http://ip][http_ip]地址/ocsreports/ 或 [http://localhost/ocsreports ╰+哭是因爲堅強的太久メ/ 2022年07月15日 03:18/ 0 赞/ 381 阅读
相关 打补丁报错Opatch error : "Unable to lock Central Inventory Applies to: Oracle Database - Enterprise Edition - Version 9.2.0.1 to 10.2.0.4 \[Relea £神魔★判官ぃ/ 2022年03月07日 11:05/ 0 赞/ 526 阅读
还没有评论,来说两句吧...