Example #1
0
    async void ReadTest()
    {
        pathText.text = Application.streamingAssetsPath;
        string path = Application.streamingAssetsPath + "/Project/Data/MapData/SampleMapA.mps";

        Debug.Log(path);
        var     mpsReader = new MpsFileReader();
        MapData mapData   = await mpsReader.ReadFileAsync(path);

        infoText.text = mapData.MapSizeWidth.ToString();
    }
Example #2
0
        async Task InitializeMapData(string dataPath)
        {
            DatabaseDataDescList mapSettingList = CoreData.Instance.systemDB.GetDataDescList(0);

            CoreData.Instance.mapEventCurrentPages = new int[mapSettingList.Count][];
            CoreData.Instance.mapDataArray         = new MapData[mapSettingList.Count];
            CoreData.Instance.mapVariables         = new int[mapSettingList.Count][][];
            for (int i = 0; i < mapSettingList.Count; i++)
            {
                string  mapPath   = dataPath + mapSettingList[i].ItemValueList[0].StringValue.ToString();
                var     mpsReader = new MpsFileReader();
                MapData mapData   = await mpsReader.ReadFileAsync(mapPath);

                CoreData.Instance.mapDataArray[i]         = mapData;
                CoreData.Instance.mapEventCurrentPages[i] = new int[mapData.MapEvents.Count];
                CoreData.Instance.mapVariables[i]         = new int[mapData.MapEvents.Count][];
                for (int j = 0; j < mapData.MapEvents.Count; j++)
                {
                    CoreData.Instance.mapVariables[i][j] = new int[10];
                }
            }
        }
Example #3
0
    async void RenderMap()
    {
        DatabaseMergedData systemDB = await ReadSystemDB();

        var mapDataList = systemDB.GetDataDescList(0);

        if (mapNo >= mapDataList.Count)
        {
            return;
        }

        string  mapPath   = dataPath + mapDataList[mapNo].ItemValueList[0].StringValue.ToString();
        var     mpsReader = new MpsFileReader();
        MapData mapData   = await mpsReader.ReadFileAsync(mapPath);

        string      tileSetPath = dataPath + "BasicData/TileSetData.dat";
        var         reader      = new TileSetDataFileReader();
        TileSetData setData     = await reader.ReadFileAsync(tileSetPath);

        TileSetSetting tileSetting = setData.TileSetSettingList[mapData.TileSetId];

        ReadBaseTileTexture(tileSetting.BaseTileSetFileName);

        ReadAutoTileTextures(tileSetting.AutoTileFileNameList.ToArray());

        Texture2D mapTexture
            = new Texture2D(mapData.MapSizeWidth * chipSize, mapData.MapSizeHeight * chipSize);

        for (int i = 0; i < mapData.MapSizeHeight; i++)
        {
            for (int j = 0; j < mapData.MapSizeWidth; j++)
            {
                for (int k = 0; k < 3; k++)
                {
                    int id = mapData.GetLayer(k).Chips[j][i];
                    if (mapData.GetLayer(k).Chips[j][i].IsAutoTile)
                    {
                        RenderAutoTile(mapTexture, j, i, id);
                    }
                    else
                    {
                        RenderNormalTile(mapTexture, j, i, id);
                    }
                }
            }
        }

        for (int i = 0; i < mapData.MapEvents.Count; i++)
        {
            int          x            = mapData.MapEvents[i].Position.X;
            int          y            = mapData.MapEvents[i].Position.Y;
            MapEventPage mapEventPage = mapData.MapEvents[i].MapEventPageList[0];
            if (mapEventPage.GraphicInfo.IsGraphicTileChip)
            {
                int tileId = mapEventPage.GraphicInfo.GraphicTileId;
                RenderNormalTile(mapTexture, x, y, tileId);
            }
            else if (!string.IsNullOrEmpty(mapEventPage.GraphicInfo.CharaChipFilePath))
            {
                string graphicPath = dataPath + mapEventPage.GraphicInfo.CharaChipFilePath;
                Debug.Log(graphicPath);
                CharaChipDirection charaChipDirection = mapEventPage.GraphicInfo.InitDirection;
                Texture2D          charaChipTexture   = new Texture2D(1, 1);
                byte[]             bytes = System.IO.File.ReadAllBytes(graphicPath);
                charaChipTexture.LoadImage(bytes);
                charaChipTexture.filterMode = FilterMode.Point;
                RenderCharaChip(mapTexture, x, y, charaChipTexture, charaChipDirection);
            }
        }

        mapTexture.Apply();
        mapTexture.filterMode = FilterMode.Point;

        Sprite sprite = Sprite.Create(mapTexture,
                                      new Rect(0.0f, 0.0f, mapTexture.width, mapTexture.height), new Vector2(0.5f, 0.5f), 1.0f);

        mapSprite.sprite = sprite;
    }