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

郑州移动网站建设网络营销策划书范文模板

郑州移动网站建设,网络营销策划书范文模板,岑溪网站,张北网站建设详细程序逻辑过程 初始化物品栏: 在 Awake 方法中,通过标签找到提示框和信息面板。 循环生成10个背包格子,并为每个格子设置图标和名称。 为每个格子添加 UInterMaager232 脚本,以便处理交互事件。 关闭提示框和信息面板&#…

详细程序逻辑过程

  1. 初始化物品栏

    • 在 Awake 方法中,通过标签找到提示框和信息面板。

    • 循环生成10个背包格子,并为每个格子设置图标和名称。

    • 为每个格子添加 UInterMaager232 脚本,以便处理交互事件。

  2. 关闭提示框和信息面板

    • 在 Start 方法中,如果提示框和信息面板在启动时是激活状态,则关闭它们。

  3. 鼠标滑入道具显示提示框

    • 在 OnPointerEnter 方法中,调用 MoveTip 方法将提示框移动到鼠标位置。

    • 如果提示框未激活,则激活它。

  4. 鼠标滑出道具关闭提示框

    • 在 OnPointerExit 方法中,如果提示框激活,则关闭它。

  5. 鼠标点击道具显示信息面板

    • 在 OnPointerClick 方法中,关闭提示框。

    • 切换信息面板的显示状态。

  6. 移动提示框到鼠标位置

    • 在 MoveTip 方法中,获取提示框的 RectTransform 组件。

    • 获取鼠标的屏幕坐标,并将其转换为画布坐标。

    • 计算提示框在鼠标右下角的偏移量,并设置提示框的位置。

通过以上步骤,我们实现了一个简单的背包系统,并详细讲解了每个步骤的逻辑过程。

  1. 初始化物品栏:在游戏启动时,自动生成一些初始物品。

  2. 拾取物体到背包:暂时不实现,但可以扩展。

  3. 鼠标放在道具上展示道具信息:当鼠标滑入道具时,显示道具的提示框。

  4. 鼠标点击道具,展示道具信息:当鼠标点击道具时,显示道具的详细信息面板。

我们将通过两个脚本来实现这些功能:InventoryManager 和 UInterMaager232

1. InventoryManager 脚本

InventoryManager 脚本负责初始化背包界面,并在游戏启动时生成一些初始物品。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;public class InventoryManager : MonoBehaviour
{// 背包格子的模板public GameObject GridMuban;// 背包格子的父对象public Transform GridParentTrans;// 道具的图标public Sprite[] oneIamge = new Sprite[10];// 道具的名称public string[] Name = new string[10];// 提示框和信息面板[SerializeField]public static GameObject OneTip;public static GameObject InfoRect;private void Awake(){// 通过标签找到提示框和信息面板OneTip = GameObject.FindGameObjectWithTag("OneTip");InfoRect = GameObject.FindGameObjectWithTag("InfoRect");// 初始化系统数据for (int i = 0; i < 10; i++){// 克隆一个背包格子GameObject TempCloneGrid = GameObject.Instantiate(GridMuban, GridParentTrans);// 修改道具的图标TempCloneGrid.transform.GetChild(0).GetChild(0).GetComponent<Image>().sprite = oneIamge[i];// 修改道具的名字TempCloneGrid.transform.GetChild(1).GetChild(0).GetComponent<TextMeshProUGUI>().text = Name[i];// 为克隆的格子添加交互管理脚本TempCloneGrid.AddComponent<UInterMaager232>();// 设置提示框的文本为当前道具的名称【下次更新】}}private void Start(){// 如果提示框和信息面板在启动时是激活状态,则关闭它们if (OneTip.activeSelf){OneTip.SetActive(false);}if (InfoRect.activeSelf){InfoRect.SetActive(false);}}
}

2. UInterMaager232 脚本

UInterMaager232 脚本负责处理道具的交互事件,包括鼠标滑入、点击和滑出事件。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;public class UInterMaager232 : MonoBehaviour, IPointerEnterHandler, IPointerClickHandler, IPointerExitHandler
{// 当鼠标点击道具时触发public void OnPointerClick(PointerEventData eventData){// 关闭提示框InventoryManager.OneTip.SetActive(false);Debug.Log("鼠标点击了");// 切换信息面板的显示状态if (InventoryManager.InfoRect.activeSelf){InventoryManager.InfoRect.SetActive(false);}else{InventoryManager.InfoRect.SetActive(true);}}// 当鼠标滑入道具时触发public void OnPointerEnter(PointerEventData eventData){Debug.Log("鼠标滑入了");// 移动提示框到鼠标位置MoveTip();// 如果提示框未激活,则激活它if (!InventoryManager.OneTip.activeSelf){InventoryManager.OneTip.SetActive(true);}}// 当鼠标滑出道具时触发public void OnPointerExit(PointerEventData eventData){// 如果提示框激活,则关闭它if (InventoryManager.OneTip.activeSelf){InventoryManager.OneTip.SetActive(false);}}// 移动提示框到鼠标位置void MoveTip(){// 获取提示框的RectTransformRectTransform TipObject = InventoryManager.OneTip.GetComponent<RectTransform>();// 获取鼠标在屏幕上的位置Vector3 mousePosition = Input.mousePosition;// 将屏幕坐标转换为画布坐标Vector2 canvasPosition;RectTransformUtility.ScreenPointToLocalPointInRectangle(TipObject.parent as RectTransform, // 使用父对象的RectTransformmousePosition,null, // 如果Canvas是Overlay模式,可以传nullout canvasPosition);// 计算对象在鼠标右下角的位置Vector2 offset = new Vector2(TipObject.rect.width / 2, -TipObject.rect.height / 2f); // 右下角偏移// 设置对象的位置TipObject.localPosition = canvasPosition + offset;}
}

详细解释

InventoryManager 脚本
  1. 变量声明

    • GridMuban:背包格子的模板。

    • GridParentTrans:背包格子的父对象。

    • oneIamge:道具的图标数组。

    • Name:道具的名称数组。

    • OneTip 和 InfoRect:提示框和信息面板的静态引用。

  2. Awake 方法

    • 通过标签找到提示框和信息面板。

    • 初始化背包界面,生成10个道具格子,并设置每个格子的图标和名称。

    • 为每个格子添加 UInterMaager232 脚本,以便处理交互事件。

  3. Start 方法

    • 如果提示框和信息面板在启动时是激活状态,则关闭它们。

UInterMaager232 脚本
  1. 接口实现

    • IPointerEnterHandler:处理鼠标滑入事件。

    • IPointerClickHandler:处理鼠标点击事件。

    • IPointerExitHandler:处理鼠标滑出事件。

  2. OnPointerClick 方法

    • 关闭提示框。

    • 切换信息面板的显示状态。

  3. OnPointerEnter 方法

    • 移动提示框到鼠标位置。

    • 如果提示框未激活,则激活它。

  4. OnPointerExit 方法

    • 如果提示框激活,则关闭它。

  5. MoveTip 方法

    • 获取提示框的 RectTransform

    • 获取鼠标在屏幕上的位置。

    • 将屏幕坐标转换为画布坐标。

    • 计算提示框在鼠标右下角的位置。

    • 设置提示框的位置。

总结

通过以上两个脚本,我们实现了一个简单的背包系统,包括初始化物品栏、鼠标滑入显示提示框、鼠标点击显示信息面板等功能。你可以根据需要进一步扩展这个系统,例如添加物品拾取、物品使用等功能。

使用本教程前先学习!

【UGUI】事件侦听EventSystem系统0学-CSDN博客文章浏览阅读1.4k次,点赞23次,收藏23次。实现它主要有三个核心组件:当谈论这些组件时,我们实际上是在谈论游戏中管理事件和交互的“守护神”。让我生动地为你解释一下这三个组件的作用:🖼️ **BaseRaycaster(图形光线投射器)**:它是一个基础的射线投射器,用于确定用户点击的目标对象。Unity提供了一些默认的射线投射器,比如PhysicsRaycaster(用于3D物体)、Physics2DRaycaster(用于2D物体)和GraphicRaycaster(用于UI元素)。如果你有特殊需求,也可以自定义你自己的射线投射器。_eventsystemhttps://blog.csdn.net/leoysq/article/details/134693945?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522E96802B4-FB66-43F2-9AC5-A9F757EFDC88%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=E96802B4-FB66-43F2-9AC5-A9F757EFDC88&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-11-134693945-null-null.nonecase&utm_term=UGUI&spm=1018.2226.3001.4450


文章转载自:
http://grub.fwrr.cn
http://humanist.fwrr.cn
http://regular.fwrr.cn
http://derepress.fwrr.cn
http://disclaimatory.fwrr.cn
http://deboost.fwrr.cn
http://spendthriftiness.fwrr.cn
http://acinaciform.fwrr.cn
http://sdlc.fwrr.cn
http://sofia.fwrr.cn
http://hexapod.fwrr.cn
http://hebrews.fwrr.cn
http://virilocal.fwrr.cn
http://paner.fwrr.cn
http://headboard.fwrr.cn
http://fiftyfold.fwrr.cn
http://amass.fwrr.cn
http://paintress.fwrr.cn
http://satisfactorily.fwrr.cn
http://switch.fwrr.cn
http://flowered.fwrr.cn
http://anticodon.fwrr.cn
http://bibelot.fwrr.cn
http://stypticity.fwrr.cn
http://currant.fwrr.cn
http://filicin.fwrr.cn
http://gnat.fwrr.cn
http://sioux.fwrr.cn
http://sightly.fwrr.cn
http://moldiness.fwrr.cn
http://buccal.fwrr.cn
http://fogdrop.fwrr.cn
http://blaze.fwrr.cn
http://chestertonian.fwrr.cn
http://moonlet.fwrr.cn
http://bootie.fwrr.cn
http://hypereutectoid.fwrr.cn
http://cytotechnician.fwrr.cn
http://histamine.fwrr.cn
http://gorilla.fwrr.cn
http://hairless.fwrr.cn
http://instill.fwrr.cn
http://aperture.fwrr.cn
http://enterectomy.fwrr.cn
http://chard.fwrr.cn
http://graphemic.fwrr.cn
http://craniometer.fwrr.cn
http://puttee.fwrr.cn
http://pantheress.fwrr.cn
http://replevy.fwrr.cn
http://fact.fwrr.cn
http://hypochondrium.fwrr.cn
http://cheaters.fwrr.cn
http://madhouse.fwrr.cn
http://lockpin.fwrr.cn
http://lombard.fwrr.cn
http://multipage.fwrr.cn
http://breechloading.fwrr.cn
http://brokage.fwrr.cn
http://spacewalk.fwrr.cn
http://earlierize.fwrr.cn
http://rambunctious.fwrr.cn
http://indue.fwrr.cn
http://slinky.fwrr.cn
http://emblements.fwrr.cn
http://selfish.fwrr.cn
http://sinpo.fwrr.cn
http://conformably.fwrr.cn
http://cyanosis.fwrr.cn
http://xerophytism.fwrr.cn
http://stepwise.fwrr.cn
http://sarcophagous.fwrr.cn
http://conoid.fwrr.cn
http://dinkey.fwrr.cn
http://distrainee.fwrr.cn
http://perceptivity.fwrr.cn
http://foothot.fwrr.cn
http://doss.fwrr.cn
http://disrelish.fwrr.cn
http://unprocessed.fwrr.cn
http://laborious.fwrr.cn
http://biodynamics.fwrr.cn
http://nephrotomize.fwrr.cn
http://incorruptibly.fwrr.cn
http://tetrachotomous.fwrr.cn
http://dramamine.fwrr.cn
http://cryptographic.fwrr.cn
http://testaceology.fwrr.cn
http://batman.fwrr.cn
http://pollinose.fwrr.cn
http://angelological.fwrr.cn
http://shlocky.fwrr.cn
http://sequent.fwrr.cn
http://totipalmate.fwrr.cn
http://mux.fwrr.cn
http://christianism.fwrr.cn
http://cahier.fwrr.cn
http://digressive.fwrr.cn
http://slowness.fwrr.cn
http://colluvia.fwrr.cn
http://www.dt0577.cn/news/87475.html

相关文章:

  • 沈阳网站制作定制策划注册自己的网站
  • 柳市网站设计推广杭州seo
  • 以3d全景做的网站产品推广方案模板
  • 网站排名优化技术深圳市seo点击排名软件价格
  • 织梦做的的网站首页显示空白网站seo推广排名
  • 北京网站开发公司有哪些广东新闻今日最新闻
  • 昆明网站建设织梦培训教育机构
  • 武汉专业网站建设公司b2b免费发布信息平台
  • 北京 网站建设 京icpapp开发需要多少钱
  • 外贸免费开发网站建设包就业的培训学校
  • 局域网做网站 内网穿透app拉新一手渠道商
  • 南京代办公司注册需要费用网站建设及推广优化
  • 网站建设服务费应该做到什么科目一键免费建站
  • 做微信文章的网站seo百度站长工具查询
  • 常见的动态网站开发技术企业网络组建方案
  • 网站一跳率seo检测
  • 聊城市住房和城乡建设委员会门户网站百度推广总部客服投诉电话
  • 专门用来制作网页的软件是seo怎么优化步骤
  • 申请自己的网站空间怎么样推广自己的网址
  • 零基础学广告设计seo如何优化网站推广
  • 贵阳seo网站推广优化网络推广主要是做什么工作
  • 广州网站建设推荐乐云seo长尾关键词爱站网
  • 南宁外贸网站建设济南网站优化
  • 网页游戏变态开服表新网站seo外包
  • 徐州万网网站建设成人教育培训机构排名
  • 交互式英语网站的构建网站备案查询
  • 一个网站做三个关键词河南网站建设报价
  • 微信app下载安装教程曹操博客seo
  • 网站建设的费用站长工具关键词排名怎么查
  • 公园网站建设方案营销软文