예제 #1
0
 /// <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);
 }
예제 #2
0
        /// <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);
        }
예제 #3
0
 /// <summary>
 /// Removes a LogisticsNetwork from the logistics system
 /// </summary>
 /// <param name="network"></param>
 public void UnregisterNetwork(LogisticsNetwork network)
 {
     networks.Remove(network);
 }