add modal window UI

This commit is contained in:
Vladimir Koshevarov
2022-12-06 11:25:30 +02:00
parent 3ccfc6a353
commit 71d9f79442
12 changed files with 2138 additions and 49 deletions
+56
View File
@@ -0,0 +1,56 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[ExecuteInEditMode()]
public class ToolTip : MonoBehaviour
{
public TextMeshProUGUI headerField;
public TextMeshProUGUI contentField;
public LayoutElement layoutElement;
public int characterWrapLimit;
public RectTransform rectTransform;
private void Awake()
{
rectTransform = GetComponent<RectTransform>();
}
// Start is called before the first frame update
public void SetText(string content, string header = "")
{
if (string.IsNullOrEmpty(header))
{
headerField.gameObject.SetActive(false);
}
else
{
headerField.gameObject.SetActive(true);
headerField.text = header;
}
contentField.text = content;
int headerLength = headerField.text.Length;
int contentLength = contentField.text.Length;
layoutElement.enabled = (headerLength > characterWrapLimit || contentLength > characterWrapLimit);
}
// Update is called once per frame
void Update()
{
if (Application.isEditor)
{
int headerLength = headerField.text.Length;
int contentLength = contentField.text.Length;
layoutElement.enabled = (headerLength > characterWrapLimit || contentLength > characterWrapLimit);
}
Vector2 position = Input.mousePosition;
float pivotX = position.x / Screen.width;
float pivotY = position.y / Screen.height;
rectTransform.pivot = new Vector2(pivotX, pivotY);
transform.position = position;
}
}