当前位置:网站首页>The panel floating with the mouse in unity can adapt to the size of text content
The panel floating with the mouse in unity can adapt to the size of text content
2022-07-07 02:35:00 【Wu Zimu】
We often use the function of floating panel , For example, the mouse moves to an object , Display the name of the object and other information
To this end, I made a panel that can adapt the content size according to the text content
The structure of the panel is as follows
There are three objects ,InfoText The name can't be the rest can
object 1: RoomInfoPanel Consists of four key components , The explanation is as follows
1 Text Used to adapt the size according to the text size , This text is transparent , Don't show users , And the font size is larger than that really used for display InfoText A little bigger
2 FloatInfoPanel, Used to set the displayed text , The code is as follows , It can be modified as needed
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Floating panel for room information
/// </summary>
public class FloatInfoPanel : MonoBehaviour
{
/// <summary>
/// Self Text Components , This Text It's completely transparent , Used to control the adaptive panel size
/// </summary>
private Text textSelf;
/// <summary>
/// Text box for displaying information
/// </summary>
private Text infoText;
/// <summary>
/// Set the surveillance camera information displayed in suspension
/// </summary>
public void SetRoomName(string roomName)
{
if (textSelf == null)
{
textSelf = transform.GetComponent<Text>();
infoText = transform.Find("InfoText").GetComponent<Text>();
}
textSelf.text = GameController.Instance.currentRoom_float;
infoText.text = GameController.Instance.currentRoom_float;
}
}
3 FloatWithMouse_Panel The panel moves with the mouse , Just hang it up , Surrogate mothers are as follows
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// The panel floats with the mouse
/// </summary>
public class FloatWithMouse_Panel : MonoBehaviour
{
public float xoffset;
public float yoffset;
public float zoffset;
private void Update()
{
print(Input.mousePosition);
transform.position = Input.mousePosition + new Vector3(xoffset,yoffset,zoffset);
}
}
4ContentSizeFitter Adaptive size
We need to pay attention to , Anchor points should be point shaped , Put it in the lower left corner , The pivot point can prevent , It is recommended to keep to the left , Or lower left
object 2 BG, Panel background , Four sides and RoomInfoPanel alignment
object 3 InfoText Text for users
边栏推荐
- Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
- MES管理系统的应用和好处有哪些
- leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
- Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
- 慧通编程入门课程 - 2A闯关
- Web3的先锋兵:虚拟人
- 差异与阵列和阵列结构和链表的区别
- B站6月榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!
- #yyds干货盘点# 解决名企真题:最大差值
- 【Node学习笔记】chokidar模块实现文件监听
猜你喜欢
dotConnect for DB2数据提供者
Web3的先锋兵:虚拟人
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
如何设计好接口测试用例?教你几个小技巧,轻松稿定
Web3's need for law
阿里云易立:云原生如何破解企业降本提效难题?
Application analysis of face recognition
C # / vb. Net supprime le filigrane d'un document word
人脸识别应用解析
随机推荐
数字滚动增加效果
postgresql之整体查询大致过程
postgresql之整體查詢大致過程
写作系列之contribution
The last line of defense of cloud primary mixing department: node waterline design
【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs
用全连接+softmax对图片的feature进行分类
A new path for enterprise mid Platform Construction -- low code platform
KYSL 海康摄像头 8247 h9 isapi测试
go swagger使用
Recommended collection!! Which is the best flutter status management plug-in? Please look at the ranking list of yard farmers on the island!
Apifox, is your API interface document rolled up like this?
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
MySQL --- 常用函数 - 字符串函数
FLIR blackfly s usb3 industrial camera: how to use counters and timers
运维管理系统有哪些特色
fiddler的使用
Leetcode:minimum_depth_of_binary_tree解决问题的方法
New generation cloud native message queue (I)
Safety delivery engineer