-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomTooltip.cs
More file actions
57 lines (47 loc) · 1.48 KB
/
Copy pathCustomTooltip.cs
File metadata and controls
57 lines (47 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CustomTooltip : MonoBehaviour
{
[SerializeField]
private Text headerField;
[SerializeField]
private Text contentField;
[SerializeField]
private LayoutElement layoutElement;
[SerializeField]
private RectTransform rectTransform;
[SerializeField]
private int characterWrapLimit;
private void Update()
{
SetPosition();
}
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;
}
public void SetPosition()
{
Vector2 position = Input.mousePosition;
float pivotX = position.x / Screen.width;
float pivotY = position.y / Screen.height;
pivotX = (pivotX <= 0.5) ? 0.03f : 0.97f;
pivotY = (pivotY <= 0.5) ? 0.08f : 0.92f;
rectTransform.pivot = new Vector2(pivotX, pivotY);
transform.position = position;
}
}