黑暗之光 Day2
1. 鼠标点击UI检测
UICamera.isOverUI
2. 鼠标指针管理
public class CussorManager : MonoBehaviour {
public static CussorManager instance; // 单例
public Texture2D cursorAttack; // 存储鼠标贴图
public Texture2D cursorLockTarget;
public Texture2D cursorNormal;
public Texture2D cursorNpcTalk;
public Texture2D cursorPick;
void Start()
{
instance = this;
}
public void SetNormal() // 设置鼠标为正常
{
Cursor.SetCursor(cursorNormal, Vector2.zero, CursorMode.Auto);
}
public void SetNpcTalk() // 设置鼠标为 Npc_talk
{
Cursor.SetCursor(cursorNpcTalk, Vector2.zero, CursorMode.Auto);
}
}
3. 读取物品文件
public TextAsset objectsInfoText;
private Dictionary<int, ObjectInfo> objectsInfoDict = new Dictionary<int, ObjectInfo>(); // 从文件中读取物品信息
void ReadInfo()
{
string text = objectsInfoText.text; // 获取文本内容
string[] objectsArr = text.Split('\n'); // 以换行符分割字符
for (int i = ; i < objectsArr.Length; ++i) // 遍历每一行
{
string[] proArr = objectsArr[i].Split(','); // 以逗号分割属性
ObjectInfo info = new ObjectInfo(); // 物品属性
info.id = int.Parse(proArr[]);
info.name = proArr[];
info.iconName = proArr[];
string type = proArr[];
info.type = ObjectType.Material;
switch (type)
{
case "Drug":
info.type = ObjectType.Drug;
break;
case "Equip":
info.type = ObjectType.Equipment;
break;
case "Mat":
info.type = ObjectType.Material;
break;
}
if (info.type == ObjectType.Drug) // 物品是药品
{
info.hp = int.Parse(proArr[]);
info.mp = int.Parse(proArr[]);
info.sellPrice = int.Parse(proArr[]);
info.buyPrice = int.Parse(proArr[]);
}
objectsInfoDict.Add(info.id, info); // 加入字典
}
} // 根据 ID 查找物品信息
public ObjectInfo GetObjectInfoById(int id)
{
ObjectInfo info;
objectsInfoDict.TryGetValue(id, out info);
return info;
}
4. 物品拖拽
继承 UIDragDropItem 类。
5. 模拟拾取物品放入背包
// 根据 id 拾取物品
public void GetId(int id)
{
InventoryItemGrid grid = null;
// 查找是否已有该物品
foreach (InventoryItemGrid temp in itemGridList)
{
if (temp.GetId() == id) // 已有
{
grid = temp;
break;
}
}
if (grid != null)
{
grid.PlusNum(); // 该物品数目+1
}
else
{
// 查找是否有空格子
foreach (InventoryItemGrid temp in itemGridList)
{
if (temp.GetId() == ) // 有空格子
{
grid = temp; break;
}
}
if (grid != null) // 往空格子里放物品
{
GameObject itemGo = NGUITools.AddChild(grid.gameObject, inventoryItemPrefab);
itemGo.transform.localPosition = Vector3.zero;
itemGo.GetComponent<UISprite>().depth = ;
grid.SetId(id); // 改变各自装的物品
}
}
}
// 根据 id 更换格子物品
public void SetId(int id, int num = )
{
info = ObjectsInfo.instance.GetObjectInfoById(id); // 根据 id 查找物品
this.id = id;
this.num = num;
InventoryItem item = GetComponentInChildren<InventoryItem>();
item.SetIconName(info.iconName);
numLabel.enabled = true;
numLabel.text = num.ToString();
}
6. 物体拖拽实现
protected override void OnDragDropRelease(GameObject surface)
{
print(this.tag);
base.OnDragDropRelease(surface);
if (surface != null)
{
if (surface.tag == Tags.inventoryItemGrid)
{
if (surface != this.transform.parent.gameObject) // 拖拽到空格子
{
InventoryItemGrid oldGrid = this.transform.parent.GetComponent<InventoryItemGrid>();
InventoryItemGrid newGrid = surface.GetComponent<InventoryItemGrid>();
newGrid.SetId(oldGrid.GetId(), oldGrid.GetNum());
oldGrid.ClearInfo();
}
}
else if (surface.tag == Tags.inventoryItem) // 拖拽到有物体的格子
{
InventoryItemGrid grid1 = this.transform.parent.GetComponent<InventoryItemGrid>();
InventoryItemGrid grid2 = surface.transform.parent.GetComponent<InventoryItemGrid>();
int id = grid1.GetId();
int num = grid1.GetNum();
grid1.SetId(grid2.GetId(), grid2.GetNum());
grid2.SetId(id, num);
}
} ResetPos();
} void ResetPos()
{
this.transform.localPosition = Vector3.zero;
}
黑暗之光 Day2的更多相关文章
- 【从零开始学BPM,Day2】默认表单开发
[课程主题]主题:5天,一起从零开始学习BPM[课程形式]1.为期5天的短任务学习2.每天观看一个视频,视频学习时间自由安排. [第二天课程] Step 1 软件下载:H3 BPM10.0全开放免费下 ...
- NOIp2016 Day1&Day2 解题报告
Day1 T1 toy 本题考查你会不会编程. //toy //by Cydiater //2016.11.19 #include <iostream> #include <cstd ...
- day2
三级菜单: ))))))))))] last_levels.pop() ]]]]]]]]:] information = : ch = msvcrt.getch() ][][: : password= ...
- java day2一个模拟双色球的代码
package day2; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt ...
- Python基础-day2
1.Python模块python 中导入模块使用import语法格式:import module_name示例1: 导入os模块system('dir')列出当前目录下的所有文件 # _*_ codi ...
- 【BZOJ 4517】【SDOI 2016 Round1 Day2 T2】排列计数
本蒟蒻第一次没看题解A的题竟然是省选$Round1$ $Day2$ $T2$ 这道组合数学题. 考试时一开始以为是莫队,后来想到自己不会组合数的一些公式,便弃疗了去做第三题,,, 做完第三题后再回来看 ...
- 冲刺阶段 day2
day2 项目进展 今天本组五位同学聚在一起将项目启动,首先我们对项目进行了规划,分工,明确指出每个人负责哪些项目.由负责第一部分的组员开始编程,在已经搭建好的窗体内,对系部设置进行了编写,本校共六个 ...
- python_way ,day2 字符串,列表,字典,时间模块
python_way ,day2 字符串,列表,字典,自学时间模块 1.input: 2.0 3.0 区别 2.0中 如果要要用户交互输入字符串: name=raw_input() 如果 name=i ...
- 二模 (8) day2
第一题: 题目描述: 有 n 个炸弹,有些炸弹牵了一根单向引线(也就是说引线只有在这一端能被炸弹点燃),只要引爆了这个炸弹,用引线连接的下一个炸弹也会爆炸.每个炸弹还有个得分,当这个炸弹被引爆后就能得 ...
随机推荐
- linux下vi命令(转)
进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi +n filename :打开文件,并将光标置于第n行首 vi + filename :打开文件,并将光标置于最后 ...
- WPF 同一窗口内的多线程 UI(VisualTarget)
WPF 的 UI 逻辑只在同一个线程中,这是学习 WPF 开发中大家几乎都会学习到的经验.如果希望做不同线程的 UI,大家也会想到使用另一个窗口来实现,让每个窗口拥有自己的 UI 线程.然而,就不能让 ...
- 进阶的Redis之数据持久化RDB与AOF
大家都知道,Redis之所以性能好,读写快,是因为Redis是一个内存数据库,它的操作都几乎基于内存.但是内存型数据库有一个很大的弊端,就是当数据库进程崩溃或系统重启的时候,如果内存数据不保存的话,里 ...
- mongooseim xmpp 服务器docker 安装试用
备注: 预备环境docker xmpp client 1. 启动mongooseim docker run -d -t -h mongooseim-1 --name mongooseim- ...
- 10.Python运行Scrapy时出现错误: ModuleNotFoundError: No module named 'win32api'
1.在命令行输入:scrapy crawl demo(demo为爬虫标识,是唯一的) 2.报错信息如下所示: 3.解决方法:https://github.com/mhammond/pywin32/re ...
- 5.JMeter测试mysql数据库
1.使用jmeter测试mysql数据库时,需要导入jar包,jar包网盘地址为:链接: https://pan.baidu.com/s/1-5-s7HccudT4GirpmBVn6Q 密码: bea ...
- [Java][Web]Request 获取请求头和数据
获取方式一 InputStream in = request.getInputStream(); int len = 0; byte buffer[] = new byte[1024]; while( ...
- docker 远程rest api 访问配置
Docker RestApi 的配置及使用 Centos Docker1.12 远程Rest api访问的配置方法 http restapiv1.24 docker sdk for python
- Win10怎么以管理员身份运行CMD命令提示符
[方法一] 我们可以在Windows10系统的开始菜单上,单击鼠标右键,这时候出现的菜单中,我们选择命令提示符(管理员)点击打开这样即可. 2 这样打开以后,大家可以看到命令提示符界面中显示管理员:命 ...
- Linux中常用的查找文件的命令
我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索.这些是从网上找到的资料(参考资料1),因为有时很长时间不会用到,当要用的时候经常弄混了,所以放到这里方便使用. w ...