Пример #1
0
        /// <summary>
        ///     Checks a 2x2 <see cref="MapSquare" /> outside of the Quadtree
        /// </summary>
        /// <param name="sw_point">The South-West (Bottom-Left) point of the square</param>
        private void CheckSpecialSquare(Vector2Int sw_point)
        {
            // Execute from main thread
            ThreadQueuer.Instance.QueueMainThreadAction(() =>
            {
                var isWalkable = true;

                var containsWater = false;
                var containsLand  = false;

                var pixels = new List <Color>();

                for (var x = sw_point.X; x < sw_point.X + 2; x++)
                {
                    for (var y = sw_point.Y; y < sw_point.Y + 2; y++)
                    {
                        Color pixel;
                        if (MapDataManager.Instance.MapTexture.width > x &&
                            MapDataManager.Instance.MapTexture.height > y)
                        {
                            pixel = MapDataManager.Instance.MapTexture.GetPixel(x, y);
                        }
                        else
                        {
                            pixel = new Color(1, 1, 1, 1);
                        }

                        pixels.Add(pixel);
                    }
                }

                var specialSquare = new MapSquare(sw_point, 2)
                {
                    MapType = MapTypes.Ground
                };

                foreach (var pixel in pixels)
                {
                    var pixelType = pixel.GetMapType();

                    if (pixelType == MapTypes.Water && !containsWater)
                    {
                        containsWater = true;
                    }
                    else if (pixelType != MapTypes.Water && !containsLand)
                    {
                        containsLand = true;
                    }
                    if (containsWater && containsLand)
                    {
                        break;
                    }
                }

                if (!containsLand && containsWater)
                {
                    specialSquare.MapType = MapTypes.Water;
                    isWalkable            = false;
                }

                RegisterNewNode(specialSquare);

                if (CheckedSpecialSquare != null)
                {
                    CheckedSpecialSquare.Invoke(isWalkable, sw_point);
                }
            });
        }