Batch 1 - Scripts

This commit is contained in:
Rohan
2026-07-21 08:58:18 +05:30
parent 604c0c786a
commit 1dcd8bf80b
41 changed files with 655 additions and 13 deletions

View File

@@ -0,0 +1,95 @@
using UnityEngine;
using UnityEngine.UI;
public class EdgeIndicator : MonoBehaviour
{
[HideInInspector]
public EdgeTarget Target;
private RectTransform rect;
private Image image;
private RectTransform minimapRect;
private MinimapManager minimap;
private float radius;
public void Initialize(
EdgeTarget target,
RectTransform minimapRectTransform,
float edgePadding)
{
Target = target;
minimapRect = minimapRectTransform;
minimap = FindObjectOfType<MinimapManager>();
rect = GetComponent<RectTransform>();
image = GetComponent<Image>();
image.sprite = target.icon;
image.color = target.iconColor;
radius = Mathf.Min(minimapRect.rect.width, minimapRect.rect.height) * 0.5f - edgePadding;
}
private void Update()
{
if (Target == null)
{
Destroy(gameObject);
return;
}
if (minimap == null || minimap.MinimapCamera == null || minimap.Player == null)
return;
Camera cam = minimap.MinimapCamera;
// Position of the target in the minimap camera
Vector3 viewport = cam.WorldToViewportPoint(Target.transform.position);
// If target is visible inside minimap, hide the edge arrow
bool visible =
viewport.z > 0 &&
viewport.x >= 0f &&
viewport.x <= 1f &&
viewport.y >= 0f &&
viewport.y <= 1f;
if (visible)
{
image.enabled = false;
return;
}
image.enabled = true;
// Direction from player to target
Vector3 worldDir = Target.transform.position - minimap.Player.position;
Vector2 dir = new Vector2(worldDir.x, worldDir.z).normalized;
// If your minimap rotates, rotate direction too
if (minimap.rotateWithPlayer)
{
float angle = -minimap.Player.eulerAngles.y * Mathf.Deg2Rad;
float cos = Mathf.Cos(angle);
float sin = Mathf.Sin(angle);
dir = new Vector2(
dir.x * cos - dir.y * sin,
dir.x * sin + dir.y * cos
);
}
// Place arrow on edge of minimap
rect.anchoredPosition = dir * radius;
// Rotate arrow to point toward target
float rot = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
rect.localRotation = Quaternion.Euler(0, 0, rot - 90f);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 90eb04afe3bc588458146859ad793297

View File

@@ -0,0 +1,92 @@
using System.Collections.Generic;
using UnityEngine;
public class EdgeIndicatorManager : MonoBehaviour
{
public static EdgeIndicatorManager Instance;
[Header("References")]
public MinimapManager minimapManager;
public RectTransform edgeContainer;
public EdgeIndicator indicatorPrefab;
[Header("Settings")]
public float edgePadding = 18f;
public float refreshInterval = 1f;
private readonly Dictionary<EdgeTarget, EdgeIndicator> indicators =
new Dictionary<EdgeTarget, EdgeIndicator>();
float timer;
void Awake()
{
Instance = this;
}
void Start()
{
if (minimapManager == null)
minimapManager = FindObjectOfType<MinimapManager>();
RefreshTargets();
}
void Update()
{
timer += Time.deltaTime;
if (timer >= refreshInterval)
{
timer = 0;
RefreshTargets();
}
}
void RefreshTargets()
{
EdgeTarget[] targets = FindObjectsOfType<EdgeTarget>();
HashSet<EdgeTarget> currentTargets = new HashSet<EdgeTarget>(targets);
//-------------------------------------
// Remove destroyed targets
//-------------------------------------
List<EdgeTarget> remove = new List<EdgeTarget>();
foreach (var pair in indicators)
{
if (pair.Key == null || !currentTargets.Contains(pair.Key))
{
if (pair.Value != null)
Destroy(pair.Value.gameObject);
remove.Add(pair.Key);
}
}
foreach (var t in remove)
indicators.Remove(t);
//-------------------------------------
// Add new targets
//-------------------------------------
foreach (EdgeTarget target in targets)
{
if (indicators.ContainsKey(target))
continue;
EdgeIndicator arrow =
Instantiate(indicatorPrefab, edgeContainer);
arrow.Initialize(
target,
edgeContainer,
edgePadding);
indicators.Add(target, arrow);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c1c3c18764486f7478515f771cac46bb

View File

@@ -0,0 +1,17 @@
using UnityEngine;
public class EdgeTarget : MonoBehaviour
{
public enum TargetType
{
Enemy,
Vault,
Deposit,
Objective
}
[Header("Indicator")]
public TargetType targetType;
public Sprite icon;
public Color iconColor = Color.white;
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 262b041e5698df34b992d80ceab7e3b6