/// <summary> /// Adds a LogisticsNetwork to the logistics system /// </summary> /// <param name="network"></param> public void RegisterNetwork(LogisticsNetwork network) { if (networks.Contains(network)) { throw new InvalidOperationException("Network already registered"); } networks.Add(network); }
/// <summary> /// Finds the active logistics node nearest to the given position /// </summary> /// <param name="position"></param> /// <returns>The nearest active network</returns> public LogisticsNetwork FindNearestNetwork(Vector3 position) { LogisticsNetwork closest = null; float closestDist = float.PositiveInfinity; foreach (var network in networks) { if (network == null) { continue; } var diff = position - network.transform.position; var dist = diff.sqrMagnitude; if (dist < closestDist) { closest = network; closestDist = dist; } } return(closest); }
/// <summary> /// Removes a LogisticsNetwork from the logistics system /// </summary> /// <param name="network"></param> public void UnregisterNetwork(LogisticsNetwork network) { networks.Remove(network); }