void OnGUI()
    {
        //GUI.skin = Skin;

        if (GUI.Button(new Rect(5, 5, 160, 35), "Load map"))
        {
            string[] path = StandaloneFileBrowser.OpenFilePanel("Open trk file", CrashdayPath + "/user/", "trk", false);
            if (path.Length != 0 && path[0].Length != 0)
            {
                PlayerPrefs.SetString("lastmappath", path[0]);
                Track = MapParser.ReadMap(path[0]);
                GetComponent <TrackManager>().LoadTrack(Track);
            }
        }

        if (GUI.Button(new Rect(175, 5, 160, 35), "Save map"))
        {
            string path = StandaloneFileBrowser.SaveFilePanel("Save trk file", CrashdayPath + "/user/", "my_awesome_track", "trk");
            if (path.Length != 0)
            {
                MapParser.SaveMap(GetComponent <TrackManager>().CurrentTrack, path);
            }
        }
    }
    public void SaveMenu_works(bool Quicksave = false)
    {
        //Debug.Log("SaveMenu:" + path);
        if (NameOfTrack.text == "")
        {
            return;
        }
        string path;

        if (Quicksave)
        {
            path = Consts.LoadLastFolderPath();
        }
        else
        {
            string[] originalpath = StandaloneFileBrowser.OpenFolderPanel("Select folder to save this track in ..", Consts.LoadLastFolderPath(), false);
            path = originalpath[0];
        }

        Consts.SaveLastFolderPath(path);

        path += "\\" + NameOfTrack.text + ".trk";

        Consts.Trackname = NameOfTrack.text;
        nazwa_toru.text  = NameOfTrack.text;
        // save currently set gravity value to static variable to remember last dropdown selection
        Consts.GravityValue = GravityEffectDropdown.value * 1000 * ((plusOn.isOn == true) ? 1 : -1);

        // Save terrain
        for (int y = 0; y <= 4 * Consts.TRACK.Height; y++)
        {
            for (int x = 0; x <= 4 * Consts.TRACK.Width; x++)
            {
                int i = x + 4 * y * Consts.TRACK.Width + y;
                Consts.TRACK.Heightmap[4 * Consts.TRACK.Height - y][x] = Consts.current_heights[i] * 5 + Consts.GravityValue;
            }
        }

        // Prepare track tiles arrays
        for (int z = 0; z < Consts.TRACK.Height; z++)
        {
            for (int x = 0; x < Consts.TRACK.Width; x++)
            {
                Consts.TRACK.TrackTiles[z][x].Set(0, 0, 0, 0);
            }
        }

        Consts.TRACK.FieldFiles.Clear();
        Consts.TRACK.FieldFiles.Add("field.cfl");
        Consts.TRACK.FieldFilesNumber = 1;
        List <QuarterData> QuartersToSave = new List <QuarterData>();

        // Save tiles
        for (int z = 0; z < Consts.TRACK.Height; z++)
        {
            for (int x = 0; x < Consts.TRACK.Width; x++)
            {
                if (Consts.TilePlacementArray[z, x].Name != null)
                {
                    ushort fieldId  = SetAndGetFieldId(Consts.TilePlacementArray[z, x].Name);
                    byte   mirror   = (byte)(Consts.TilePlacementArray[z, x].Inversion ? 1 : 0);
                    byte   rotation = (byte)(Consts.TilePlacementArray[z, x].Rotation / 90);
                    if (mirror == 1 && rotation != 0)
                    {
                        rotation = (byte)(4 - rotation);
                    }
                    byte       height = Consts.TilePlacementArray[z, x].Height;
                    Vector2Int dim    = TileManager.GetRealDims(Consts.TilePlacementArray[z, x].Name, (rotation == 1 || rotation == 3) ? true : false);
                    //Base part - Left Top
                    Consts.TRACK.TrackTiles[Consts.TRACK.Height - 1 - z][x].Set(fieldId, rotation, mirror, height);
                    //Left Bottom
                    if (dim.y == 2)
                    {
                        //Consts.TRACK.TrackTiles[Consts.TRACK.Height - 1 - z][x].Set(65471, rotacja, inwersja, height);
                        QuartersToSave.Add(new QuarterData(Consts.TRACK.Height - z, x, 1, rotation, mirror, height));
                    }
                    //Right top
                    if (dim.x == 2)
                    {
                        //  Consts.TRACK.TrackTiles[Consts.TRACK.Height - 1 - z + 1 - dim.y][x + 1].Set(65472, rotacja, inwersja, height);
                        QuartersToSave.Add(new QuarterData(Consts.TRACK.Height - 1 - z, x + 1, 2, rotation, mirror, height));
                    }
                    //Right bottom
                    if (dim.x == 2 && dim.y == 2)
                    {
                        //  Consts.TRACK.TrackTiles[Consts.TRACK.Height - 1 - z][x + 1].Set(65470, rotacja, inwersja, height);
                        QuartersToSave.Add(new QuarterData(Consts.TRACK.Height - z, x + 1, 0, rotation, mirror, height));
                    }
                }
            }
        }
        foreach (QuarterData q in QuartersToSave)
        {
            try
            {
                if (Consts.TRACK.TrackTiles[q.Y][q.X].FieldId == 0)
                {
                    Consts.TRACK.TrackTiles[q.Y][q.X].Set(q.ID == 0 ? (ushort)65470 : q.ID == 1 ? (ushort)65471 : (ushort)65472, q.rotation, q.mirror, q.height);
                }
            }
            catch
            {
                Debug.LogWarning("Index out of range: Y,X=" + q.Y + " " + q.X + " ");
            }
        }
        Debug.Log("saveto:" + path);
        MapParser.SaveMap(Consts.TRACK, path);
        save.SetActive(false);
        StartCoroutine(DisplayMessage());
    }