80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using TMPro;
|
||
|
||
namespace RR.Common.Behaviour
|
||
{
|
||
public class Message : Sequencer
|
||
{
|
||
[SerializeField] private TextMeshProUGUI messageText;
|
||
[SerializeField] private RectTransform bubbleRectTransform;
|
||
[SerializeField] private Image speakerIconImage;
|
||
[SerializeField] private int maxWidth;
|
||
|
||
private string _text;
|
||
private Sprite _speakerIcon;
|
||
|
||
/// <summary>
|
||
/// Инициализирует сообщение с текстом и иконкой говорящего.
|
||
/// </summary>
|
||
/// <param name="text">Текст сообщения</param>
|
||
/// <param name="speakerIcon">Иконка (спрайт) говорящего персонажа</param>
|
||
public void Initialize(string text, Sprite speakerIcon = null)
|
||
{
|
||
_text = text;
|
||
_speakerIcon = speakerIcon;
|
||
|
||
if (_text != null)
|
||
{
|
||
messageText.text = _text;
|
||
}
|
||
|
||
// Устанавливаем иконку говорящего, если она передана
|
||
if (speakerIconImage)
|
||
{
|
||
if (_speakerIcon)
|
||
{
|
||
speakerIconImage.sprite = _speakerIcon;
|
||
speakerIconImage.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
speakerIconImage.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
|
||
if (actions.Count == 0)
|
||
{
|
||
SetDefaultActions();
|
||
}
|
||
|
||
InitializeSequence();
|
||
}
|
||
|
||
private void SetDefaultActions()
|
||
{
|
||
actions.Add(new MessageAppearAction()
|
||
{
|
||
startScale = 0f,
|
||
endScale = 1f,
|
||
transitionSpeed = 3f
|
||
});
|
||
|
||
actions.Add(new WaitAction()
|
||
{
|
||
duration = 2f
|
||
});
|
||
|
||
actions.Add(new MessageDisappearAction()
|
||
{
|
||
startScale = 1f,
|
||
endScale = 0f,
|
||
transitionSpeed = 3f
|
||
});
|
||
actions.Add(new DeleteGameObjectAction()
|
||
{
|
||
targetObject = gameObject
|
||
});
|
||
}
|
||
}
|
||
} |