void OnValidate()
        {
            tunnelRadius = Mathf.Max(1, tunnelRadius);

            if (carvedModule != null)
            {
                Coord extrema = carvedModule.GetMapSize() - Coord.One;
                for (int i = 0; i < entrances.Length; i++)
                {
                    MapEntrance entrance = entrances[i];

                    BoundaryPoint start = entrance.StartPoint;
                    BoundaryPoint end   = entrance.EndPoint;

                    var           startSide      = start.BoundarySide;
                    int           startMagnitude = ClampMagnitude(start, extrema);
                    BoundaryPoint newStart       = new BoundaryPoint(startSide, startMagnitude);

                    var           endSide      = end.BoundarySide;
                    int           endMagnitude = ClampMagnitude(end, extrema);
                    BoundaryPoint newEnd       = new BoundaryPoint(endSide, endMagnitude);

                    entrances[i] = new MapEntrance(newStart, newEnd);
                }
            }
        }
        /// <summary>
        /// Define a map entrance starting at the startpoint, of the given length. e.g. passing in (Left, 15) for the
        /// start point and 3 for the length will create an entrance between (Left, 15) and (Left, 18).
        /// </summary>
        public MapEntrance(BoundaryPoint startPoint, int length)
        {
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            this.startPoint = startPoint;
            endPoint        = new BoundaryPoint(startPoint.BoundarySide, startPoint.Magnitude + length);
        }
Exemple #3
0
        void OnValidate()
        {
            tunnelRadius = Mathf.Max(1, tunnelRadius);

            if (carvedModule != null && entrances != null)
            {
                Coord extrema;
                try
                {
                    extrema = carvedModule.GetMapSize() - Coord.one;
                }
                catch (InvalidOperationException)
                {
                    // this catches the case where a module is slotted into the entrance carver in the inspector,
                    // but the module is not fully configured and throws an exception when accessing its map size.
                    return;
                }
                for (int i = 0; i < entrances.Length; i++)
                {
                    MapEntrance entrance = entrances[i];

                    BoundaryPoint start = entrance.StartPoint;
                    BoundaryPoint end   = entrance.EndPoint;

                    var           startSide      = start.BoundarySide;
                    int           startMagnitude = ClampMagnitude(start, extrema);
                    BoundaryPoint newStart       = new BoundaryPoint(startSide, startMagnitude);

                    var           endSide      = end.BoundarySide;
                    int           endMagnitude = ClampMagnitude(end, extrema);
                    BoundaryPoint newEnd       = new BoundaryPoint(endSide, endMagnitude);

                    entrances[i] = new MapEntrance(newStart, newEnd);
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Define a map entrance starting at the startpoint, of the given length. e.g. passing in (Left, 15) for the
 /// start point and 3 for the length will create an entrance between (Left, 15) and (Left, 18).
 /// </summary>
 public MapEntrance(BoundaryPoint startPoint, int length)
 {
     this.startPoint = startPoint;
     endPoint        = new BoundaryPoint(startPoint.BoundarySide, startPoint.Magnitude + length);
 }
Exemple #5
0
 /// <summary>
 /// Define a map entrance between these two points. Note that start and end do not have to be on the same side.
 /// </summary>
 public MapEntrance(BoundaryPoint startPoint, BoundaryPoint endPoint)
 {
     this.startPoint = startPoint;
     this.endPoint   = endPoint;
 }
        static int ClampMagnitude(BoundaryPoint point, Coord extrema)
        {
            int max = point.IsHorizontal() ? extrema.x : extrema.y;

            return(Mathf.Clamp(point.Magnitude, 0, max));
        }