64 lines
1.8 KiB
C#
Executable File
64 lines
1.8 KiB
C#
Executable File
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MapManager : MonoBehaviour
|
|
{
|
|
private static MapManager instance;
|
|
public static MapManager Instance => instance;
|
|
[SerializeField] static List<NavPoint> _navPoints;
|
|
public static List<NavPoint> NavPoints { get => _navPoints; private set => _navPoints = value; }
|
|
public static Dictionary<int, NavPoint> IDToNavPoint {get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance is null)
|
|
instance = this;
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
Debug.LogError("Only 1 Instance");
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
var navPointSet = GameObject.Find("NavPoint Set");
|
|
var count = navPointSet.transform.childCount;
|
|
for (int i=0; i < count; i++)
|
|
NavPoints.Add(navPointSet.transform.GetChild(i)
|
|
.gameObject.GetComponent<NavPoint>());
|
|
|
|
NavPointSetToID();
|
|
}
|
|
|
|
private void NavPointSetToID()
|
|
{
|
|
int i = 0;
|
|
foreach (var navPoint in NavPoints)
|
|
{
|
|
IDToNavPoint.Add(i, navPoint);
|
|
navPoint.PointId = i;
|
|
i++;
|
|
}
|
|
}
|
|
|
|
public static void AddDeathAttributeToPoints(int startPoint, int endPoint,
|
|
float allDistance, float remainingDistance)
|
|
{
|
|
var startNavPoint = IDToNavPoint[startPoint];
|
|
var endNavPoint = IDToNavPoint[endPoint];
|
|
float coef;
|
|
try
|
|
{
|
|
coef = remainingDistance / allDistance;
|
|
}
|
|
catch (System.ArithmeticException)
|
|
{
|
|
Debug.LogError("Path Length is zero");
|
|
return;
|
|
}
|
|
startNavPoint.DeathAttr += 1 - coef;
|
|
endNavPoint.DeathAttr += coef;
|
|
}
|
|
}
|