wordpress 架站,wordpress 客户端源码,手机网站一键分享到微信,中企动力做网站我们打开上一篇62QFrameWork背包框架的项目#xff0c; 上文将功能实现在一个脚本中 本章要做的事情让脚本实现背包框架思想 首先按照图示创建脚本#xff1a; 创建脚本#xff1a;Item.cs namespace QFramework {public class Item{//道具public string Key;public string …我们打开上一篇62QFrameWork背包框架的项目 上文将功能实现在一个脚本中 本章要做的事情让脚本实现背包框架思想 首先按照图示创建脚本 创建脚本Item.cs namespace QFramework {public class Item{//道具public string Key;public string Name;public Item(string key, string name){Key key;Name name;}}
}
创建脚本Slot.cs namespace QFramework {//插槽格子Slotpublic class Slot{public Item Item;public int Count;public Slot(Item item, int count){Item item;Count count;}}
}
创建脚本QFramework.cs using System.Collections.Generic;
namespace QFramework {public class ItemKit{//数据public static Item Item1 new(item_1, 物品1);public static Item Item2 new(item_2, 物品2);public static Item Item3 new(item_3, 物品3);public static Item Item4 new(item_4, 物品4);public static Item Item5 new(item_5, 物品5);//插槽格子Slot列表public static ListSlot Slots new ListSlot() {new Slot(Item1,1),new Slot(Item2,10),new Slot(Item3,1),new Slot(Item4,1),};//根据Key获取Itempublic static Dictionarystring, Item ItemByKey new Dictionarystring, Item() {{ Item1.Key,Item1 },{ Item2.Key,Item2 },{ Item3.Key,Item3 },{ Item4.Key,Item4 },{ Item5.Key,Item5 },};//获取道具方法//Slot FindSlotByKey(string itemKey) {// return mSlots.Find(s s.Item ! null s.Item.Key itemKey s.Count ! 0);//}//获取道具方法public static Slot FindSlotByKey(string itemKey) ItemKit.Slots.Find(s s.Item ! null s.Item.Key itemKey s.Count ! 0);//获取空格子方法public static Slot FindEmptySlot() ItemKit.Slots.Find(s s.Count 0);//可以增加格子方法public static Slot FindAddableSlot(string itemKey){var slot FindSlotByKey(itemKey);if (slot null){slot FindEmptySlot();if (slot ! null)slot.Item ItemKit.ItemByKey[itemKey];}return slot;}//增加道具方法public static bool AddItem(string itemKey, int addCount 1){var slot FindAddableSlot(itemKey);if (slot null)return false;elseslot.Count addCount;return true;}//减少道具方法public static bool SubItem(string itemKey, int subCount 1){var slot FindSlotByKey(itemKey);if (slot ! null){slot.Count - subCount;return true;}return false;}}
}
修改脚本InventoryExample1.cs using UnityEngine;
namespace QFramework.Example{public partial class InventoryExample1 : ViewController {void OnGUI(){//调用IM帮助类的设置设计分辨率函数IMGUIHelper.SetDesignResolution(640,360);foreach (var slot in ItemKit.Slots) {//创建一个box类型的水平布局图形用户界面GUILayout.BeginHorizontal(box);if (slot.Count 0)GUILayout.Label($格子空);else//在水平布局图形用户界面中添加一个标签GUILayout.Label($格子:{slot.Item.Name} x {slot.Count});//结束水平布局组GUILayout.EndHorizontal();}GUILayout.BeginHorizontal();GUILayout.Label(物品1);//创建一个按钮 - 增加if (GUILayout.Button()){if (!ItemKit.AddItem(item_1))Debug.Log(物品栏已满);}//减少if (GUILayout.Button(-)){ ItemKit.SubItem(item_1); }GUILayout.EndHorizontal();GUILayout.BeginHorizontal();GUILayout.Label(物品2);//创建一个按钮 - 增加if (GUILayout.Button()) {if (!ItemKit.AddItem(item_2))Debug.Log(物品栏已满);}//减少if (GUILayout.Button(-)) { ItemKit.SubItem(item_2); }GUILayout.EndHorizontal();GUILayout.BeginHorizontal();GUILayout.Label(物品3);//创建一个按钮 - 增加if (GUILayout.Button()) {if (!ItemKit.AddItem(item_3))Debug.Log(物品栏已满);}//减少if (GUILayout.Button(-)) { ItemKit.SubItem(item_3); }GUILayout.EndHorizontal();GUILayout.BeginHorizontal();GUILayout.Label(物品4);//创建一个按钮 - 增加if (GUILayout.Button()) {if (!ItemKit.AddItem(item_4))Debug.Log(物品栏已满);}//减少if (GUILayout.Button(-)) { ItemKit.SubItem(item_4); }GUILayout.EndHorizontal();GUILayout.BeginHorizontal();GUILayout.Label(物品5);//创建一个按钮 - 增加if (GUILayout.Button()) {if (!ItemKit.AddItem(item_5))Debug.Log(物品栏已满);}//减少if (GUILayout.Button(-)) { ItemKit.SubItem(item_5); }GUILayout.EndHorizontal();}}
}本章做了让脚本实现背包框架思想
接下来的文章内容
1.QFrameWork道具栏物品生成
2.窗口可拖拽脚本
3.点击名称寻找地点功能
4.隐藏怪物的生成
5.怪物I攻击范围内的主动攻击
6.掉落坐骑蛋的获取
7.异步传送转换场景
以及开放回合制、坐骑系统、宠物系统、背包系统、神炼系统、商城系统、Boss的目标跟随任务导航系统以及UI播放3D动画效果等等。
具体项目运行效果请关注water1024的b站视频项目演示《破碎纪元》 【Unity回合2.5D】破碎纪元_单机游戏热门视频 (bilibili.com)https://www.bilibili.com/video/BV1rZY4e9Ebs/?spm_id_from333.999.0.0vd_source547091a95b03acfa8e8a9e46ef499cd6