Beispiel #1
0
    /// <summary>
    /// Tile 위에 부서지기 전까지 Piece가 위치하는 것을 방지하는 BreakableTile을 생성합니다.
    /// </summary>
    public void CreateBreakableTile()
    {
        // 만일 스테이지에 설정한 BreakableTile이 없으면 그대로 반환합니다.
        if (stageData.breakableTile.Length <= 0)
        {
            return;
        }

        for (int column = 0; column < vertical; ++column)
        {
            for (int row = 0; row < horizontal; ++row)
            {
                // BlankSpace이거나 BreakableTile이 아니면 다음 Tile로 이동합니다.
                if (IsBlankSpace(row, column) || !IsBreakableTile(row, column, true))
                {
                    continue;
                }

                // BreakableTile 객체를 위치에 생성합니다.
                BreakableTile breakableTile = Instantiate(breakableTilePrefab, new Vector2(row, column), Quaternion.identity).GetComponent <BreakableTile>();
                // BreakableTile을 초기화합니다.
                breakableTile.InitializeBreakableTile();
                // 해당 Tile 배열에 생성한 BreakableTile을 저장합니다.
                tiles[row, column].breakableTile = breakableTile;

                // BreakableTile의 이름을 BreakableTile[row, column]으로 변경합니다.
                breakableTile.name = $"BreakableTile [{row} , {column}]";
                // BreakableTile을 Parent 오브젝트의 Child로 만듭니다.
                breakableTile.transform.SetParent(tiles[row, column].transform);
            }
        }
    }
Beispiel #2
0
    public void DamagedResetBreakableTile()
    {
        for (int i = 0; i < stageData.breakableTile.Length; ++i)
        {
            BreakableTile b_tile = GetBreakableTile((int)stageData.breakableTile[i].x, (int)stageData.breakableTile[i].y);

            if (!b_tile.tileBreak)
            {
                b_tile.damaged = false;
            }
        }
    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Environment")
        {
            Vector3 hitPos = Vector3.zero;

            if (collision.contacts.Length > 0)
            {
                hitPos.x = collision.contacts[0].point.x;
                hitPos.y = collision.contacts[0].point.y;

                var tilemap      = collision.gameObject.GetComponent <Tilemap>();
                var tilePosition = tilemap.WorldToCell(hitPos);
                var tile         = tilemap.GetTile(tilePosition);

                if (tile is BreakableTile)
                {
                    BreakableTile.Break(tilePosition, tilemap);
                }
            }
        }
    }
    //TODO: I really hate this, I don't want to have to make a class based on an enum
    public void AddObjectEntity(ObjectData data)
    {
        switch (data.type)
        {
        case ObjectType.Chest:
            Chest temp = new Chest(ScriptableObject.Instantiate(mCurrentMap.Data.chestType));
            temp.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.FallingRock:
            FallingRock temp2 = new FallingRock(Resources.Load("Prototypes/Entity/Objects/FallingRock") as EntityPrototype);
            temp2.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.FlowerBed:
            FlowerBed temp3 = new FlowerBed(Resources.Load("Prototypes/Entity/Objects/FlowerBed") as EntityPrototype);
            temp3.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.Tree:
            Tree temp4 = new Tree(Resources.Load("Prototypes/Entity/Objects/Tree") as EntityPrototype);
            temp4.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.Medbay:
            MedicalBay temp5 = new MedicalBay(Resources.Load("Prototypes/Entity/Objects/Medbay") as EntityPrototype);
            temp5.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.Door:
            if (mCurrentMap.mapType != MapType.BossMap)
            {
                Door temp6 = new Door(Resources.Load("Prototypes/Entity/Objects/Door") as DoorPrototype);
                if (mCurrentMap.Data.hasMiniboss)
                {
                    temp6.locked = true;
                }
                temp6.Spawn(GetMapTilePosition(data.TilePosition));
            }
            break;

        case ObjectType.NavSystem:
            NavSystem temp7 = new NavSystem(Resources.Load("Prototypes/Entity/Objects/NavSystem") as EntityPrototype);
            temp7.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.BouncePad:
            BouncePad temp8 = new BouncePad(Resources.Load("Prototypes/Entity/Objects/BouncePad") as EntityPrototype);
            temp8.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.Spikes:
            Spikes temp9 = new Spikes(Resources.Load("Prototypes/Entity/Objects/Spikes") as EntityPrototype);
            temp9.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.Iceblock:
            Iceblock temp10 = new Iceblock(Resources.Load("Prototypes/Entity/Objects/Iceblock") as EntityPrototype);
            temp10.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.AnalysisCom:
            AnalysisCom temp11 = new AnalysisCom(Resources.Load("Prototypes/Entity/Objects/AnalysisCom") as EntityPrototype);
            temp11.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.Item:
            if (data is ItemObjectData itemData)
            {
                ItemObject temp12 = new ItemObject(ItemDatabase.GetItem(itemData.itemType), Resources.Load("Prototypes/Entity/Objects/ItemObject") as EntityPrototype);
                temp12.Spawn(GetMapTilePosition(data.TilePosition));
            }
            break;

        case ObjectType.SmallGatherable:
            Gatherable temp13 = new Gatherable(Resources.Load("Prototypes/Entity/Objects/Gatherables/Small Blue Vein") as GatherablePrototype);
            temp13.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.LargeGatherable:
            Gatherable temp14 = new Gatherable(Resources.Load("Prototypes/Entity/Objects/Gatherables/Large Blue Vein") as GatherablePrototype);
            temp14.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.SaveMachine:
            SaveMachine temp15 = new SaveMachine(Resources.Load("Prototypes/Entity/Objects/SaveMachine") as EntityPrototype);
            temp15.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.BreakableTile:
            BreakableTile temp16 = new BreakableTile(Resources.Load("Prototypes/Entity/Objects/BreakableTile") as EntityPrototype);
            temp16.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.PracticeBot:
            PracticeBot temp17 = new PracticeBot(Resources.Load("Prototypes/Entity/Objects/PracticeBot") as EntityPrototype);
            temp17.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.ShipTeleporter:
            ShipTeleporter temp18 = new ShipTeleporter(Resources.Load("Prototypes/Entity/Objects/ShipTeleporter") as EntityPrototype);
            temp18.Spawn(GetMapTilePosition(data.TilePosition));
            break;

        case ObjectType.MovingPlatform:
            MovingPlatform temp19 = new MovingPlatform(Resources.Load("Prototypes/Entity/Objects/MovingPlatform") as EntityPrototype);
            temp19.Spawn(GetMapTilePosition(data.TilePosition));
            break;
        }
    }