private void Start()
 {
     if (UpdatedLoadingState != null)
     {
         UpdatedLoadingState.Invoke(LoadingState.NotLoading);
     }
 }
    private void Update()
    {
        if (_isProcessingImg && !_isCheckingMap)
        {
            if (_isMapValid)
            {
                if (UpdatedLoadingState != null)
                {
                    UpdatedLoadingState.Invoke(LoadingState.Done);
                }
            }
            else
            {
                if (UpdatedLoadingState != null)
                {
                    UpdatedLoadingState.Invoke(LoadingState.Failed);
                }
            }

            _isProcessingImg = false;

            _isMapValid = false;
        }
    }
    /// <summary>
    ///     Processes a selected image file
    /// </summary>
    /// <param name="imagePath">The file path</param>
    private void ProcessImage(string imagePath)
    {
        try
        {
            if (File.Exists(imagePath))
            {
                if (UpdatedLoadingState != null)
                {
                    UpdatedLoadingState.Invoke(LoadingState.Loading);
                }

                // Create map texture
                var imageData = File.ReadAllBytes(imagePath);
                MapTexture = new Texture2D(2, 2)
                {
                    filterMode = FilterMode.Point
                };
                MapTexture.LoadImage(imageData);

                var imgWidth  = MapTexture.width;
                var imgHeight = MapTexture.height;
                if (imgHeight > imgWidth)
                {
                    throw new Exception("Flip image (width must be larger or same as height)");
                }
                var mapSize = Mathf.Max(imgWidth, imgHeight);

                // Check if map is valid and search city and quax positions
                var pixels = MapTexture.GetPixels32();
                _pathfindingManager.PathfindingGrid = new Grid(imgWidth, imgHeight);
                ThreadQueuer.Instance.StartThreadedAction(() => { CheckMapPixels(pixels, imgWidth); });

                // Resize map
                MapTexture.Resize(mapSize, mapSize);
                MapTexture.SetPixels32(0, 0, imgWidth, imgHeight, pixels);
                MapTexture.Apply();

                MapDataManager.Instance.MapTexture = MapTexture;

                if (MapTexture.width <= 2 && MapTexture.height <= 2)
                {
                    throw new Exception("Image is to small");
                }

                // Set GUI text
                _imageDimensionsText.text = imgWidth + "x" + imgHeight;
                _filePathText.text        = imagePath;

                // Update the MapDataManager instance
                MapDataManager.Instance.Dimensions = new Vector2Int(MapTexture.width, MapTexture.height);
            }
            else
            {
                throw new FileNotFoundException("File " + imagePath + " not found!");
            }
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
            if (UpdatedLoadingState != null)
            {
                UpdatedLoadingState.Invoke(LoadingState.Failed);
            }
        }
    }