当前位置:网站首页>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
边栏推荐
- Overall query process of PostgreSQL
- Yyds dry goods inventory # solve the real problem of famous enterprises: maximum difference
- Draco - gltf model compression tool
- 【论文阅读|深读】RolNE: Improving the Quality of Network Embedding with Structural Role Proximity
- Introduction to FLIR blackfly s industrial camera
- Untiy文本框的代码换行问题
- Here comes a white paper to uncover the technology behind Clickhouse, a node with 10000 bytes!
- The cities research center of New York University recruits master of science and postdoctoral students
- Decryption function calculates "task state and lifecycle management" of asynchronous task capability
- [Mori city] random talk on GIS data (II)
猜你喜欢

Data connection mode in low code platform (Part 1)

AWS学习笔记(一)

Overall query process of PostgreSQL

Fundamentals of process management

Alibaba cloud middleware open source past

Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module

【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs

运维管理系统有哪些特色

FLIR blackfly s usb3 industrial camera: how to use counters and timers
![[unity notes] screen coordinates to ugui coordinates](/img/e4/fc18dd9b4b0e36ec3e278e5fb3fd23.jpg)
[unity notes] screen coordinates to ugui coordinates
随机推荐
C语言练习题_1
数论 --- 快速幂、快速幂求逆元
Here comes a white paper to uncover the technology behind Clickhouse, a node with 10000 bytes!
Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
postgresql之整体查询大致过程
Stm32f4 --- PWM output
遇到慢SQL该怎么办?(下)
CDB PDB user rights management
Why am I warned that the 'CMAKE_ TOOLCHAIN_ FILE' variable is not used by the project?
Difference and the difference between array and array structure and linked list
unity webgl自适应网页尺寸
KYSL 海康摄像头 8247 h9 isapi测试
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
人脸识别应用解析
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
GEE升级,可以实现一件run tasks
豆瓣平均 9.x,分布式领域的 5 本神书!
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
Halcon instance to opencvsharp (C openCV) implementation -- bottle mouth defect detection (with source code)
PostgreSQL图形化界面工具之pgAdmin4