39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Подпись над объектом в мире (полка с канистрами, ноутбук, домкрат, мойка, площадка продажи).
|
||
|
|
/// Показывается GuideSystem, когда игрок рядом: что это и какой клавишей пользоваться.
|
||
|
|
/// </summary>
|
||
|
|
public class WorldLabel : MonoBehaviour
|
||
|
|
{
|
||
|
|
public static readonly List<WorldLabel> All = new List<WorldLabel>();
|
||
|
|
|
||
|
|
[TextArea] public string title = "Объект";
|
||
|
|
[TextArea] public string hint = "";
|
||
|
|
public Vector3 offset = new Vector3(0f, 1.2f, 0f);
|
||
|
|
public float showDistance = 9f;
|
||
|
|
|
||
|
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||
|
|
private static void ResetStatics() => All.Clear();
|
||
|
|
|
||
|
|
private void OnEnable()
|
||
|
|
{
|
||
|
|
if (!All.Contains(this)) All.Add(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnDisable() => All.Remove(this);
|
||
|
|
|
||
|
|
public Vector3 WorldPoint => transform.position + offset;
|
||
|
|
|
||
|
|
public static WorldLabel Add(GameObject go, string title, string hint, Vector3 offset, float distance = 9f)
|
||
|
|
{
|
||
|
|
WorldLabel l = go.GetComponent<WorldLabel>();
|
||
|
|
if (l == null) l = go.AddComponent<WorldLabel>();
|
||
|
|
l.title = title;
|
||
|
|
l.hint = hint;
|
||
|
|
l.offset = offset;
|
||
|
|
l.showDistance = distance;
|
||
|
|
return l;
|
||
|
|
}
|
||
|
|
}
|