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的更多相关文章

  1. 【从零开始学BPM,Day2】默认表单开发

    [课程主题]主题:5天,一起从零开始学习BPM[课程形式]1.为期5天的短任务学习2.每天观看一个视频,视频学习时间自由安排. [第二天课程] Step 1 软件下载:H3 BPM10.0全开放免费下 ...

  2. NOIp2016 Day1&Day2 解题报告

    Day1 T1 toy 本题考查你会不会编程. //toy //by Cydiater //2016.11.19 #include <iostream> #include <cstd ...

  3. day2

    三级菜单: ))))))))))] last_levels.pop() ]]]]]]]]:] information = : ch = msvcrt.getch() ][][: : password= ...

  4. java day2一个模拟双色球的代码

    package day2; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt ...

  5. Python基础-day2

    1.Python模块python 中导入模块使用import语法格式:import module_name示例1: 导入os模块system('dir')列出当前目录下的所有文件 # _*_ codi ...

  6. 【BZOJ 4517】【SDOI 2016 Round1 Day2 T2】排列计数

    本蒟蒻第一次没看题解A的题竟然是省选$Round1$ $Day2$ $T2$ 这道组合数学题. 考试时一开始以为是莫队,后来想到自己不会组合数的一些公式,便弃疗了去做第三题,,, 做完第三题后再回来看 ...

  7. 冲刺阶段 day2

    day2 项目进展 今天本组五位同学聚在一起将项目启动,首先我们对项目进行了规划,分工,明确指出每个人负责哪些项目.由负责第一部分的组员开始编程,在已经搭建好的窗体内,对系部设置进行了编写,本校共六个 ...

  8. python_way ,day2 字符串,列表,字典,时间模块

    python_way ,day2 字符串,列表,字典,自学时间模块 1.input: 2.0 3.0 区别 2.0中 如果要要用户交互输入字符串: name=raw_input() 如果 name=i ...

  9. 二模 (8) day2

    第一题: 题目描述: 有 n 个炸弹,有些炸弹牵了一根单向引线(也就是说引线只有在这一端能被炸弹点燃),只要引爆了这个炸弹,用引线连接的下一个炸弹也会爆炸.每个炸弹还有个得分,当这个炸弹被引爆后就能得 ...

随机推荐

  1. BZOJ1087 SCOI2005 互不侵犯King 【状压DP】

    BZOJ1087 SCOI2005 互不侵犯King Description 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附 ...

  2. 《DSP using MATLAB》示例Example7.24

    代码: ws1 = 0.2*pi; wp1 = 0.35*pi; wp2 = 0.65*pi; ws2 = 0.8*pi; Rp = 1.0; As = 60; [delta1, delta2] = ...

  3. 日志框架--(二)JDK Logging

    前言 从jdk1.4起,JDK开始自带一套日志系统.JDK Logger最大的优点就是不需要任何类库的支持,只要有Java的运行环境就可以使用.相对于其他的日志框架,JDK自带的日志可谓是鸡肋,无论易 ...

  4. python 读取 xlsx

    >>> xl = pd.ExcelFile("dummydata.xlsx") >>> xl.sheet_names [u'Sheet1', u ...

  5. 网站SEO知识

    http://seo.chinaz.com/ 这是综合查询的 site:www.hr246.com 可以查看百度收录的情况 参照贪玩游戏来搞 http://www.tanwan.com http:// ...

  6. ecmall 挂件开发实例一

     (参考网上相关文章,进行测试点评,下述方法测试成功) 1:在页面上添加要展示的页面模块 <div class="left" area="bottom_foot&q ...

  7. Hadoop的简单序列化框架

    Hadoop提供了一个加单的序列化框架API,用于集成各种序列化实现.该框架由Serialization实现. 其中Serialization是一个接口,使用抽象工厂的设计模式,提供了一系列和序列化相 ...

  8. 保证service不被杀死的方法

    Service设置成START_STICKY kill 后会被重启(等待5秒左右),重传Intent,保持与重启前一样 提升service优先级 在AndroidManifest.xml文件中对于in ...

  9. JDK 9 & JDK 10 新特性

    JDK 9 新增了不少特性,官方文档:https://docs.oracle.com/javase/9/whatsnew/toc.htm#JSNEW-GUID-527735CF-44E1-4144-9 ...

  10. java web 程序---登陆验证4个页面

    思路: 1.第一个是登陆页面login.jsp一个form表单.点击登陆按钮 2.第二个是验证页面check.jsp.如果username和password都正确.则跳转到另一个页面a.jsp显示登陆 ...