Example #1
0
 void CreateMap(int x, int z)
 {
     if (generateMaps)
     {
         mapGenerator.GenerateMap(x, z, wrapping);
     }
     else
     {
         hexGrid.CreateMap(x, z, wrapping);
     }
     HexMapCamera.ValidatePosition();
     Close();
 }
Example #2
0
 /// <summary>
 /// 创建地图
 /// </summary>
 /// <param name="x"></param>
 /// <param name="z"></param>
 void CreateMap(int x, int z)
 {
     if (generateMaps)
     {
         mapGenerator.GenerateMap(x, z); // 生成随机地图
     }
     else
     {
         hexGrid.CreateMap(x, z);        // 生成默认地图
     }
     HexMapCamera.ValidatePosition();    // 验证地图边界,矫正摄像机位置
     Close();
 }
Example #3
0
    public void CreateMap(int x, int z)
    {
        if (m_generateMaps)
        {
            HexMapGenerator.GenerateMap(x, z, m_wrap);
        }
        else
        {
            HexGrid.CreateMap(x, z, m_wrap);
        }

        HexMapCamera.ValidatePosition();
        Close();
    }
 void CreateMap(int x, int z)
 {
     if (generateMaps)
     {
         mapGenerator.GenerateMap(x, z);
     }
     else
     {
         hexGrid.CreateMap(x, z);
     }
     HexMapCamera.ValidatePosition();
     playMode.RespawnPlayInRandomCell();
     Close();
 }
Example #5
0
 void CreateMap(int x, int z)
 {
     //проверка способа создания карты
     if (generateMaps)
     {
         mapGenerator.GenerateMap(x, z, wrapping);
     }
     else
     {
         hexGrid.CreateMap(x, z, wrapping);
     }
     HexMapCamera.ValidatePosition();
     Close();
 }
    void Load(string pathp)
    {
        if (!File.Exists(pathp))
        {
            path = null;
            return;
        }

        using (BinaryReader reader = new BinaryReader(File.OpenRead(path))) {
            int header = reader.ReadInt32();
            if (header <= 1)
            {
                hexGrid.Load(reader, header);
                HexMapCamera.ValidatePosition();
            }
        }
    }
Example #7
0
    public void Load()
    {
        string path = Path.Combine(Application.persistentDataPath, "test.map");

        using (BinaryReader reader = new BinaryReader(File.OpenRead(path))) {
            int header = reader.ReadInt32();

            if (header <= 1)
            {
                hexGrid.Load(reader, header);
                HexMapCamera.ValidatePosition();
            }
            else
            {
                Debug.LogWarning("Unknown map format " + header);
            }
        }
    }
        public IEnumerator CheckValidateCameraPosition()
        {
            SceneManager.LoadScene("Scene", LoadSceneMode.Single);
            yield return(new WaitForSeconds(1.0f));

            goA = SceneManager.GetActiveScene().GetRootGameObjects();
            GameObject Camera = goA[2];

            HexMapCamera.ValidatePosition();
            Assert.AreEqual(Camera.gameObject.transform.localPosition, new Vector3(0f, 0f, 0f));

            foreach (GameObject g in goA)
            {
                GameObject.Destroy(g);
            }
            GameObject.Destroy(Camera);
            SceneManager.UnloadScene("Scene");
        }
Example #9
0
    public void Load()
    {
        DirectoryInfo info = new DirectoryInfo(Application.dataPath);
        string        path = Path.Combine(info.ToString() + "/Maps", "test.map");

        using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))
        {
            int header = reader.ReadInt32();
            if (header <= HexMapEditor.mapVersion)
            {
                hexGrid.Load(reader, header);
                HexMapCamera.ValidatePosition();
            }
            else
            {
                Debug.LogWarning("Unknown map format " + header);
            }
        }
    }
 void Load(string path)
 {
     if (!File.Exists(path))
     {
         Debug.LogError("File does not exist " + path);
         return;
     }
     using (BinaryReader reader = new BinaryReader(File.OpenRead(path))) {
         int header = reader.ReadInt32();
         if (header <= mapFileVersion)
         {
             hexGrid.Load(reader, header);
             HexMapCamera.ValidatePosition();
         }
         else
         {
             Debug.LogWarning("Unknown map format " + header);
         }
     }
 }
    public void Load(string path)
    {
        if (!File.Exists(path))
        {
            Debug.LogError("File does not exist " + path);
            return;
        }

        using (BinaryReader reader = new BinaryReader(File.OpenRead(path))) {
            int header = reader.ReadInt32();             // Read save format version
            if (header == mapFileVersion)
            {
                hexGrid.Load(reader);
                HexMapCamera.ValidatePosition();                 // Camera may be in invalid position if map size change
            }
            else
            {
                Debug.LogWarning("Unknown map format " + header);
            }
        }
    }
Example #12
0
    public void CentreMap()
    {
        CityState cityState = humanPlayer.GetCityStates().FirstOrDefault();

        if (cityState)
        {
            hexMapCamera.MoveCamera(cityState.GetCity().GetHexCell());
        }
        else
        {
            Agent agent = humanPlayer.GetAgents().FirstOrDefault();
            if (agent)
            {
                hexMapCamera.MoveCamera(agent.HexUnit.Location);
            }
            else
            {
                HexMapCamera.ValidatePosition();
            }
        }
    }
Example #13
0
    public void Load(string path)
    {
        if (path != null)
        {
            if (!File.Exists(path))
            {
                Debug.LogError("File does not exist " + path);
                return;
            }

            using (BinaryReader binReader = new BinaryReader(File.Open(path, FileMode.Open)))
            {
                binReader.ReadInt32();
                int x = binReader.ReadInt32();
                int z = binReader.ReadInt32();
                HexGrid.CreateMap(x, z, HexMetrics.Wrap);
                HexGrid.Load(binReader);
                HexMapCamera.ValidatePosition();
            }
        }
    }
    /// <summary>
    /// Returns true if map was created with specifield dimensions, false if otherwise.
    /// </summary>
    public bool CreateMap(int x, int z, bool wrapping)
    {
        ClearPath();         // Clear any pathfinding highlighting
        ClearUnits();        // Clear Units

        // Sanity Check
        if (x <= 0 || x % HexMetrics.ChunkSizeX != 0 || z <= 0 || z % HexMetrics.ChunkSizeZ != 0)
        {
            Debug.LogError("Unsupported map size " + x + " x " + z + " .");
            return(false);
        }

        // If defined clear old data, columns and their chunks
        if (Columns != null)
        {
            for (int i = 0; i < Columns.Length; i++)
            {
                Destroy(Columns[i].gameObject);
            }
        }

        CellCountX = x;
        CellCountZ = z;

        Wrapping                 = wrapping;
        HexMetrics.WrapSize      = wrapping ? CellCountX : 0;
        CurrentCenterColumnIndex = -1;

        ChunkCountX = CellCountX / HexMetrics.ChunkSizeX;
        ChunkCountZ = CellCountZ / HexMetrics.ChunkSizeZ;

        cellShaderData.Initialize(CellCountX, CellCountZ);
        CreateChunks();
        CreateCells();

        HexMapCamera.ValidatePosition();

        return(true);
    }
Example #15
0
    void Load(string path)
    {
        //string path = Path.Combine(Application.persistentDataPath, "Test.map");

        if (!File.Exists(path))
        {
            Debug.LogError("File does not exist " + path);
            return;
        }
        using (BinaryReader reader = new BinaryReader(File.OpenRead(path))) {
            int header = reader.ReadInt32();
            if (header <= 2)
            {
                hexGrid.Load(reader, header);
                HexMapCamera.ValidatePosition();
            }
            else
            {
                Debug.LogWarning("Unknown map format " + header);
            }
        }
    }
Example #16
0
    public void CreateMap(int x, int z, bool _wrapping)
    {
        if (x <= 0 || x % HexMetrics.chunkSizeX != 0)
        {
            Debug.LogError("Error : Unsupported map X size :" + x);
            return;
        }
        if (z <= 0 || z % HexMetrics.chunkSizeZ != 0)
        {
            Debug.LogError("Error : Unsupported map Z size" + x);
            return;
        }

        Clean();

        if (columns != null)
        {
            for (int i = 0; i < columns.Length; i++)
            {
                Destroy(columns[i].gameObject);
            }
        }

        cellCountX               = x;
        cellCountZ               = z;
        this.wrapping            = _wrapping;
        HexMetrics.wrapSize      = wrapping ? cellCountX : 0;
        currentCenterColumnIndex = -1;

        chunkCountX = cellCountX / HexMetrics.chunkSizeX;
        chunkCountZ = cellCountZ / HexMetrics.chunkSizeZ;

        cellShaderData.Initialize(cellCountX, cellCountZ);

        CreateChunks();
        CreateCells();

        HexMapCamera.ValidatePosition();
    }
Example #17
0
 /// <summary>
 /// 从文件加载地图
 /// </summary>
 public void Load(string path)
 {
     if (!File.Exists(path))
     {
         Debug.LogError("文件不存在: " + path);
         return;
     }
     Debug.Log("加载开始:" + path);
     using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))                 // File.OpenRead(path) 相当于 File.Open(path, FileMode.Open)
     {
         int header = reader.ReadInt32();
         if (header <= mapFileVersion)
         {
             hexGrid.Load(reader, header);
             HexMapCamera.ValidatePosition();    // 矫正摄像机位置
             hexGrid.RefreshChunks();
         }
         else
         {
             Debug.LogError("地图文件格式有误!无法加载! " + header);
         }
     }
 }
        public void OpenMapClicked()
        {
            string path = GetSelectedPath();

            if (!File.Exists(path))
            {
                Debug.LogError("File does not exist " + path);
                return;
            }
            using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))
            {
                int header = reader.ReadInt32();
                if (header <= mapFileVersion)
                {
                    _hexMapEditor.hexGrid.Load(reader, header);
                    HexMapCamera.ValidatePosition();
                }
                else
                {
                    Debug.LogWarning("Unknown map format " + header);
                }
            }
            ContentViewSwitcher.SwitchTo("MainRegion");
        }
Example #19
0
 private void CreateMap(int x, int z)
 {
     hexGrid.CreateMap(x, z);
     HexMapCamera.ValidatePosition();
     Close();
 }