当前位置: 首页 > news >正文

『功能项目』鼠标悬停物品显示信息【77】

本章项目成果展示

我们打开上一篇763D模型动态UI显示的项目,

本章要做的事情是鼠标悬停在道具身上显示对应信息

首先制作一个武器Image信息面板

重命名为WeaponUI01

设为隐藏

修改脚本:RightClickItem.cs

查看挂载脚本:

运行项目 - 当鼠标悬停背包中的装备时

继续制作面板 - 修改增加其他装备

首先增加装备栏里的插槽位置标签

修改脚本:RightClickItem.cs

修改脚本:UGUICanvas.cs

增加装备栏插槽sprite需要加载图片

创建脚本:RightClickShoesBack.cs

using QFramework.Example;
using QFramework;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class RightClickShoesBack : MonoBehaviour, IPointerClickHandler{Image childImage;Sprite ShoesIconNormal;GameManager gm;GameObject currentCanvas;void Start(){gm = GameManager.Instance;ShoesIconNormal = Resources.Load<Sprite>("Prefabs/UGUIIcons/IndigoShieldtIcon_14");currentCanvas = GameObject.Find("CurrentCanvas").gameObject;}public void OnPointerClick(PointerEventData eventData){if (eventData.button == PointerEventData.InputButton.Right){if (transform.GetComponent<Image>().sprite == null)return;Transform Icon = currentCanvas.transform.Find("BagExample/Scroll View/Viewport/SlotItemRoot/UISlot(Clone)/Icon").transform;Icon.gameObject.SetActive(true);childImage = GameObject.FindWithTag("ShoesEquipPos").GetComponent<Image>();GameObject[] uiSlots = GameObject.FindGameObjectsWithTag("UISlot");foreach (GameObject uiSlot in uiSlots){Image imageComponent = uiSlot.GetComponent<Image>();if (imageComponent != null && imageComponent.sprite == null){ItemKit.AddItem(ConfigManager.Default.Diamond.GetKey);bool isSpriteNull = true;uiSlot.SetActive(isSpriteNull);uiSlot.gameObject.GetComponent<Image>().sprite = childImage.sprite;uiSlot.gameObject.GetComponent<Image>().color = Color.white;childImage.sprite = ShoesIconNormal;childImage.GetComponent<RectTransform>().sizeDelta = new Vector2(90, 90);gm.infoSys.defineValue -= 180;gm.infoSys.CombatValue -= (int)(180 * 3);currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().color = Color.red;currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().text = "战斗力下降" + (int)(180 * 3);currentCanvas.transform.Find("EquipInfo").gameObject.SetActive(true);StartCoroutine(WaitForThreeEquipText());FindObjectOfType<BagExample>().Refresh();FindObjectOfType<UGUICanvas>().Refresh();}}}}IEnumerator WaitForThreeEquipText(){yield return new WaitForSeconds(2);currentCanvas.transform.Find("EquipInfo").gameObject.SetActive(false);}
}

绑定脚本

运行项目

修改脚本:RightClickItem.cs

此时当鼠标悬停在装备栏时就会有设置隐藏的装备面板显示,鼠标离开后消失

RightClickItem.cs

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using QFramework.Example;
using QFramework;
public class RightClickItem : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler{Image childImage;GameManager gm;GameObject currentCanvas;GameObject PlayerNormal;GameObject PlayerUI;void Start(){gm = GameManager.Instance;childImage = transform.Find("Icon").GetComponent<Image>();currentCanvas = GameObject.Find("CurrentCanvas").gameObject;PlayerNormal = GameObject.FindWithTag("Player").gameObject;PlayerUI = GameObject.Find("PlayerUI").gameObject;}public void OnPointerClick(PointerEventData eventData){if (eventData.button == PointerEventData.InputButton.Right){#region 装备武器if (transform.Find("Icon").GetComponent<Image>().sprite != null && transform.Find("Icon").GetComponent<Image>().sprite.name == "equip02"){currentCanvas.transform.Find("EquipUIs/WeaponUI01").gameObject.SetActive(false);Transform weaponEquipPos = GameObject.FindGameObjectWithTag("WeaponEquipPos").transform;weaponEquipPos.gameObject.GetComponent<Image>().sprite = transform.Find("Icon").GetComponent<Image>().sprite;weaponEquipPos.gameObject.GetComponent<Image>().color = Color.white;weaponEquipPos.gameObject.transform.Find("Image").gameObject.SetActive(false);var slot = ItemKit.BagSlots.Find(s => s.Item != null && s.Item.GetKey == "Item_ironSword"); if (slot != null){slot.Item = null;slot.Count = 0;}transform.Find("Icon").GetComponent<Image>().sprite = null;transform.Find("Icon").GetComponent<Image>().color = new Color(45f / 255f, 45f / 255f, 45f / 255f);transform.Find("Icon").GetComponent<Image>().GetComponent<RectTransform>().sizeDelta = new Vector2(90, 90);gm.infoSys.attackValue += 500;gm.infoSys.CombatValue += (int)(500 * 1.3f);currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().color = Color.green;currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().text = "战斗力上升" + (int)(500 * 1.3f);currentCanvas.transform.Find("EquipInfo").gameObject.SetActive(true);FindObjectOfType<BagExample>().Refresh();}#endregion#region 装备护肩if (childImage.sprite != null && childImage.sprite.name == "equip01"){currentCanvas.transform.Find("EquipUIs/ShoulderUI01").gameObject.SetActive(false);Transform shoulderEquipPos = GameObject.FindGameObjectWithTag("ShoulderEquipPos").transform;shoulderEquipPos.gameObject.GetComponent<Image>().sprite = childImage.sprite;shoulderEquipPos.gameObject.GetComponent<Image>().color = Color.white;shoulderEquipPos.gameObject.transform.Find("Image").gameObject.SetActive(false);var slot = ItemKit.BagSlots.Find(s => s.Item != null && s.Item.GetKey == "item_iron"); if (slot != null){slot.Item = null;slot.Count = 0;}transform.Find("Icon").GetComponent<Image>().sprite = null;transform.Find("Icon").GetComponent<Image>().color = new Color(45f / 255f, 45f / 255f, 45f / 255f);transform.Find("Icon").GetComponent<Image>().GetComponent<RectTransform>().sizeDelta = new Vector2(90, 90);PlayerNormal.transform.Find("Player/Armors/Plate1/PlateSet1_Shoulders").gameObject.SetActive(true);PlayerUI.transform.Find("Player111/Armors/Plate1/PlateSet1_Shoulders").gameObject.SetActive(true);gm.infoSys.defineValue += 112;gm.infoSys.CombatValue += (int)(112 * 3.3f);currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().color = Color.green;currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().text = "战斗力上升" + (int)(112 * 3.3f);currentCanvas.transform.Find("EquipInfo").gameObject.SetActive(true);FindObjectOfType<BagExample>().Refresh();}#endregion#region 装备铠甲if (childImage.sprite != null && childImage.sprite.name == "equip03"){currentCanvas.transform.Find("EquipUIs/ClothesUI01").gameObject.SetActive(false);Transform clothesEquipPos = GameObject.FindGameObjectWithTag("ClothesEquipPos").transform;clothesEquipPos.gameObject.GetComponent<Image>().sprite = childImage.sprite;clothesEquipPos.gameObject.GetComponent<Image>().color = Color.white;clothesEquipPos.gameObject.transform.Find("Image").gameObject.SetActive(false);var slot = ItemKit.BagSlots.Find(s => s.Item != null && s.Item.GetKey == "item_clothes"); if (slot != null){slot.Item = null;slot.Count = 0;}transform.Find("Icon").GetComponent<Image>().sprite = null;transform.Find("Icon").GetComponent<Image>().color = new Color(45f / 255f, 45f / 255f, 45f / 255f);transform.Find("Icon").GetComponent<Image>().GetComponent<RectTransform>().sizeDelta = new Vector2(90, 90);PlayerNormal.transform.Find("Player/Armors/Plate1/PlateSet1_Chest").gameObject.SetActive(true);PlayerUI.transform.Find("Player111/Armors/Plate1/PlateSet1_Chest").gameObject.SetActive(true);PlayerNormal.transform.Find("Player/Armors/StarterClothes/Starter_Chest").gameObject.SetActive(false);PlayerUI.transform.Find("Player111/Armors/StarterClothes/Starter_Chest").gameObject.SetActive(false);gm.infoSys.defineValue += 224;gm.infoSys.CombatValue += (int)(224 * 3.6f);currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().color = Color.green;currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().text = "战斗力上升" + (int)(224 * 3.6f);currentCanvas.transform.Find("EquipInfo").gameObject.SetActive(true);FindObjectOfType<BagExample>().Refresh();}#endregion#region 装备裤子if (childImage.sprite != null && childImage.sprite.name == "equip04"){currentCanvas.transform.Find("EquipUIs/PantsUI01").gameObject.SetActive(false);Transform pantsEquipPos = GameObject.FindGameObjectWithTag("PantsEquipPos").transform;pantsEquipPos.gameObject.GetComponent<Image>().sprite = childImage.sprite;pantsEquipPos.gameObject.GetComponent<Image>().color = Color.white;pantsEquipPos.gameObject.transform.Find("Image").gameObject.SetActive(false);var slot = ItemKit.BagSlots.Find(s => s.Item != null && s.Item.GetKey == "Item_pants");if (slot != null){slot.Item = null;slot.Count = 0;}transform.Find("Icon").GetComponent<Image>().sprite = null;transform.Find("Icon").GetComponent<Image>().color = new Color(45f / 255f, 45f / 255f, 45f / 255f);transform.Find("Icon").GetComponent<Image>().GetComponent<RectTransform>().sizeDelta = new Vector2(90, 90);PlayerNormal.transform.Find("Player/Armors/Plate1/PlateSet1_Pants").gameObject.SetActive(true);PlayerUI.transform.Find("Player111/Armors/Plate1/PlateSet1_Pants").gameObject.SetActive(true);PlayerNormal.transform.Find("Player/Armors/StarterClothes/Starter_Pants").gameObject.SetActive(false);PlayerUI.transform.Find("Player111/Armors/StarterClothes/Starter_Pants").gameObject.SetActive(false);gm.infoSys.defineValue += 80;gm.infoSys.CombatValue += (int)(80 * 5);currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().color = Color.green;currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().text = "战斗力上升" + (int)(80 * 5);currentCanvas.transform.Find("EquipInfo").gameObject.SetActive(true);FindObjectOfType<BagExample>().Refresh();}#endregion#region 装备鞋子if (childImage.sprite != null && childImage.sprite.name == "equip05"){currentCanvas.transform.Find("EquipUIs/ShoesUI01").gameObject.SetActive(false);Transform shoesEquipPos = GameObject.FindGameObjectWithTag("ShoesEquipPos").transform;shoesEquipPos.gameObject.GetComponent<Image>().sprite = childImage.sprite;shoesEquipPos.gameObject.GetComponent<Image>().color = Color.white;shoesEquipPos.gameObject.transform.Find("Image").gameObject.SetActive(false);var slot = ItemKit.BagSlots.Find(s => s.Item != null && s.Item.GetKey == "item_shoes");if (slot != null){slot.Item = null;slot.Count = 0;}transform.Find("Icon").GetComponent<Image>().sprite = null;transform.Find("Icon").GetComponent<Image>().color = new Color(45f / 255f, 45f / 255f, 45f / 255f);transform.Find("Icon").GetComponent<Image>().GetComponent<RectTransform>().sizeDelta = new Vector2(90, 90);PlayerNormal.transform.Find("Player/Armors/Plate1/PlateSet1_Boots").gameObject.SetActive(true);PlayerUI.transform.Find("Player111/Armors/Plate1/PlateSet1_Boots").gameObject.SetActive(true);PlayerNormal.transform.Find("Player/Armors/StarterClothes/Starter_Boots").gameObject.SetActive(false);PlayerUI.transform.Find("Player111/Armors/StarterClothes/Starter_Boots").gameObject.SetActive(false);gm.infoSys.defineValue += 180;gm.infoSys.CombatValue += (int)(180 * 3);currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().color = Color.green;currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().text = "战斗力上升" + (int)(180 * 3);currentCanvas.transform.Find("EquipInfo").gameObject.SetActive(true);FindObjectOfType<BagExample>().Refresh();}#endregion#region 装备头盔if (childImage.sprite != null && childImage.sprite.name == "equip06"){currentCanvas.transform.Find("EquipUIs/HatUI01").gameObject.SetActive(false);Transform hatEquipPos = GameObject.FindGameObjectWithTag("HatEquipPos").transform;hatEquipPos.gameObject.GetComponent<Image>().sprite = childImage.sprite;hatEquipPos.gameObject.GetComponent<Image>().color = Color.white;hatEquipPos.gameObject.transform.Find("Image").gameObject.SetActive(false);var slot = ItemKit.BagSlots.Find(s => s.Item != null && s.Item.GetKey == "item_hat");if (slot != null){slot.Item = null;slot.Count = 0;}transform.Find("Icon").GetComponent<Image>().sprite = null;transform.Find("Icon").GetComponent<Image>().color = new Color(45f / 255f, 45f / 255f, 45f / 255f);transform.Find("Icon").GetComponent<Image>().GetComponent<RectTransform>().sizeDelta = new Vector2(90, 90);PlayerNormal.transform.Find("Player/Armors/Plate1/PlateSet1_Helmet").gameObject.SetActive(true);PlayerUI.transform.Find("Player111/Armors/Plate1/PlateSet1_Helmet").gameObject.SetActive(true);PlayerNormal.transform.Find("Player/Armors/Plate1/PlateSet1_Gloves").gameObject.SetActive(true);PlayerUI.transform.Find("Player111/Armors/Plate1/PlateSet1_Gloves").gameObject.SetActive(true);gm.infoSys.defineValue += 200;gm.infoSys.CombatValue += (int)(200 * 3);currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().color = Color.green;currentCanvas.transform.Find("EquipInfo").GetComponent<Text>().text = "战斗力上升" + (int)(200 * 3);currentCanvas.transform.Find("EquipInfo").gameObject.SetActive(true);FindObjectOfType<BagExample>().Refresh();}#endregion}}public void OnPointerEnter(PointerEventData eventData){#region 装备武器if (childImage.sprite != null && childImage.sprite.name == "equip02"){currentCanvas.transform.Find("EquipUIs/WeaponUI01").gameObject.SetActive(true);}#endregion#region 装备护肩if (childImage.sprite != null && childImage.sprite.name == "equip01"){currentCanvas.transform.Find("EquipUIs/ShoulderUI01").gameObject.SetActive(true);}#endregion#region 装备铠甲if (childImage.sprite != null && childImage.sprite.name == "equip03"){currentCanvas.transform.Find("EquipUIs/ClothesUI01").gameObject.SetActive(true);}#endregion#region 装备裤子if (childImage.sprite != null && childImage.sprite.name == "equip04"){currentCanvas.transform.Find("EquipUIs/PantsUI01").gameObject.SetActive(true);}#endregion#region 装备鞋子if (childImage.sprite != null && childImage.sprite.name == "equip05"){currentCanvas.transform.Find("EquipUIs/ShoesUI01").gameObject.SetActive(true);}#endregion#region 装备头盔if (childImage.sprite != null && childImage.sprite.name == "equip06"){currentCanvas.transform.Find("EquipUIs/HatUI01").gameObject.SetActive(true);}#endregion}public void OnPointerExit(PointerEventData eventData){#region 装备武器if (childImage.sprite != null && childImage.sprite.name == "equip02"){currentCanvas.transform.Find("EquipUIs/WeaponUI01").gameObject.SetActive(false);}#endregion#region 装备护肩if (childImage.sprite != null && childImage.sprite.name == "equip01"){currentCanvas.transform.Find("EquipUIs/ShoulderUI01").gameObject.SetActive(false);}#endregion#region 装备铠甲if (childImage.sprite != null && childImage.sprite.name == "equip03"){currentCanvas.transform.Find("EquipUIs/ClothesUI01").gameObject.SetActive(false);}#endregion#region 装备裤子if (childImage.sprite != null && childImage.sprite.name == "equip04"){currentCanvas.transform.Find("EquipUIs/PantsUI01").gameObject.SetActive(false);}#endregion#region 装备鞋子if (childImage.sprite != null && childImage.sprite.name == "equip05"){currentCanvas.transform.Find("EquipUIs/ShoesUI01").gameObject.SetActive(false);}#endregion#region 装备头盔if (childImage.sprite != null && childImage.sprite.name == "equip06"){currentCanvas.transform.Find("EquipUIs/HatUI01").gameObject.SetActive(false);}#endregion}
}

运行项目 

接下来的文章内容:

1.六件装备穿戴齐全后的炫光效果

2.窗口可拖拽脚本

3.点击名称寻找地点功能

4.隐藏怪物的生成

5.怪物I攻击范围内的主动攻击

6.掉落坐骑蛋的获取

7.异步传送转换场景

以及开放回合制、坐骑系统、宠物系统、背包系统、神炼系统、商城系统、Boss的目标跟随任务导航系统以及UI播放3D动画效果等等。

具体项目运行效果请关注water1024的b站视频项目演示《破碎纪元》

【Unity回合2.5D】破碎纪元_单机游戏热门视频 (bilibili.com)icon-default.png?t=O83Ahttps://www.bilibili.com/video/BV1rZY4e9Ebs/?spm_id_from=333.999.0.0&vd_source=547091a95b03acfa8e8a9e46ef499cd6

相关文章:

  • .Net 6.0 Windows平台如何判断当前电脑是否联网
  • 重头开始嵌入式第四十四天(硬件 ARM裸机开发)
  • 外国电影演员识别系统源码分享
  • 当大语言模型应用到教育领域时会有什么火花出现?
  • SD(Stable Diffusion)模型的基本工作数据流
  • 批量发送邮件:性能优化与错误处理深度解析
  • 基于微信小程序爱心领养小程序设计与实现(源码+定制+开发)
  • 算法刷题笔记 约数个数(详细注释的C++实现)
  • 【Java】单元测试【主线学习笔记】
  • 通俗易懂的Latex使用步骤
  • RNA-seq通用代码-生物信息学pipeline001
  • 从博客到ICT社区:深化学习与交流的桥梁
  • 端上自动化测试平台实践
  • 不再兼容安卓,鸿蒙系统未来胜算几何?
  • 智能工厂的设计软件 设计目标:关乎对象的实践法则的认识论原则
  • CentOS 7 防火墙操作
  • FineReport中如何实现自动滚屏效果
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • Just for fun——迅速写完快速排序
  • laravel 用artisan创建自己的模板
  • mysql外键的使用
  • python_bomb----数据类型总结
  • RxJS: 简单入门
  • vuex 学习笔记 01
  • Vue源码解析(二)Vue的双向绑定讲解及实现
  • 大主子表关联的性能优化方法
  • 基于Javascript, Springboot的管理系统报表查询页面代码设计
  • 基于Vue2全家桶的移动端AppDEMO实现
  • 如何合理的规划jvm性能调优
  • 如何选择开源的机器学习框架?
  • 微信小程序:实现悬浮返回和分享按钮
  • 赢得Docker挑战最佳实践
  • 继 XDL 之后,阿里妈妈开源大规模分布式图表征学习框架 Euler ...
  • ​【原创】基于SSM的酒店预约管理系统(酒店管理系统毕业设计)
  • ​力扣解法汇总946-验证栈序列
  • ​软考-高级-信息系统项目管理师教程 第四版【第14章-项目沟通管理-思维导图】​
  • # wps必须要登录激活才能使用吗?
  • # 透过事物看本质的能力怎么培养?
  • ## 临床数据 两两比较 加显著性boxplot加显著性
  • #Datawhale X 李宏毅苹果书 AI夏令营#3.13.2局部极小值与鞍点批量和动量
  • #WEB前端(HTML属性)
  • (iPhone/iPad开发)在UIWebView中自定义菜单栏
  • (pycharm)安装python库函数Matplotlib步骤
  • (不用互三)AI绘画工具应该如何选择
  • (第30天)二叉树阶段总结
  • (二)什么是Vite——Vite 和 Webpack 区别(冷启动)
  • (附源码)springboot 智能停车场系统 毕业设计065415
  • (附源码)计算机毕业设计大学生兼职系统
  • (亲测)设​置​m​y​e​c​l​i​p​s​e​打​开​默​认​工​作​空​间...
  • (十五)devops持续集成开发——jenkins流水线构建策略配置及触发器的使用
  • (十五)使用Nexus创建Maven私服
  • (五)IO流之ByteArrayInput/OutputStream
  • (一)RocketMQ初步认识
  • (转)拼包函数及网络封包的异常处理(含代码)
  • (总结)(2)编译ORB_SLAM2遇到的错误