Answer the question
In order to leave comments, you need to log in
Is it possible to assign a composite value to a field of type string in the inspector?
I want to make tooltips that will appear when hovering over an interface element and will contain some information. I use two classes for this:
public class TooltipSystem : MonoBehaviour
{
private static TooltipSystem current;
public Tooltip tooltip;
public void Awake()
{
current = this;
}
public static void Show(string content, string header = "")
{
current.tooltip.SetText(content, header);
current.tooltip.SetPosition();
current.tooltip.gameObject.SetActive(true);
}
public static void Hide()
{
current.tooltip.gameObject.SetActive(false);
}
}
class TooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public string content;
public string header;
public void OnPointerEnter(PointerEventData eventData)
{
TooltipSystem.Show(content, header);
}
public void OnPointerExit(PointerEventData eventData)
{
TooltipSystem.Hide();
}
}
string content = $"Heal recover {Player.MaxHealth / 10} HP.}
Answer the question
In order to leave comments, you need to log in
Yes, you can implement the unit's OnValidate method for this. It will work in the editor when the prefab is changed or loaded.
#if UNITY_EDITOR
private void OnValidate()
{
if (content == "")
content = $"Heal recover {Player.MaxHealth / 10} HP.}";
}
#endif
content = "Heal recover {0} HP";
...
var result = string.Format(content, 42);
similar to: https://docs.unity3d.com/ScriptReference/TooltipAt...
and other attributes: https://habr.com/ru/post/331042/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question