107 lines
4.0 KiB
C#
107 lines
4.0 KiB
C#
using System.Collections.Generic;
|
|
using Comfort.Common;
|
|
using EFT;
|
|
using System.Linq;
|
|
using Terkoiz.MapZoneHighlighter.BoundedBoxes;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace Terkoiz.MapZoneHighlighter
|
|
{
|
|
public class HighlightController : MonoBehaviour
|
|
{
|
|
private static GameWorld _gameWorld;
|
|
private static Camera _mainCamera;
|
|
private static TextMeshProUGUI _alphaLabel;
|
|
private static List<ColliderBoundsController> _boundsControllers = new List<ColliderBoundsController>();
|
|
|
|
private const float DistanceLimit = 50f;
|
|
|
|
public void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.F10))
|
|
{
|
|
_gameWorld = Singleton<GameWorld>.Instance;
|
|
_mainCamera = Camera.main;
|
|
|
|
if (_gameWorld == null)
|
|
{
|
|
Debug.LogError($"[{nameof(HighlightController)}] GameWorld was null, skipping");
|
|
return;
|
|
}
|
|
|
|
if (_mainCamera != null && _mainCamera.gameObject.GetComponent<ColliderBoundsRenderer>() == null)
|
|
{
|
|
_mainCamera.gameObject.AddComponent<ColliderBoundsRenderer>();
|
|
}
|
|
|
|
_boundsControllers = new List<ColliderBoundsController>();
|
|
foreach (var mapZone in FindObjectsOfType<EFT.Interactive.TriggerWithId>().Select(x => x.gameObject).ToList())
|
|
{
|
|
if (mapZone.GetComponent<ColliderBoundsController>() == null)
|
|
{
|
|
mapZone.AddComponent<ColliderBoundsController>();
|
|
}
|
|
|
|
_boundsControllers.Add(mapZone.GetComponent<ColliderBoundsController>());
|
|
}
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.F9))
|
|
{
|
|
if (_mainCamera == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_alphaLabel == null)
|
|
{
|
|
_alphaLabel = GameObject.Find("AlphaLabel").GetComponent<TextMeshProUGUI>();
|
|
_alphaLabel.color = Color.green;
|
|
_alphaLabel.fontSize = 22;
|
|
_alphaLabel.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/ARIAL SDF");
|
|
}
|
|
|
|
_alphaLabel.text = string.Empty;
|
|
|
|
foreach (var boundsController in _boundsControllers)
|
|
{
|
|
boundsController.IsActive = false;
|
|
}
|
|
|
|
var ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
|
|
if (Physics.Raycast(ray, out var hitPoint, DistanceLimit, LayerMask.GetMask("Triggers")))
|
|
{
|
|
var trigger = hitPoint.transform.gameObject.GetComponent<EFT.Interactive.TriggerWithId>();
|
|
if (trigger != null && _alphaLabel != null)
|
|
{
|
|
trigger.GetComponent<ColliderBoundsController>().IsActive = true;
|
|
_alphaLabel.text = $"{trigger.GetType().Name.Split('.').Last()} Id: {trigger.Id}";
|
|
Debug.LogError(_alphaLabel.text);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnGUI()
|
|
{
|
|
if (_mainCamera == null || _gameWorld == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var boundsController in _boundsControllers)
|
|
{
|
|
if (!boundsController.IsOnScreen || boundsController.DistanceToCamera > DistanceLimit)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
UIDrawingUtil.DrawString(
|
|
new Vector2(boundsController.ScreenPosition.x, boundsController.ScreenPosition.y),
|
|
boundsController.transform.GetComponent<EFT.Interactive.TriggerWithId>().Id,
|
|
boundsController.IsActive ? ColliderBoundsController.ActiveLineColor : ColliderBoundsController.InactiveLineColor);
|
|
}
|
|
}
|
|
}
|
|
} |