Esempio n. 1
0
        public void UpdateField(int x, int y, int _, uint color, int cost)
        {
            x   %= Constants.MiniMapSectorSize;
            y   %= Constants.MiniMapSectorSize;
            cost = GetWaypointsSafe(cost);

            int texelX = x, texelY = Constants.MiniMapSectorSize - y - 1;

            Texture2D.SetPixel(texelX, texelY, Colors.ColorFromARGB(color));

            byte costb = (byte)cost;

            if (costb > 210)
            {
                costb = 210;
            }
            WaypointsTexture2D.SetPixel(texelX, texelY, new Color32 {
                r = costb, g = costb, b = costb, a = 255
            });

            _cost[y * Constants.MiniMapSectorSize + x] = cost;
            MinCost = System.Math.Min(MinCost, cost);
            UncommittedPixelChanges = true;
            Dirty = true;
        }
Esempio n. 2
0
 public void ApplyPixelChanges()
 {
     if (UncommittedPixelChanges)
     {
         UncommittedPixelChanges = false;
         Texture2D.Apply();
         WaypointsTexture2D.Apply();
     }
 }
Esempio n. 3
0
        public bool LoadSharedObject()
        {
            var sectorName = GetSectorName(this);

            var colorPath    = Path.Combine(Application.persistentDataPath, "MiniMap/MiniMap_Color_" + sectorName + ".png");
            var waypointPath = Path.Combine(Application.persistentDataPath, "MiniMap/MiniMap_WaypointCost_" + sectorName + ".png");

            if (!File.Exists(colorPath) && !File.Exists(waypointPath))
            {
                return(false);
            }

            if (File.Exists(colorPath))
            {
                var colorBytes = File.ReadAllBytes(colorPath);
                if (!Texture2D.LoadImage(colorBytes))
                {
                    return(false);
                }

                Texture2D.Apply();
            }

            if (File.Exists(waypointPath))
            {
                var waypointBytes = File.ReadAllBytes(waypointPath);
                if (!WaypointsTexture2D.LoadImage(waypointBytes))
                {
                    return(false);
                }

                WaypointsTexture2D.Apply();
                for (int x = 0; x < Constants.MiniMapSectorSize; x++)
                {
                    for (int y = 0; y < Constants.MiniMapSectorSize; y++)
                    {
                        Color32 c    = WaypointsTexture2D.GetPixel(x, y);
                        int     cost = c.r;
                        if (cost >= 210)
                        {
                            cost = Constants.PathCostObstacle;
                        }

                        MinCost = Mathf.Min(MinCost, c.r);
                        _cost[(Constants.MiniMapSectorSize - y - 1) * Constants.MiniMapSectorSize + x] = c.r;
                    }
                }
            }

            UncommittedPixelChanges = false;
            return(true);
        }
Esempio n. 4
0
        public void SaveSharedObject()
        {
            if (!Directory.Exists(Path.Combine(Application.persistentDataPath, "MiniMap")))
            {
                Directory.CreateDirectory(Path.Combine(Application.persistentDataPath, "MiniMap"));
            }

            byte[] colorTexBytes     = Texture2D.EncodeToPNG();
            byte[] waypointsTexBytes = WaypointsTexture2D.EncodeToPNG();

            var sectorName    = GetSectorName(this);
            var colorPath     = Path.Combine(Application.persistentDataPath, "MiniMap/MiniMap_Color_" + sectorName + ".png");
            var waypointsPath = Path.Combine(Application.persistentDataPath, "MiniMap/MiniMap_WaypointCost_" + sectorName + ".png");

            File.WriteAllBytes(colorPath, colorTexBytes);
            File.WriteAllBytes(waypointsPath, waypointsTexBytes);
            Dirty = false;
        }