Esempio n. 1
0
        public void TestSaveMethod()
        {
            TileFile tileFile = new TileFile();
            tileFile.Load(TEST_FILE);

            MemoryStream savedStream = new MemoryStream();
            tileFile.Save(savedStream);

            savedStream.Seek(0, SeekOrigin.Begin);

            TileFile savedTileFile = new TileFile();
            savedTileFile.Load(savedStream);

            savedStream.Close();

            Assert.AreEqual(tileFile.Width, savedTileFile.Width, "Width values do not match");
            Assert.AreEqual(tileFile.Height, savedTileFile.Height, "Height values do not match");

            for (int x = 0; x < tileFile.Height; x++) {
                for (int y = 0; y < tileFile.Width; y++) {
                    Assert.AreEqual(tileFile[x, y].Brush, savedTileFile[x, y].Brush, "Brush values do not match");
                    Assert.AreEqual(tileFile[x, y].TileIndex, savedTileFile[x, y].TileIndex, "Tile index values do not match");
                    Assert.AreEqual(tileFile[x, y].TileSet, savedTileFile[x, y].TileSet, "Tile set values do not match");
                    Assert.AreEqual(tileFile[x, y].Tile, savedTileFile[x, y].Tile, "Tile values do not match");
                }
            }
        }
Esempio n. 2
0
        public void TestLoadMethod()
        {
            const int HEIGHT = 16;
            const int WIDTH = 16;

            Stream stream = File.OpenRead(TEST_FILE);

            stream.Seek(0, SeekOrigin.End);
            long fileSize = stream.Position;
            stream.Seek(0, SeekOrigin.Begin);

            TileFile tileFile = new TileFile();
            tileFile.Load(stream);

            long streamPosition = stream.Position;
            stream.Close();

            Assert.AreEqual(fileSize, streamPosition, "Not all of the file was read");
            Assert.AreEqual(WIDTH, tileFile.Width, "Incorrect width");
            Assert.AreEqual(HEIGHT, tileFile.Height, "Incorrect height");
        }
Esempio n. 3
0
    static Terrain ImportTerrain(string planet, string map, Revise.Files.ZON.ZoneFile zon, int x, int y)
    {
        var blockName = x.ToString() + "_" + y.ToString();
        var basePath = rootPath + "3DDATA/MAPS/" + planet + "/" + map + "/" + blockName;
        float blockX = (x - 32) * 160;
        float blockY = (32 - y) * 160;

        Object.DestroyImmediate(GameObject.Find(blockName));

        var ifo = new Revise.Files.IFO.MapDataFile();
        ifo.Load(basePath + ".IFO");

        for (int i = 0; i < ifo.Objects.Count; ++i)
        {
            var obj = ifo.Objects[i];
            ImportObject("JUNON_JDT_DECO", x, y, "DECO", i, obj);
        }

        for (int i = 0; i < ifo.Buildings.Count; ++i)
        {
            var obj = ifo.Buildings[i];
            ImportObject("JUNON_JDT_CNST", x, y, "CNST", i, obj);
        }

        for (int i = 0; i < ifo.Animations.Count; ++i)
        {
            //var obj = ifo.Animations[i];
            Debug.LogWarning("Got unexpected animation object.");
        }

        for (int i = 0; i < ifo.Sounds.Count; ++i) {
            var snd = ifo.Sounds[i];
            var sndName = "SND_" + snd.ObjectID.ToString() + " (" + blockName + "_" + i.ToString() + ")";

            var a = new GameObject();

            //var s = a.AddComponent<AudioSource>();
            //TODO: Need to link to audio after copy in prestage

            a.transform.localPosition = ifotruPosition(snd.Position);
            a.transform.localRotation = rtuRotation(snd.Rotation);
            a.transform.localScale = rtuScale(snd.Scale);
            a.name = sndName;
            a.isStatic = true;
        }

        var tex = ImportPlanMap(planet, map, x, y);

        var him = new Revise.Files.HIM.HeightmapFile();
        him.Load(basePath + ".HIM");

        float[,] heights = new float[65,65];
        float heightMin = him.Heights[0, 0];
        float heightMax = him.Heights[0, 0];
        for (int ix = 0; ix < 65; ++ix)
        {
            for (int iy = 0; iy < 65; ++iy)
            {
                if (him.Heights[ix, iy] < heightMin)
                {
                    heightMin = him.Heights[ix, iy];
                }
                if (him.Heights[ix, iy] > heightMax)
                {
                    heightMax = him.Heights[ix, iy];
                }
            }
        }
        float heightBase = heightMin;
        float heightDelta = heightMax - heightMin;
        for (int ix = 0; ix < 65; ++ix)
        {
            for (int iy = 0; iy < 65; ++iy)
            {
                heights[ix, iy] = (him.Heights[64 - ix, iy] - heightBase) / heightDelta;
            }
        }

        var til = new Revise.Files.TIL.TileFile();
        til.Load(basePath + ".TIL");

        /*
        for (int ix = 0; ix < til.Width; ++ix) {
            for (int iy = 0; iy < til.Height; ++iy) {
                var t = til[ix, iy].Tile;
                Debug.Log(
                    til[ix, iy].Brush.ToString() + "," +
                    til[ix, iy].TileSet.ToString() + "," +
                    til[ix, iy].TileIndex.ToString() + "," +
                    til[ix, iy].Tile.ToString());
                Debug.Log(
                    zon.Tiles[t].Layer1.ToString() + "," +
                    zon.Tiles[t].Offset1.ToString() + "," +
                    zon.Tiles[t].Layer2.ToString() + "," +
                    zon.Tiles[t].Offset2.ToString() + "," +
                    zon.Tiles[t].TileType.ToString() + "," +
                    zon.Tiles[t].TileType.ToString() + "," +
                    zon.Tiles[t].Rotation.ToString());
                Debug.Log(zon.Textures[zon.Tiles[t].Layer1 + zon.Tiles[t].Offset1]);
                Debug.Log(zon.Textures[zon.Tiles[t].Layer2 + zon.Tiles[t].Offset2]);
            }
        }
        */

        var td = new TerrainData();
        td.size = new Vector3(80, heightDelta/100, 80);
        td.heightmapResolution = 65;
        td.SetHeights(0, 0, heights);
        var ts = new SplatPrototype[1];
        ts[0] = new SplatPrototype();
        ts[0].texture = tex;
        ts[0].tileSize = new Vector2(160, 160);
        td.splatPrototypes = ts;

        var ter = Terrain.CreateTerrainGameObject(td).GetComponent<Terrain>();
        ter.name = blockName;

        ter.transform.localPosition = new Vector3(blockX, heightBase/100, blockY);
        return ter;
    }