黑暗之光 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 个炸弹,有些炸弹牵了一根单向引线(也就是说引线只有在这一端能被炸弹点燃),只要引爆了这个炸弹,用引线连接的下一个炸弹也会爆炸.每个炸弹还有个得分,当这个炸弹被引爆后就能得 ...
随机推荐
- HDU2222 Keywords Search 【AC自动机】
HDU2222 Keywords Search Problem Description In the modern time, Search engine came into the life of ...
- 几种设置UITableView的cell动态高度的方法
1.UITableView加载的顺序是先得到表的行的高度,也就是先调用heightForRowAtIndexPath方法,然后再调用cellForRowAtIndexPath,所以我们有两个办法实现自 ...
- 高度注意 Map 类集合 K/V 能不能存储 null 值的情况
集合类 Key Value Super 说明 Hashtable 不允许为 null 不允许为 null Dictionary 线程安全 ConcurrentHashMap 不允许为 null 不允许 ...
- python环境搭建-Linux系统下python2.7升级python3.5.2步骤
首先Python 查看版本 , 在Linux下特别注意权限问题,创建目录时候切记给予权限 如果是 ubnutu 请使用首先切换到 sudo su , 否则 make install 会出现问题.. 升 ...
- 重温CLR(十) 字符、字符串和文本处理
本章将介绍.net中处理字符和字符串的机制 字符 在.NET Framewole中,字符总是表示成16位Unicode代码值,这简化了国际化应用程序的开发. 每个字符都表示成System.Char结构 ...
- svn 操作命令
1.第一次提交代码到svn svn import project_directory PATH 2.将文件checkout到本地svn checkout path(path是服务器上的目录) 例如:s ...
- LeetCode 760. Find Anagram Mappings
原题链接在这里:https://leetcode.com/problems/find-anagram-mappings/description/ 题目: Given two lists Aand B, ...
- gradle 插件
1. 系统内置插件的应用 a. 二进制 apply plugin :"pluginname" 比如: java b. 脚本插件 apply from : "version ...
- iOS7 自己定义动画跳转
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/Liar0606/article/details/26399125 简单介绍 在iOS7系统中,假设你 ...
- wpf 虚拟化操作异常
根据这篇文章提供的方法会导致搜索变慢及有时候搜索不到 WPF中ItemsControl应用虚拟化时找到子元素的方法, 具体可以修改为下面代码: //Action action = () => / ...