当前位置:网站首页>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
边栏推荐
- Halcon实例转OpenCvSharp(C# OpenCV)实现--瓶口缺陷检测(附源码)
- MySQL
- Common fitting models and application methods of PCL
- 豆瓣平均 9.x,分布式领域的 5 本神书!
- Apifox, is your API interface document rolled up like this?
- 6-6 vulnerability exploitation SSH security defense
- Rethinking of investment
- 一文读懂Faster RCNN
- 普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
- 阿里云易立:云原生如何破解企业降本提效难题?
猜你喜欢
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
电气工程及其自动化
Infrared camera: juge infrared mag32 product introduction
[paper reading | deep reading] graphsage:inductive representation learning on large graphs
慧通编程入门课程 - 2A闯关
Detailed explanation of line segment tree (including tested code implementation)
The last line of defense of cloud primary mixing department: node waterline design
如何从0到1构建32Core树莓派集群
Web3对法律的需求
Overall query process of PostgreSQL
随机推荐
FLIR blackfly s usb3 industrial camera: how to use counters and timers
Argo workflows source code analysis
Apifox, is your API interface document rolled up like this?
服装企业部署MES管理系统的五个原因
安全巡检的工作
MES管理系统的应用和好处有哪些
MySQL --- 常用函数 - 字符串函数
Pioneer of Web3: virtual human
unity中跟随鼠标浮动的面板,并可以自适应文字内容的大小
The cities research center of New York University recruits master of science and postdoctoral students
[Mori city] random talk on GIS data (II)
What to do when encountering slow SQL? (next)
Lumion 11.0软件安装包下载及安装教程
Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
Yyds dry goods inventory # solve the real problem of famous enterprises: maximum difference
How do I dump SoapClient requests for debugging- How to dump SoapClient request for debug?
[unity notes] screen coordinates to ugui coordinates
Common fitting models and application methods of PCL
CSDN summer camp course project analysis
MetaForce原力元宇宙佛萨奇2.0智能合约系统开发(源码部署)