当前位置:网站首页>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
边栏推荐
- argo workflows源码解析
- unity 自定义webgl打包模板
- Cloud Mail .NET Edition
- C#/VB.NET 删除Word文档中的水印
- [xlua notes] array of lua to array of C #
- ODBC database connection of MFC windows programming [147] (with source code)
- 纽约大学 CITIES 研究中心招聘理学硕士和博士后
- [leetcode]Search for a Range
- C # / vb. Net supprime le filigrane d'un document word
- S120驱动器基本调试步骤总结
猜你喜欢
Lidar: introduction and usage of ouster OS
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity
运维管理系统有哪些特色
Argo workflows source code analysis
S120驱动器基本调试步骤总结
KYSL 海康摄像头 8247 h9 isapi测试
Douban average 9 x. Five God books in the distributed field!
Web3对法律的需求
Overall query process of PostgreSQL
New generation cloud native message queue (I)
随机推荐
dotConnect for DB2数据提供者
Alibaba cloud middleware open source past
KYSL 海康摄像头 8247 h9 isapi测试
Lombok makes the pit of ⽤ @data and @builder at the same time
Detailed explanation of line segment tree (including tested code implementation)
差异与阵列和阵列结构和链表的区别
Web3's need for law
安全巡检的工作
postgresql之整體查詢大致過程
fiddler的使用
Here comes a white paper to uncover the technology behind Clickhouse, a node with 10000 bytes!
6-6 vulnerability exploitation SSH security defense
实施MES管理系统时,哪些管理点是需要注意的
unity webgl自适应网页尺寸
遇到慢SQL该怎么办?(下)
go swagger使用
3--新唐nuc980 kernel支持jffs2, Jffs2文件系统制作, 内核挂载jffs2, uboot网口设置,uboot支持tftp
豆瓣平均 9.x,分布式领域的 5 本神书!
MySQL
Safety delivery engineer