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. VSCode插件开发

    VSCode插件开发全攻略(十)打包.发布.升级 发布方式 插件开发完了,如何发布出去分享给他人呢?主要有3种方法: 方法一:直接把文件夹发给别人,让别人找到vscode的插件存放目录并放进去,然后重 ...

  2. C#连接数据库以及增、删、改、查操作

    using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; usin ...

  3. fpga配置过程(转载)

    fpga 配置时序图如下 1.FPGA器件有三类配置下载方式:主动配置方式(AS)和被动配置方式(PS)和最常用的(JTAG)配置方式.             AS 由FPGA器件引导配置操作过程, ...

  4. div,css常用技术

    1,<div></div>一张图作为背景的用法: 必须指定width,height,background属性 .smallCircle{ margin-top: 25px;   ...

  5. GNU Radio: 自定义 block 实例

    综述 本文通过在GNU Radio 中编写一个block的例子,系统介绍创建一个block的过程.该 block 的功能是可以在GRC中通过滑块(WX GUI Slider)来实时改变信号源(Sign ...

  6. 数组游标实现对数组的各种操作(PHP学习)

    如何不用foreach实现对数组实现循环? 答:我们只需要模拟foreach就行了,数组在执行foreach循环的时候,是有一个游标指向当前数组循环到的值, 那如果我们能拿到这个游标,并且操作游标,使 ...

  7. ubuntu 进入单用户模式

    进入单用户模式:  按shift进入 1.开机到grub时,用上下键移到第二行的恢复模式,按e(注意不是回车) 即Ubuntu,With Linux 3.2.0-23-generic(recovery ...

  8. 深入理解jQuery框架-框架结构

    这是本人结合资料视频总结出来的jQuery大体框架结构,如果大家都熟悉了之后,相信你们也会写出看似高档的js框架: jquery框架的总体结构 (function(w, undefined){ //定 ...

  9. postman 查看请求,已各种语言方式展示:

    查看请求,已各种语言方式展示:

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

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