Unity 3D
来源:互联网 发布:国际象棋对弈软件下载 编辑:程序博客网 时间:2024/06/04 17:56
Unity 3D - UGUI 显示道具信息 :
显示效果 :
字符串排版处理 - 链接
Demo 实现效果 :
鼠标放到道具上 , 会显示出图中提示信息 , 提示信息面板会跟随鼠标移动 , 鼠标离开道具时 , 提示信息面板会自动隐藏 .
实现过程 :
先在道具脚本上继承接口 IPointerEnterHandler 和 IPointerExitHandler .
在鼠标移动到道具上时 , 通过委派调用 OnEnter 方法 , 传入transform .
C# 代码 :
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.EventSystems;using System;public class GridUI : MonoBehaviour, IPointerEnterHandler,IPointerExitHandler{ public static Action<Transform> OnEnter; public static Action OnExit; public void OnPointerEnter(PointerEventData eventData) { if (OnEnter != null) { OnEnter (transform); } } public void OnPointerExit(PointerEventData eventData) { if (OnExit != null) { OnExit (); } }}
Manager类处理 .
//先添加回调函数void Awake(){ GridUI.OnEnter += GridUI_OnEnte; GridUI.OnExit += GridUI_OnExit;}public void GridUI_OnEnte(Transform gridTransfrom){ //获取道具信息 Item item = ItemModel.GetItem (gridTransfrom.name); //通过道具信息得到需要显示的字符串 string str = GetItemInfoStr (item); //显示提示框 isShow = true; itemtip.gameObject.SetActive (true); //用字符串刷新提示框里文本信息 itemtip.refreshInfo (str);}public void GridUI_OnExit(){ //隐藏提示框 isShow = false; itemtip.gameObject.SetActive (false);}
然后在Update中 , 让提示框跟随移动 .
void Update (){ //如果处理显示状态 if (isShow == true) { //获取鼠标位置 Vector2 position; RectTransform rect = GameObject.Find ("Canvas").transform as RectTransform; Vector2 point = Input.mousePosition; RectTransformUtility.ScreenPointToLocalPointInRectangle (rect, point, null, out position); //设置提示框位置 itemtip.transform.localPosition = position; }}
1 0
- Unity 3D
- unity 3d 注意事项
- Unity 3d 摄像头
- Unity 3D 使用
- Unity 3D--PlayerPrefs
- Unity 3d
- Unity 3D俄罗斯方块
- unity 3d 多开
- UNITY 3D笔记
- Unity 3D接触
- unity 3d
- Unity 3D简介
- Unity 3D 琐记
- unity 3d 视频
- Unity 3D 光源
- Unity 3D FingerID
- 再议Unity 3D
- unity 3d 网址
- 左右都是半圆的selector
- 表达式求值
- 1.3.1微信小程序 WXML
- javascript添加删除div,对象的方法
- c++ primer plus 之for循环
- Unity 3D
- BZOJ4653: [Noi2016]区间
- 在Windows2008 Server服务器上开启Ping或者禁PING
- cuda由7.0升级到8.0
- xutils 网络请求框架结合BaseRecyclerViewAdapterHelper万能adapter
- alsa 无噪音播放pcm
- dinic 模板
- 正则表达式
- 【IMWeb训练营作业】之select组件