106 lines
2.5 KiB
C#
Raw Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Unity
// Author : Kimch
// Created : 2020-05-31
// Description :
// Last Modified By : Kimch
// Last Modified On :
// ***********************************************************************
// <copyright file= "BubbleBoard" company="kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G
{
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class BubbleBoard : KUIWidget
{
[KUIFlag]
private Image _imgBubble;
[KUIFlag]
#pragma warning disable CS0649 // 从未对字段“BubbleBoard._tmpText”赋值字段将一直保持其默认值 null
private TextMeshProUGUI _tmpText;
#pragma warning restore CS0649 // 从未对字段“BubbleBoard._tmpText”赋值字段将一直保持其默认值 null
private RectTransform _rectTransform;
private RectTransform _parentRect;
private float _showDuration;
private void Awake()
{
SetViewData();
_rectTransform = this.GetComponent<RectTransform>();
_parentRect = this.transform.parent.GetComponent<RectTransform>();
}
public void Reset()
{
gameObject.SetActive(false);
}
public void SetContent(string text)
{
if (_tmpText != null)
{
_tmpText.gameObject.SetActive(true);
_tmpText.text = text;
}
}
public void SetDuration(float second)
{
_showDuration = second;
}
Transform _target;
public void SetTarget(Transform target)
{
_target = target;
}
Vector3 _position = Vector3.zero;
public void SetPosition(Vector3 worldposition, Vector2 offset = default)
{
_position = worldposition;
}
public void LateUpdate()
{
if (_showDuration > 0f)
{
_showDuration -= Time.unscaledDeltaTime;
if (_showDuration <= 0f)
{
BoardManager.Instance.ReturnBoard(this);
return;
}
}
if (_target)
{
_position = _target.position;
Vector3 screenPosition = RectTransformUtility.WorldToScreenPoint(Camera.main, _position);
RectTransformUtility.ScreenPointToLocalPointInRectangle(_parentRect, screenPosition, KUIRoot.RootCamera, out Vector2 localPoint);
_rectTransform.anchoredPosition = localPoint;
}
}
public void DisableThis()
{
this.gameObject.SetActive(false);
}
public void Init()
{
this.gameObject.SetActive(true);
_target = null;
_tmpText.text = string.Empty;
}
}
}