Files
5.24BuYu/Assets/MyGame/aa/UI/Home/Sub/Service/DialogItem.cs
T
2026-06-02 14:57:23 +08:00

100 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class DialogItem : MonoBehaviour
{
public TextMeshProUGUI tMP_content_Top;
public TextMeshProUGUI tMP_content_Bottom;
public GameObject waitMessage;
public GameObject messageDefeated;
public Image title;
int top_buttonIndex = 0;
int maxWidth = 650;
public void SetMessage(string str)
{
List<string> msgBottom = new List<string>();
msgBottom.Add("");
int tempindex = 0;
for (int i = str.Length - 1; i >= 0; i--)
{
if (tempindex < 2)
{
if (tMP_content_Bottom.GetPreferredValues(msgBottom[tempindex]).x >= maxWidth)
{
tempindex++;
msgBottom.Add("");
}
}
else
{
if (tMP_content_Top.GetPreferredValues(msgBottom[tempindex]).x >= maxWidth)
{
tempindex++;
msgBottom.Add("");
}
}
msgBottom[tempindex] += str[i];
}
string temp = "";
bool istop = true;
int tempCount = 0;
if (msgBottom.Count >2)
{
for (int i = 0; i < str.Length; i++)
{
temp += str[i];
if (istop)
{
if (tMP_content_Top.GetPreferredValues(temp).x >= maxWidth)
{
temp += "\n";
tMP_content_Top.text += temp;
temp = "";
tempCount++;
if (tempCount>= msgBottom.Count - 2)
{
istop = false;
}
}
}
else
{
if (tMP_content_Bottom.GetPreferredValues(temp).x >= maxWidth|| i== str.Length-1)
{
temp += "\n";
tMP_content_Bottom.text += temp;
temp = "";
}
}
}
}
else
{
for (int i = 0; i < str.Length; i++)
{
temp += str[i];
if (tMP_content_Bottom.GetPreferredValues(temp).x >= maxWidth|| i==str.Length-1)
{
temp += "\n";
tMP_content_Bottom.text += temp;
temp = "";
}
}
}
}
}