33 lines
924 B
C#
33 lines
924 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Events;
|
|
using System;
|
|
using UnityEditor;
|
|
|
|
public class UI_MatterItem : BaseItem
|
|
{
|
|
public TextMeshProUGUI label;
|
|
public Toggle selfToggle;
|
|
public RectTransform result;
|
|
|
|
public void Init(string labelData, UnityAction<bool> callBack)
|
|
{
|
|
label.text = labelData;
|
|
selfToggle.onValueChanged.AddListener(callBack);
|
|
AdjustImageWidth(label,GetComponent<RectTransform>(),10f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据文字数量改变 背景 大小
|
|
/// </summary>
|
|
/// <param name="contentText"></param>
|
|
public void AdjustImageWidth(TextMeshProUGUI contentText, RectTransform _bg, float height)
|
|
{
|
|
float preferredHeight = contentText.preferredHeight;
|
|
_bg.sizeDelta = new Vector2( _bg.sizeDelta.x, preferredHeight+height);
|
|
}
|
|
}
|