Hello.
Example of how to change the position of tooltips:
using UnityEngine;
public class ModifyDrawTooltipsAlways:MonoBehaviour
{
public float offsetY;
private OnlineMaps map;
private OnlineMapsControlBase control;
private bool isTileset;
private GUIStyle tooltipStyle;
private void Start()
{
map = OnlineMaps.instance;
control = OnlineMapsControlBase.instance;
isTileset = control is OnlineMapsTileSetControl;
OnlineMapsMarkerBase.OnMarkerDrawTooltip += OnMarkerDrawTooltip;
tooltipStyle = new GUIStyle
{
normal =
{
background = map.tooltipBackgroundTexture,
textColor = new Color32(230, 230, 230, 255)
},
border = new RectOffset(8, 8, 8, 8),
margin = new RectOffset(4, 4, 4, 4),
wordWrap = true,
richText = true,
alignment = TextAnchor.MiddleCenter,
stretchWidth = true,
padding = new RectOffset(0, 0, 3, 3)
};
}
private void OnGUITooltip(GUIStyle style, string text, Vector2 position)
{
GUIContent tip = new GUIContent(text);
Vector2 size = style.CalcSize(tip);
GUI.Label(new Rect(position.x - size.x / 2 - 5, Screen.height - position.y - size.y - 20 + offsetY, size.x + 10, size.y + 5), text, style);
}
private void OnMarkerDrawTooltip(OnlineMapsMarkerBase markerBase)
{
double tlx, tly, brx, bry;
map.GetCorners(out tlx, out tly, out brx, out bry);
if (brx < tlx) brx += 360;
double mx, my;
markerBase.GetPosition(out mx, out my);
OnlineMapsMarker marker = markerBase as OnlineMapsMarker;
GUIStyle style = new GUIStyle(tooltipStyle);
if (isTileset)
{
Vector2 tilesetSize = map.tilesetSize;
Vector3 p1 = OnlineMapsTileSetControl.instance.GetWorldPositionWithElevation(mx, my, tlx, tly, brx, bry);
Vector3 p2 = p1 + new Vector3(0, 0, tilesetSize.y / map.tilesetHeight * marker.height * marker.scale);
Vector2 screenPoint1 = OnlineMapsTileSetControl.instance.activeCamera.WorldToScreenPoint(p1);
Vector2 screenPoint2 = OnlineMapsTileSetControl.instance.activeCamera.WorldToScreenPoint(p2);
float yOffset = (screenPoint1.y - screenPoint2.y) * transform.localScale.x - 10;
OnGUITooltip(style, marker.label, screenPoint1 + new Vector2(0, yOffset));
}
else
{
Rect rect = marker.screenRect;
OnGUITooltip(style, marker.label, new Vector2(rect.x + rect.width / 2, rect.y + rect.height + 5));
}
}
}
Kind Regards,
Infinity Code Team.
Boost your productivity a lot and immediately using
Ultimate Editor Enhancer.
Trial and non-commerce versions available.