public void SaveMapClicked()
        {
            //string path = GetSelectedPath();

            //using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create)))
            //{
            //    writer.Write(mapFileVersion);
            //    _hexMapEditor.hexGrid.Save(writer);
            //}

            HexGridData hexGridData = new HexGridData();

            _hexMapEditor.hexGrid.Save(hexGridData);

            //save to the database
            Map map = new Map();

            map.HexGridData = hexGridData;
            map.Name        = MapItemName.Value;

            //we'll always disable the old one and insert a new one


            ContentViewSwitcher.SwitchTo("MainRegion");
        }
Beispiel #2
0
        public WorldEditor(HexGrid hexGrid)
        {
            this.hexGridColiderer = hexGrid.hexGridColiderer;
            this.hexGridRenderer  = hexGrid.hexGridRenderer;

            this.MapData = hexGrid.MapData;
        }
Beispiel #3
0
    private void init()
    {
        hexGridData  = new HexGridData(20, 20, 3.0f); //Debug: default values 65k vertices max per mesh
        hexGridMesh  = new HexGridMesh(hexGridData);
        meshFilter   = this.gameObject.AddComponent <MeshFilter>();
        meshRenderer = this.gameObject.AddComponent <MeshRenderer>();
        meshCollider = this.gameObject.AddComponent <MeshCollider>();
        zeroPlane    = new Plane();

        updateMesh();
    }
Beispiel #4
0
    public void Save(HexGridData hexGridData)
    {
        hexGridData.CellCountX = cellCountX;
        hexGridData.CellCountZ = cellCountZ;

        hexGridData.Cells = new List <HexCellData>();

        for (int i = 0; i < cells.Length; i++)
        {
            HexCellData hexCellData = new HexCellData();
            cells[i].Save(hexCellData);
            hexGridData.Cells.Add(hexCellData);
        }
    }
Beispiel #5
0
        static public void MapSaverXMLFile(HexGridData MapToSave, string path, SaveType saveType)
        {
            CInfo.NumberFormat.NumberDecimalSeparator = ".";

            XDocument XmlDoc = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement("MapDatas"));

            XElement MapData = new XElement("MapData", new XAttribute("name", MapToSave.name));

            XmlDoc.Root.Add(MapData);

            MapData.Add(new XElement("width", MapToSave.width));
            MapData.Add(new XElement("height", MapToSave.height));

            MapData.Add(new XElement("cellSize", MapToSave.cellSize));
            MapData.Add(new XElement("cellPadding", MapToSave.cellPadding));

            MapData.Add(new XElement("accuracyOfApproximation", MapToSave.AccurcyOfApproximation));

            MapData.Add(new XElement("materialPath", MapToSave.materialPath));

            XElement HeightMap = new XElement("HeightMap", new XAttribute("type", saveType.ToString()));


            XElement ColorMap = new XElement("ColorMap", new XAttribute("type", SaveType.overrideSave));

            switch (saveType)
            {
            case SaveType.defaultSave:
                MapSaverXMLFile_DefaultSave(ref HeightMap, ref ColorMap, MapToSave);
                break;

            case SaveType.overrideSave:
                MapSaverXMLFile_OverrideSave(ref HeightMap, ref ColorMap, MapToSave);
                break;
            }
            MapData.Add(HeightMap);
            MapData.Add(ColorMap);

            XmlDoc.Save(Application.dataPath + "/" + "Resources/" + path + ".xml");
            // AssetDatabase.SaveAssets();
            // AssetDatabase.Refresh();
        }
Beispiel #6
0
    public void SaveMap(string path)
    {
        HexCellData[] cellsData = new HexCellData[cells.Length];

        for (int i = 0; i < cells.Length; i++)
        {
            HexCellData data = HexCell.TurnIntoCellData(cells[i]);
            cellsData[i] = data;
        }

        HexGridData mapData = new HexGridData(cellsData);

        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Open(path, FileMode.OpenOrCreate);

        bf.Serialize(file, mapData);
        file.Close();

        Debug.Log("Save ended, you can now change scenes");
    }
Beispiel #7
0
    public void LoadMap(string path)
    {
        if (!File.Exists(path))
        {
            return;                    //Redundante pero por si acaso
        }
        BinaryFormatter bf      = new BinaryFormatter();
        FileStream      file    = File.Open(path, FileMode.Open);
        HexGridData     mapData = (HexGridData)bf.Deserialize(file);

        file.Close();

        RemoveMap();

        int cellAmount = mapData.cellData.Length;

        cells = new HexCell[cellAmount];
        if (createLabels)
        {
            labels = new Text[side * side];
        }

        for (int i = 0; i < cellAmount; i++)
        {
            HexCellData cellData = mapData.cellData[i];
            if (!cellData.valid)
            {
                continue;
            }
            int x = cellData.coordinates.X, z = cellData.coordinates.Z;
            CreateCell(x, z, i);
            cells[i].pfWeight = cellData.pfWeight;
            cells[i].faction  = cellData.faction;
            cells[i].Type     = cellData.type;
            //Debug.Log(cellData.type);
        }

        InitializeAllNeighbors();
    }
Beispiel #8
0
        static void MapSaverXMLFile_OverrideSave(ref XElement HeightMap, ref XElement ColorMap, HexGridData MapData)
        {
            for (int z = 0; z < MapData.height; z++)
            {
                for (int x = 0; x < MapData.width; x++)
                {
                    #region Save color
                    if (MapData.ColorMap[z * MapData.width + x] != MapData.Default.color)
                    {
                        XElement Cell = new XElement("Cell");

                        Cell.Add(new XElement("Xindex", x));
                        Cell.Add(new XElement("Zindex", z));

                        XElement Color = new XElement("Color");

                        Color.Add(new XElement("Red", MapData.ColorMap[z * MapData.width + x].r));
                        Color.Add(new XElement("Green", MapData.ColorMap[z * MapData.width + x].g));
                        Color.Add(new XElement("Blue", MapData.ColorMap[z * MapData.width + x].b));

                        Cell.Add(Color);
                        ColorMap.Add(Cell);
                    }
                    #endregion

                    #region SaveHeight
                    if (MapData.HeightMap[z * MapData.width + x] != 0)
                    {
                        XElement Cell = new XElement("Cell");

                        Cell.Add(new XElement("Xindex", x));
                        Cell.Add(new XElement("Zindex", z));
                        Cell.Add(new XElement("Y", MapData.HeightMap[z * MapData.width + x].ToString(CInfo)));

                        HeightMap.Add(Cell);
                    }
                    #endregion
                }
            }
        }
Beispiel #9
0
        static void MapSaverXMLFile_DefaultSave(ref XElement HeightMap, ref XElement ColorMap, HexGridData MapData)
        {
            for (int z = 0; z < MapData.height; z++)
            {
                string rowValue = "";
                for (int x = 0; x < MapData.width; x++)
                {
                    rowValue += MapData.HeightMap[z * MapData.width + x].ToString(CInfo) + "/";

                    XElement Cell = new XElement("Cell");

                    Cell.Add(new XElement("Xindex", x));
                    Cell.Add(new XElement("Zindex", z));

                    XElement Color = new XElement("Color");

                    Color.Add(new XElement("Red", MapData.ColorMap[z * MapData.width + x].r));
                    Color.Add(new XElement("Green", MapData.ColorMap[z * MapData.width + x].g));
                    Color.Add(new XElement("Blue", MapData.ColorMap[z * MapData.width + x].b));

                    Cell.Add(Color);
                    ColorMap.Add(Cell);
                }
                HeightMap.Add(new XElement("Row", rowValue));
            }
        }
Beispiel #10
0
 public HexGridMesh(HexGridData data)
 {
     hexGridData = data;
     meshBuilder = new MeshBuilder();
 }