unity3d 自动变化大小_【Unity UGUI InputField根据内容自动改变控件大小】-问答求助-【游戏蛮牛】-游戏出海,ar增强现实,虚拟现实,unity3d,unity3d教程下载首...

本文介绍了一个Unity3D的C#脚本,用于实现InputField控件根据输入的内容自动调整大小。该脚本实现了ILayoutElement接口,并通过监听onValueChanged事件来更新InputField的高度。在Awake()函数中保存了初始尺寸,在Update()函数中根据文本内容的长度计算新的宽度和高度,确保InputField始终能容纳所有文本。
摘要由CSDN通过智能技术生成

[C#] 纯文本查看 复制代码using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

using UnityEngine.EventSystems;

[RequireComponent(typeof(InputField))]

public class InputFieldScaler:MonoBehaviour,ILayoutElement

{

private Text textComponent

{

get

{

return this.GetComponent().textComponent;

}

}

public TextGenerationSettings GetTextGenerationSettings(Vector2 extents)

{

var settings = textComponent.GetGenerationSettings(extents);

settings.generateOutOfBounds = true;

return settings;

}

private RectTransform m_Rect;

private RectTransform rectTransform

{

get

{

if (m_Rect == null)

m_Rect = GetComponent();

retur

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值