黑暗之光 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 个炸弹,有些炸弹牵了一根单向引线(也就是说引线只有在这一端能被炸弹点燃),只要引爆了这个炸弹,用引线连接的下一个炸弹也会爆炸.每个炸弹还有个得分,当这个炸弹被引爆后就能得 ...
随机推荐
- selenium数据驱动
Selenium最后一个知识点——数据驱动.学会了这个Selenium就算学完啦~ 看代码: 这是修改的testSell.py文件. # coding: utf-8 import ddtimport ...
- PHP的网站主要攻击方式有哪些
1.命令注入(Command Injection) 2.eval注入(Eval Injection) 3.客户端脚本攻击(Script Insertion) 4.跨网站脚本攻击(Cross Site ...
- Oracle数据库安装图文操作步骤1
Oracle数据库安装图文操作步骤 一.Oracle 下载 注意Oracle分成两个文件,下载完后,将两个文件解压到同一目录下即可. 路径名称中,最好不要出现中文,也不要出现空格等不规则字符. 官 ...
- npm dose not support Node.js v10.15.3
事件起因: 楼主在vue-cli官网,尝试使用vue-cli3脚手架+yarn包管理器构建项目时,命令行窗口提示node版本不对.如下图 这个大家都知道该如何去解决,直接去node官网下载符合版本的n ...
- RESTful的一个样例
后台代码: @RequestMapping(value = { "queues" }) @ResponseBody public List<ResourcePool> ...
- qt 把整形数据转换成固定长度字符串(转)
QString ToStr(int number, int size){ return QString("%1").arg(number, size, 10, QChar('0') ...
- Opencv2.3.1移植到am335x-y
1.(更新2017/3/4)编译libpng库,原来一直出错(configure --prefix --host --enable-shared -- enable-static ,在修改make ...
- RK3288 修改设备默认的蓝牙名称
path:device/rockchip/rk3288/bluetooth/bdroid_buildcfg.h /* * Copyright (C) 2012 The Android Open Sou ...
- Android 操作文件系统失败: Read-only file system
现象: $ adb push /d/Aaron/Desktop/libreference-ril-LS.so system/lib failed to copy 'D:/Aaron/Desktop/l ...
- SharePoint2013 Online中InfoPath 无法调用WebService
传说微软office365中国区服务器已经迁移到国内,试了下速度果然比之前快了很多,不过随后测试了个简单的功能,还是直接被打击了. 准备在online版本中做一个简单的报销流程测试测试,于是先用Inf ...