void RenderCharaChip(Texture2D target, int x, int y, Texture2D charaChipTexture, CharaChipDirection direction) { int charaWidth = charaChipTexture.width / (GameBasicInfo.Instance.CharaAnimations * GameBasicInfo.Instance.CharaImageDirections / 4); int charaHeight = charaChipTexture.height / 4; int xOffset = (chipSize - charaWidth) / 2; for (int i = 0; i < charaHeight; i++) { for (int j = 0; j < charaWidth; j++) { Color color = charaChipTexture.GetPixel(j, charaChipTexture.height - charaHeight + i); if (color.a == 1 && x * chipSize + j + xOffset >= 0 && x * chipSize + j + xOffset < target.width) { target.SetPixel(x * chipSize + j + xOffset, target.height - (y + 1) * chipSize + i, color); } } } }
/// <summary> /// WodiLibのアクセシビリティや型を修正する必要あり /// </summary> /// <param name="eventID"></param> /// <param name="typeID"></param> /// <param name="value"></param> public void SetEventPositionVariable(int eventID, int typeID, int value) { int mapID = CoreData.Instance.currentMapID; int pageID = CoreData.Instance.mapEventCurrentPages[mapID][eventID]; MapEvent mapEvent = CoreData.Instance.mapDataArray[mapID].MapEvents[eventID]; switch (typeID) { case 0: mapEvent.Position = new Position(value, mapEvent.Position.Y); break; case 1: mapEvent.Position = new Position(mapEvent.Position.X, value); break; case 2: mapEvent.Position = new Position(value / 2, mapEvent.Position.Y); break; case 3: mapEvent.Position = new Position(mapEvent.Position.X, value / 2); break; case 4: break; case 5: mapEvent.MapEventPageList[pageID].ShadowGraphicId = (byte)value; break; case 6: mapEvent.MapEventPageList[pageID].GraphicInfo.InitDirection = CharaChipDirection.FromByte((byte)value); break; } }
private void ReadMapEventOnePage(ICollection <MapEventPage> mapEventPages) { var result = new MapEventPage(); // ヘッダチェック foreach (var b in MapEventPage.Header) { if (ReadStatus.ReadByte() != b) { throw new InvalidOperationException( $"マップイベントページのヘッダが異なります。(offset: {ReadStatus.Offset})"); } ReadStatus.IncreaseByteOffset(); } var graphicInfo = new MapEventPageGraphicInfo(); // タイル画像ID var graphicTileId = (MapEventTileId)ReadStatus.ReadInt(); if (graphicTileId != MapEventTileId.NotUse) { graphicInfo.IsGraphicTileChip = true; graphicInfo.GraphicTileId = graphicTileId; } ReadStatus.IncreaseIntOffset(); // キャラチップ名 var charaChipString = ReadStatus.ReadString(); if (!graphicInfo.IsGraphicTileChip) { graphicInfo.CharaChipFilePath = charaChipString.String; } ReadStatus.AddOffset(charaChipString.ByteLength); // 初期キャラ向き var initDirection = ReadStatus.ReadByte(); graphicInfo.InitDirection = CharaChipDirection.FromByte(initDirection); ReadStatus.IncreaseByteOffset(); // 初期アニメーション番号 graphicInfo.InitAnimationId = ReadStatus.ReadByte(); ReadStatus.IncreaseByteOffset(); // キャラチップ透過度 graphicInfo.CharaChipOpacity = ReadStatus.ReadByte(); ReadStatus.IncreaseByteOffset(); // キャラチップ表示形式 graphicInfo.CharaChipDrawType = PictureDrawType.FromByte(ReadStatus.ReadByte()); ReadStatus.IncreaseByteOffset(); result.GraphicInfo = graphicInfo; var bootInfo = new MapEventPageBootInfo(); // 起動条件 bootInfo.MapEventBootType = MapEventBootType.FromByte(ReadStatus.ReadByte()); ReadStatus.IncreaseByteOffset(); // 条件1~4演算子 & 使用フラグ var conditions = new List <MapEventBootCondition> { new MapEventBootCondition(), new MapEventBootCondition(), new MapEventBootCondition(), new MapEventBootCondition(), }; for (var i = 0; i < 4; i++) { conditions[i].Operation = CriteriaOperator.FromByte((byte)(ReadStatus.ReadByte() & 0xF0)); conditions[i].UseCondition = (byte)(ReadStatus.ReadByte() & 0x0F) != 0; ReadStatus.IncreaseByteOffset(); } // 条件1~4左辺 for (var i = 0; i < 4; i++) { conditions[i].LeftSide = ReadStatus.ReadInt(); ReadStatus.IncreaseIntOffset(); } // 条件1~4右辺 for (var i = 0; i < 4; i++) { conditions[i].RightSide = ReadStatus.ReadInt(); ReadStatus.IncreaseIntOffset(); bootInfo.SetEventBootCondition(i, conditions[i]); } result.BootInfo = bootInfo; var moveRouteInfo = new MapEventPageMoveRouteInfo(); // アニメ速度 moveRouteInfo.AnimateSpeed = AnimateSpeed.FromByte(ReadStatus.ReadByte()); ReadStatus.IncreaseByteOffset(); // 移動速度 moveRouteInfo.MoveSpeed = MoveSpeed.FromByte(ReadStatus.ReadByte()); ReadStatus.IncreaseByteOffset(); // 移動頻度 moveRouteInfo.MoveFrequency = MoveFrequency.FromByte(ReadStatus.ReadByte()); ReadStatus.IncreaseByteOffset(); // 移動ルート moveRouteInfo.MoveType = MoveType.FromByte(ReadStatus.ReadByte()); ReadStatus.IncreaseByteOffset(); var option = new MapEventPageOption(); // オプション var optionByte = ReadStatus.ReadByte(); option.SetOptionFlag(optionByte); ReadStatus.IncreaseByteOffset(); result.Option = option; // カスタム移動ルートフラグ var actionEntry = new ActionEntry(); var customMoveRouteFlag = ReadStatus.ReadByte(); actionEntry.SetOptionFlag(customMoveRouteFlag); ReadStatus.IncreaseByteOffset(); // 動作指定コマンド数 actionEntry.CommandList = ReadCharaMoveCommand(); moveRouteInfo.CustomMoveRoute = actionEntry; result.MoveRouteInfo = moveRouteInfo; // イベント行数 var eventLength = ReadStatus.ReadInt(); ReadStatus.IncreaseIntOffset(); // イベントコマンド var eventCommandListReader = new EventCommandListReader(); result.EventCommands = eventCommandListReader.Read(eventLength, ReadStatus); // イベントコマンド終端チェック foreach (var b in EventCommandList.EndEventCommand) { if (ReadStatus.ReadByte() != b) { throw new InvalidOperationException( $"イベントコマンド後の値が異なります。(offset: {ReadStatus.Offset})"); } ReadStatus.IncreaseByteOffset(); } // 影グラフィック番号 result.ShadowGraphicId = ReadStatus.ReadByte(); ReadStatus.IncreaseByteOffset(); // 接触範囲拡張X var rangeWidth = ReadStatus.ReadByte(); ReadStatus.IncreaseByteOffset(); // 接触範囲拡張Y var rangeHeight = ReadStatus.ReadByte(); ReadStatus.IncreaseByteOffset(); result.HitExtendRange = (rangeWidth, rangeHeight); // イベントページ末尾チェック foreach (var b in MapEventPage.Footer) { if (ReadStatus.ReadByte() != b) { throw new InvalidOperationException( $"イベントページ末尾の値が異なります。(offset: {ReadStatus.Offset})"); } ReadStatus.IncreaseByteOffset(); } // 完了 mapEventPages.Add(result); }
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; }
void RenderMap() { MapData mapData = CoreData.Instance.mapDataArray[CoreData.Instance.currentMapID]; TileSetSetting tileSetting = CoreData.Instance.tileSetData.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 < mapTexture.height; i++) { for (int j = 0; j < mapTexture.width; j++) { mapTexture.SetPixel(j, i, new Color(0, 0, 0)); } } 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); /*sprite = Sprite.Create(baseTileTexture, * new Rect(0, 0, baseTileTexture.width, baseTileTexture.height), new Vector2(0.5f, 0.5f), 1.0f);*/ mapSprite.sprite = sprite; }