Ejemplo n.º 1
0
    private static void Restore()
    {
        if (!HasValidTerrain())
        {
            return;
        }

        Debug.Log("Script reload detected. Attempting to restore texture data...");

        string path = Path.Combine(Application.dataPath, "splat.bytes");

        if (File.Exists(path))
        {
            TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 8);
            Splat = new SplatMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Splat Maps");
        }

        path = Path.Combine(Application.dataPath, "biome.bytes");
        if (File.Exists(path))
        {
            TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 4);
            Biome = new BiomeMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Biome Maps");
        }

        path = Path.Combine(Application.dataPath, "alpha.bytes");
        if (File.Exists(path))
        {
            TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 1);
            Alpha = new AlphaMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Alpha Maps");
        }

        path = Path.Combine(Application.dataPath, "topology.bytes");
        if (File.Exists(path))
        {
            TerrainMap <int> byteMap = new TerrainMap <int>(File.ReadAllBytes(path), 1);
            Topology = new TopologyMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Topology Maps");
        }

        path = Path.Combine(Application.dataPath, "water.bytes");
        if (File.Exists(path))
        {
            TerrainMap <short> byteMap = new TerrainMap <short>(File.ReadAllBytes(path), 1);
            Water = new WaterMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Water Maps");
        }
    }
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            var sw = Stopwatch.StartNew();
            var mm = TopologyMap.Load(@"world.mpk.lz4");

            sw.Stop();
            Debug.WriteLine(sw.ElapsedMilliseconds + "ms");
            map.Map            = mm;
            map.Zoom           = 5;
            map.CenterLocation = new Location(36.474f, 135.264f);


            //var obj = new List<RenderObject>
            //{
            //	new EllipseRenderObject(new Location(39.563f, 135.615f), 500000, null, new Pen(new SolidColorBrush(Color.FromArgb(200, 0, 160, 255)), 1)),
            //	new EllipseRenderObject(new Location(39.563f, 135.615f), 300000, new RadialGradientBrush(new GradientStopCollection(new[] { new GradientStop(Color.FromArgb(0, 255, 80, 120), .6), new GradientStop(Color.FromArgb(80, 255, 80, 120), 1) })), new Pen(new SolidColorBrush(Color.FromArgb(200, 255, 80, 120)), 1)),
            //	new EewCenterRenderObject(new Location(39.563f, 135.615f)),
            //	new RawIntensityRenderObject(new Location(34.4312f, 135.2294f), "test point", 4),
            //};
            //map.RenderObjects = obj.ToArray();
        }
Ejemplo n.º 3
0
    public IEnumerator Load(World.Data world)
    {
        ActionProgressBar.UpdateProgress("Loading Terrain", 0f);
        yield return(null);

        yield return(null);

        Splat    = new SplatMap(world.splatMap);
        Alpha    = new AlphaMap(world.alphaMap);
        Biome    = new BiomeMap(world.biomeMap);
        Topology = new TopologyMap(world.topologyMap);
        Water    = new WaterMap(world.waterMap);

        TerrainData terrainData = new TerrainData();

        terrainData.alphamapResolution  = Mathf.Clamp(Mathf.NextPowerOfTwo((int)(world.size.x * 0.50f)), 16, 2048);
        terrainData.baseMapResolution   = Mathf.NextPowerOfTwo((int)((float)(world.size.x) * 0.01f));
        terrainData.heightmapResolution = Mathf.NextPowerOfTwo((int)((float)(world.size.x) * 0.5f)) + 1;

        terrainData.size = world.size;

        terrainData.SetHeights(0, 0, world.landHeightMap);

        Terrain = Terrain.CreateTerrainGameObject(terrainData).GetComponent <Terrain>();

        Terrain.name = Terrain.tag = "Terrain";

        Terrain.gameObject.layer = 8;

        Terrain.transform.position = -0.5f * terrainData.size;

        Terrain.gameObject.AddComponent <PositionLock>();

        SetSplatMaps(PaintType.Splat);

        CreateWaterPlane(world.size.x);
    }