65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
|
|
namespace RR.Common.Behaviour
|
|
{
|
|
public class Message : Sequencer
|
|
{
|
|
[SerializeField] private TextMeshProUGUI messageText;
|
|
[SerializeField] private RectTransform bubbleRectTransform;
|
|
[SerializeField] private int maxWidth;
|
|
|
|
private string _text;
|
|
|
|
public void Initialize(string text)
|
|
{
|
|
_text = text;
|
|
if (_text != null)
|
|
{
|
|
float width = Mathf.Ceil(_text.Length * 1.2f / 5f);
|
|
|
|
if (maxWidth > 0 && width > maxWidth)
|
|
{
|
|
width = maxWidth;
|
|
messageText.textWrappingMode = TextWrappingModes.Normal;
|
|
}
|
|
else
|
|
{
|
|
messageText.textWrappingMode = TextWrappingModes.NoWrap;
|
|
}
|
|
|
|
bubbleRectTransform.sizeDelta = new Vector2(width, bubbleRectTransform.sizeDelta.y);
|
|
messageText.text = _text;
|
|
}
|
|
|
|
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
|
|
});
|
|
}
|
|
}
|
|
} |