当前位置:网站首页>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
边栏推荐
- Application analysis of face recognition
- [xlua notes] array of lua to array of C #
- #yyds干货盘点# 解决名企真题:最大差值
- leetcode:5. Longest palindrome substring [DP + holding the tail of timeout]
- Difference and the difference between array and array structure and linked list
- 3D laser slam: time synchronization of livox lidar hardware
- C语言练习题_1
- [Mori city] random talk on GIS data (II)
- 服装企业部署MES管理系统的五个原因
- [leetcode]Search for a Range
猜你喜欢
Summer Challenge database Xueba notes (Part 2)~
电气工程及其自动化
Alibaba cloud middleware open source past
Lumion 11.0软件安装包下载及安装教程
dotConnect for DB2数据提供者
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity
Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
C#/VB.NET 删除Word文檔中的水印
Application analysis of face recognition
用全连接+softmax对图片的feature进行分类
随机推荐
一本揭秘字节万台节点ClickHouse背后技术实现的白皮书来了!
[xlua notes] array of lua to array of C #
B站6月榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!
leetcode:5. Longest palindrome substring [DP + holding the tail of timeout]
QPushButton-》函数精解
Use of pgpool II and pgpooladmin
A new path for enterprise mid Platform Construction -- low code platform
What to do when encountering slow SQL? (next)
运维管理系统有哪些特色
【Node学习笔记】chokidar模块实现文件监听
The empirical asset pricing package (EAP) can be installed through pypi
导数、偏导数、方向导数
argo workflows源码解析
实施MES管理系统时,哪些管理点是需要注意的
[server data recovery] data recovery case of a Dell server crash caused by raid damage
6-6漏洞利用-SSH安全防御
你不可不知道的Selenium 8种元素定位方法,简单且实用
Detailed explanation of line segment tree (including tested code implementation)
The cities research center of New York University recruits master of science and postdoctoral students
MetaForce原力元宇宙佛萨奇2.0智能合约系统开发(源码部署)