Tz2/Assets/Scripts/TopicComponent.cs

58 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using DefaultNamespace.ProcessMode;
using MotionFramework;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class TopicComponent : MonoBehaviour
{
[SerializeField] private TMP_InputField text;
public TMP_Text textInp;
public GameObject rec;
public void Init()
{
Debug.Log("初始化弹窗消息");
MotionEngine.GetModule<ProcessManager>().OnStepProcessMessage += OnStepProcessDescriptionMessage;
}
private void OnStepProcessDescriptionMessage(string message)
{
Debug.Log("弹窗的消息---->" + message);
// 先将滚动条重置到最顶上
ScrollToTop();
// 设置文本内容
text.text = message+" "+"\n";
}
/// <summary>
/// 设置textInp的RectTransform的top和bottom都为0
/// </summary>
private void ScrollToTop()
{
if (textInp != null)
{
RectTransform rectTransform = textInp.rectTransform;
RectTransform rectTransform2 = rec.transform.Find("Caret").GetComponent<RectTransform>();
// 设置top和bottom都为0
rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, 0f); // bottom = 0
rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x, 0f); // top = 0
rectTransform2.offsetMin = new Vector2(rectTransform.offsetMin.x, 0f); // bottom = 0
rectTransform2.offsetMax = new Vector2(rectTransform.offsetMax.x, 0f); // top = 0
Debug.Log("TopicComponent: textInp的RectTransform已设置 - top和bottom都为0");
}
else
{
Debug.LogWarning("TopicComponent: textInp为空无法设置RectTransform");
}
}
}