当前位置:网站首页>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
边栏推荐
- fiddler的使用
- wzoi 1~200
- 如何从0到1构建32Core树莓派集群
- Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
- 豆瓣平均 9.x,分布式领域的 5 本神书!
- fasterxml ToStringSerializerBase报错
- Here comes a white paper to uncover the technology behind Clickhouse, a node with 10000 bytes!
- 安德鲁斯—-多媒体编程
- 【软件测试】最全面试问题和回答,全文背熟不拿下offer算我输
- This week's hot open source project!
猜你喜欢
[paper reading | deep reading] graphsage:inductive representation learning on large graphs
6-6 vulnerability exploitation SSH security defense
Ali yunyili: how does yunyuansheng solve the problem of reducing costs and improving efficiency?
leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
Processus général de requête pour PostgreSQL
postgresql之integerset
本周 火火火火 的开源项目!
人脸识别应用解析
leetcode:736. LISP syntax parsing [flowery + stack + status enumaotu + slots]
AWS学习笔记(一)
随机推荐
Why am I warned that the 'CMAKE_ TOOLCHAIN_ FILE' variable is not used by the project?
Application analysis of face recognition
Lidar: introduction and usage of ouster OS
Real project, realized by wechat applet opening code (end)
How do I dump SoapClient requests for debugging- How to dump SoapClient request for debug?
Leetcode:minimum_ depth_ of_ binary_ Tree solutions
实施MES管理系统时,哪些管理点是需要注意的
fasterxml ToStringSerializerBase报错
C#/VB. Net to delete watermarks in word documents
慧通编程入门课程 - 2A闯关
真实项目,用微信小程序开门编码实现(完结)
导数、偏导数、方向导数
记一次JAP查询导致OOM的问题分析
安德鲁斯—-多媒体编程
C # / vb. Net supprime le filigrane d'un document word
Lombok同时使⽤@Data和@Builder 的坑
Work of safety inspection
MySQL --- 常用函数 - 字符串函数
fiddler的使用
B站6月榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!