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 _boundsControllers = new List(); private const float DistanceLimit = 50f; public void Update() { if (Input.GetKeyDown(KeyCode.F10)) { _gameWorld = Singleton.Instance; _mainCamera = Camera.main; if (_gameWorld == null) { Debug.LogError($"[{nameof(HighlightController)}] GameWorld was null, skipping"); return; } if (_mainCamera != null && _mainCamera.gameObject.GetComponent() == null) { _mainCamera.gameObject.AddComponent(); } _boundsControllers = new List(); foreach (var mapZone in FindObjectsOfType().Select(x => x.gameObject).ToList()) { if (mapZone.GetComponent() == null) { mapZone.AddComponent(); } _boundsControllers.Add(mapZone.GetComponent()); } } if (Input.GetKeyDown(KeyCode.F9)) { if (_mainCamera == null) { return; } if (_alphaLabel == null) { _alphaLabel = GameObject.Find("AlphaLabel").GetComponent(); _alphaLabel.color = Color.green; _alphaLabel.fontSize = 22; _alphaLabel.font = Resources.Load("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(); if (trigger != null && _alphaLabel != null) { trigger.GetComponent().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().Id, boundsController.IsActive ? ColliderBoundsController.ActiveLineColor : ColliderBoundsController.InactiveLineColor); } } } }