| | |
| | | [RequireComponent(typeof(RectTransform))] |
| | | public class ChatBulletItem : MonoBehaviour |
| | | { |
| | | [SerializeField] ImageEx contentImage; |
| | | [SerializeField] RectTransform rectContent; |
| | | [SerializeField] RichText contentText; |
| | | |
| | | [SerializeField] ImageEx sysImage; |
| | | [SerializeField] RectTransform rectSys; |
| | | [SerializeField] RichText sysText; |
| | | // 背景图左右的额外留白 (x:左边距, y:右边距) |
| | | [SerializeField] Vector2 padding = new Vector2(50f, 50f); |
| | | [SerializeField] Vector2 sysPadding = new Vector2(70f, 70f); |
| | | private RectTransform rectTrans; |
| | | private RectTransform imageRect; |
| | | private RectTransform imageSysRect; |
| | | private GameObject sourcePrefab; |
| | | private Tweener moveTweener; |
| | | private Action<ChatBulletItem> onFinishCallback; |
| | |
| | | private void Awake() |
| | | { |
| | | rectTrans = GetComponent<RectTransform>(); |
| | | imageRect = contentImage.rectTransform; |
| | | imageSysRect = sysImage.rectTransform; |
| | | } |
| | | |
| | | public void Init(bool isSys, string content, ArrayList infoList, Color color, float speed, Vector2 startPos, float leftBoundary, GameObject prefab, Action<ChatBulletItem> onFinish) |
| | | { |
| | | if (rectTrans == null) |
| | | rectTrans = GetComponent<RectTransform>(); |
| | | contentImage.SetActive(!isSys); |
| | | sysImage.SetActive(isSys); |
| | | rectContent.SetActive(!isSys); |
| | | rectSys.SetActive(isSys); |
| | | |
| | | if (infoList != null) |
| | | { |
| | |
| | | // 保持原有的高度 |
| | | currentHeight = rectTrans.sizeDelta.y; |
| | | // 设置背景图(ContentImage)的大小 |
| | | if (imageRect != null) |
| | | { |
| | | imageRect.sizeDelta = new Vector2(totalWidth, currentHeight); |
| | | } |
| | | rectContent.sizeDelta = new Vector2(totalWidth, currentHeight); |
| | | } |
| | | else |
| | | { |
| | |
| | | // 图片的高度 |
| | | currentHeight = 39; |
| | | // 设置背景图(ContentImage)的大小 |
| | | if (imageSysRect != null) |
| | | { |
| | | imageSysRect.sizeDelta = new Vector2(totalWidth, currentHeight); |
| | | } |
| | | rectSys.sizeDelta = new Vector2(totalWidth, currentHeight); |
| | | } |
| | | |
| | | |