//------------------------------------------------------------------------- // Auto Chip public AutoChip CreateAutoChip(AutoChipType type) { var chip = this.pools[MapChipGroup.Field].Create <AutoChip>("field"); chip.Setup(type); return(chip); }
/// <summary> /// フィールドのマップチップを生成 /// </summary> public void CreateAutoChips() { ResetAutoChips(); DungeonManager.Instance.Map((int x, int y, IReadOnlyTile tile) => { bool[] flags = new bool[9]; MyGame.Util.LoopByRect(new RectInt(x - 1, y - 1, 3, 3), (_x, _y, index) => { var DM = DungeonManager.Instance; bool isNotEntry = false; if (x <= 0 || x >= Define.WIDTH - 1 || y <= 0 || y >= Define.HEIGHT - 1) { // 範囲外 isNotEntry = true; } else { isNotEntry = DM.GetTile(new Vector2Int(_x, _y)).IsWall; } if (tile.IsWall) { isNotEntry = !isNotEntry; } flags[index] = isNotEntry; } ); AutoChipType chipType = tile.IsWall ? AutoChipType.Umi : AutoChipType.Sabaku; //:TODO 仮 AutoChip chip = MapChipFactory.Instance.CreateAutoChip(chipType); chip.Coord = new Vector2Int(x, y); chip.TileSize = Define.CHIP_SCALE.x; chip.CachedTransform.position = Dungeon.Util.GetPositionBy(x, y); // スプライトの更新 chip.UpdateConnect(flags); this.autoChips[x, y] = chip; }); }
// Start is called before the first frame update public void Setup(AutoChipType chipType) { // スプライト読み込み Sprite[] sprites = null; //TODO: factory側からもらうようにかえたい switch (chipType) { case AutoChipType.Sabaku: sprites = Resources.LoadAll <Sprite>("Textures/MapChip/800x600/pipo-map001_at-sabaku"); break; case AutoChipType.Tuchi: sprites = Resources.LoadAll <Sprite>("Textures/MapChip/640x480/pipo-map001_at-tuti"); break; case AutoChipType.Umi: sprites = Resources.LoadAll <Sprite>("Textures/MapChip/800x600/pipo-map001_at-umi"); break; case AutoChipType.Mori: sprites = Resources.LoadAll <Sprite>("Textures/MapChip/640x480/pipo-map001_at-mori"); break; } // スプライト分割 foreach (var sprite in sprites) { // スプライト名末尾の数字の取得 var splitIndex = sprite.name.LastIndexOf('_'); string numText = sprite.name.Substring(splitIndex + 1); int num = -1; if (int.TryParse(numText, out num) == false) { // 数字の取得に失敗 continue; } // スプライト配属先指定 CellType cellType = (CellType)(num % (int)CellType.Count); ConnectType connectType = (ConnectType)(num / (int)CellType.Count); switch (cellType) { case CellType.LeftTop: leftTopCell.SetSprite(connectType, sprite); break; case CellType.RightTop: rightTopCell.SetSprite(connectType, sprite); break; case CellType.LeftBottom: leftBottomCell.SetSprite(connectType, sprite); break; case CellType.RightBottom: rightBottomCell.SetSprite(connectType, sprite); break; } // 準備 leftTopCell.Setup(CachedTransform, this.TileSize); rightTopCell.Setup(CachedTransform, this.TileSize); leftBottomCell.Setup(CachedTransform, this.TileSize); rightBottomCell.Setup(CachedTransform, this.TileSize); } }