コード例 #1
0
    private void LoadLevel()
    {
        LevelDef level = Levels[CurrentLevelIndex];

        LevelText.text       = $"{level.Number}/{Levels.Length}";
        DescriptionText.text = level.DescriptionText;

        Lovables = 0;

        string layout = level.LevelLayout;

        int row = 0;

        foreach (var line in layout.Split(new string[] { System.Environment.NewLine }, System.StringSplitOptions.None))
        {
            int col = 0;

            foreach (var letter in line)
            {
                switch (letter)
                {
                case 'W':
                    Instantiate(WallPrefab, new Vector3(col, -row, 0), Quaternion.identity, transform);
                    break;

                case 'F':
                    Instantiate(FloorPrefab, new Vector3(col, -row, 0), Quaternion.identity, transform);
                    break;

                case 'U':
                    Instantiate(FloorPrefab, new Vector3(col, -row, 0), Quaternion.identity, transform);

                    Lovable upLovable = Instantiate(LovablePrefab, new Vector3(col, -row, 0), Quaternion.identity, transform);
                    upLovable.SetRotation(Lovable.UpRotation);
                    Lovables++;
                    break;

                case 'R':
                    Instantiate(FloorPrefab, new Vector3(col, -row, 0), Quaternion.identity, transform);

                    Lovable rightLovable = Instantiate(LovablePrefab, new Vector3(col, -row, 0), Quaternion.identity, transform);
                    rightLovable.SetRotation(Lovable.RightRotation);
                    Lovables++;
                    break;

                case 'D':
                    Instantiate(FloorPrefab, new Vector3(col, -row, 0), Quaternion.identity, transform);

                    Lovable downLovable = Instantiate(LovablePrefab, new Vector3(col, -row, 0), Quaternion.identity, transform);
                    downLovable.SetRotation(Lovable.DownRotation);
                    Lovables++;
                    break;

                case 'L':
                    Instantiate(FloorPrefab, new Vector3(col, -row, 0), Quaternion.identity, transform);

                    Lovable leftLovable = Instantiate(LovablePrefab, new Vector3(col, -row, 0), Quaternion.identity, transform);
                    leftLovable.SetRotation(Lovable.LeftRotation);
                    Lovables++;
                    break;

                default:
                    break;
                }

                col++;
            }

            row++;
        }
    }