Exemple #1
0
    void BuildWorld()
    {
        CalculateContinentTerritory();
        int tile = MapMetrics.Tile;

        MapMesh.regionIndex = regionIndex;
        MapMesh.regions     = regions;
        for (int i = 0; i < h; i += tile)
        {
            for (int j = 0; j < w; j += tile)
            {
                MapMesh mapMesh = Instantiate(mapMeshPrefab);
                MapMeshes.Add(mapMesh);
                mapMesh.TriangulateMap(j, i);
                mapMesh.transform.localPosition = Vector3.zero;
            }
        }

        SetProvNames();
        SetTowns();
        foreach (var state in states)
        {
            state.Text       = Instantiate(Text);
            state.Text.layer = 8;
            state.SetName();
            state.SetNameStatus(true);
            Region cap = state.Capital;
            cap.Corona = Instantiate(CoronaPrefab, cap.Town.transform);
            cap.Corona.transform.localPosition = Vector3.up * 0.8f;
        }


        for (int i = 0; i < regions.Count; i++)
        {
            regions[i].UpdateBorder();
        }

        regionMap = MapMetrics.map = new Texture2D(w, h, TextureFormat.RGBA32, false);
        MapMetrics.provincemap = new Texture2D(w, h, TextureFormat.RGBA32, false, false);
        occupationMap          = MapMetrics.occupemap = new Texture2D(w, h, TextureFormat.RGBA32, false);

        regionMap.filterMode     = FilterMode.Point;
        occupationMap.filterMode = FilterMode.Point;
        MapMetrics.UpdateColorMap();
        MapMetrics.UpdateOccupedMap();
        MapMetrics.UpdateProvincesMap();
        System.IO.File.WriteAllBytes("DasIst.png", regionMap.EncodeToPNG());
        terrainMat.SetTexture("_OccupeMap", MapMetrics.occupemap);
        terrainMat.SetColor("_Select", Color.white);

        Shader.SetGlobalTexture("_StateColor", MapMetrics.map);
        Shader.SetGlobalTexture("_ProvincesColor", MapMetrics.provincemap);
        Shader.SetGlobalVector("_NoiseConst", new Vector4(MapMetrics.noiseScale, MapMetrics.cellPerturbStrength, 0, 0));
        Shader.SetGlobalTexture("_SplatMap", MapMetrics.GetSplatMap());
        Shader.SetGlobalVector("_Size", new Vector4(1f / w, 1f / h, w, h));
        Shader.SetGlobalTexture("_HeightMap", MapMetrics.GetHeightMap);
        Shader.SetGlobalTexture("_Noise", MapMetrics.noise);
        Shader.SetGlobalFloat("_MaxHeight", MapMetrics.MaxHeight);
        Shader.SetGlobalFloat("_SeaLevel", MapMetrics.SeaLevel);
    }