Пример #1
0
        public Polygon2D(List <Vector2Int> points)
        {
            this.points = points;

            if (!RoomTemplateLoaderGrid2D.IsClockwiseOriented(points.Select(x => x.ToCustomIntVector2()).ToList()))
            {
                this.points.Reverse();
            }

            CheckValidity();
        }
        public PolygonGrid2D GetOutline()
        {
            try
            {
                var polygon = RoomTemplateLoaderGrid2D.GetPolygonFromRoomTemplate(gameObject);

                return(polygon);
            }
            catch (ArgumentException)
            {
                return(null);
            }
        }
Пример #3
0
        public List <DoorLineGrid2D> GetDoorLines(DoorsGrid2D doors)
        {
            var doorLines = new List <DoorLineGrid2D>();

            try
            {
                var polygon = RoomTemplateLoaderGrid2D.GetPolygonFromRoomTemplate(doors.gameObject);

                if (polygon == null)
                {
                    return(null);
                }

                foreach (var originalLine in polygon.GetLines())
                {
                    var line     = originalLine;
                    var settings = GetSettings(line);

                    if (line.Length - settings.Margin1 - settings.Margin2 < settings.Length - 1)
                    {
                        continue;
                    }

                    if (!settings.Enabled)
                    {
                        continue;
                    }

                    if (line.GetDirection() == OrthogonalLineGrid2D.Direction.Bottom ||
                        line.GetDirection() == OrthogonalLineGrid2D.Direction.Left)
                    {
                        line = line.SwitchOrientation();
                    }

                    var doorLineTemp = line.Shrink(settings.Margin1, settings.Margin2);
                    var doorLine     = new DoorLineGrid2D()
                    {
                        From   = doorLineTemp.From.ToUnityIntVector3(),
                        To     = doorLineTemp.To.ToUnityIntVector3(),
                        Length = settings.Length,
                    };
                    doorLines.Add(doorLine);
                }
            }
            catch (ArgumentException)
            {
            }

            return(doorLines);
        }
Пример #4
0
        private RoomTemplateGrid2D GetRoomTemplate(GameObject roomTemplatePrefab)
        {
            if (prefabToRoomTemplateMapping.ContainsKey(roomTemplatePrefab))
            {
                return(prefabToRoomTemplateMapping[roomTemplatePrefab]);
            }

            if (RoomTemplateLoaderGrid2D.TryGetRoomTemplate(roomTemplatePrefab, out var roomTemplate, out var result))
            {
                prefabToRoomTemplateMapping.Add(roomTemplatePrefab, roomTemplate);
                return(roomTemplate);
            }

            Debug.LogError($"There was a problem when loading the room template \"{roomTemplatePrefab.name}\":");
            foreach (var error in result.Errors)
            {
                Debug.LogError($"- {error}");
            }

            throw new ConfigurationException("Please fix all the errors above and try again");
        }
 public static bool IsClockwiseOriented(IList <EdgarVector2Int> points)
 {
     return(RoomTemplateLoaderGrid2D.IsClockwiseOriented(points));
 }
 /// <summary>
 ///     Computes a room room template from a given room template game object.
 /// </summary>
 /// <param name="roomTemplatePrefab"></param>
 /// <param name="roomTemplate"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public static bool TryGetRoomTemplate(GameObject roomTemplatePrefab, out RoomTemplateGrid2D roomTemplate, out ActionResult result)
 {
     return(RoomTemplateLoaderGrid2D.TryGetRoomTemplate(roomTemplatePrefab, out roomTemplate, out result));
 }
 /// <summary>
 /// Gets all tiles that are not null in given tilemaps.
 /// </summary>
 /// <param name="tilemaps"></param>
 /// <returns></returns>
 public static HashSet <Vector3Int> GetUsedTiles(IEnumerable <Tilemap> tilemaps)
 {
     return(RoomTemplateLoaderGrid2D.GetUsedTiles(tilemaps));
 }
 /// <summary>
 /// Computes a polygon from points on given tilemaps.
 /// </summary>
 /// <param name="roomTemplate"></param>
 /// <returns></returns>
 public static PolygonGrid2D GetPolygonFromRoomTemplate(GameObject roomTemplate)
 {
     return(RoomTemplateLoaderGrid2D.GetPolygonFromRoomTemplate(roomTemplate));
 }
 /// <summary>
 /// Computes a polygon from points on given tilemaps.
 /// </summary>
 /// <param name="tilemaps"></param>
 /// <returns></returns>
 public static PolygonGrid2D GetPolygonFromTilemaps(ICollection <Tilemap> tilemaps)
 {
     return(RoomTemplateLoaderGrid2D.GetPolygonFromTilemaps(tilemaps));
 }
 /// <summary>
 /// Computes a polygon from its tiles.
 /// </summary>
 /// <param name="allPoints"></param>
 /// <returns></returns>
 public static PolygonGrid2D GetPolygonFromTiles(HashSet <Vector3Int> allPoints)
 {
     return(RoomTemplateLoaderGrid2D.GetPolygonFromTiles(allPoints));
 }