示例#1
0
    public void LoadLevelPieces(List <int> levelPieceIndices, bool loadRecycledPieces)
    {
        for (int i = 0; i < levelPieceIndices.Count; i++)
        {
            int pieceIndex = levelPieceIndices[i];

            LevelPieceModel levelPieceModel = levelPieceModels[pieceIndex];
            levelPieceModel.isEnabled = true;

            LevelPieceController levelPiece = levelPiecePrefab.Spawn(transform, Vector3.zero, Quaternion.identity);
            levelPiece.Reset();
            levelPiece.levelPieceModel = levelPieceModel;

            levelPiece.topBorder.transform.localPosition    = new Vector3(0, levelPieceModel.topBorderY, 0);
            levelPiece.bottomBorder.transform.localPosition = new Vector3(0, levelPieceModel.bottomBorderY, 0);

            Transform levelPieceTransform = levelPiece.gameObject.transform;

            if ((loadRecycledPieces || !isInitialized) && i == 0)
            {
                bottomPieceTop.transform.position = levelPiece.topBorder.transform.position;
            }

            if (loadRecycledPieces)
            {
                float piecePos = recycledLevelPieces[recycledLevelPieces.Count - 1].Value;
                recycledLevelPieces.RemoveAt(recycledLevelPieces.Count - 1);

                levelPieceTransform.Translate(new Vector3(0, piecePos, 0));
                loadedLevelPieces.Insert(0, levelPiece);

                bottomPieceTop.transform.position = levelPiece.topBorder.transform.position;
            }
            else
            {
                if (loadedLevelPieces.Count != 0)
                {
                    LevelPieceController topPiece = loadedLevelPieces[loadedLevelPieces.Count - 1];
                    levelPieceTransform.Translate(new Vector3(0, topPiece.topBorder.transform.position.y + 2, 0));
                }
                else
                {
                    levelPieceTransform.Translate(new Vector3(0, 0, 0));
                }

                if (i == levelPieceIndices.Count - 1)
                {
                    topPieceBottom.transform.position = levelPiece.bottomBorder.transform.position;
                }

                loadedLevelPieces.Add(levelPiece);
            }

            // create cicles
            foreach (CircleModel circle in levelPieceModel.circles)
            {
                CircleController circleInstance = null;
                switch (circle.circleType)
                {
                case CircleModel.CircleType.CIRCLE_1:
                {
                    circleInstance = circle1Prefab.Spawn(levelPieceTransform, circle.position, Quaternion.identity);
                    break;
                }

                case CircleModel.CircleType.CIRCLE_2:
                {
                    circleInstance = circle2Prefab.Spawn(levelPieceTransform, circle.position, Quaternion.identity);
                    break;
                }

                case CircleModel.CircleType.CIRCLE_3:
                {
                    circleInstance = circle3Prefab.Spawn(levelPieceTransform, circle.position, Quaternion.identity);
                    break;
                }

                case CircleModel.CircleType.CIRCLE_4:
                {
                    circleInstance = circle4Prefab.Spawn(levelPieceTransform, circle.position, Quaternion.identity);
                    break;
                }
                }
                circleInstance.Reset();

                levelPiece.circles.Add(circleInstance);
            }

            // create spikes
            foreach (SpikeModel spike in levelPieceModel.spikes)
            {
                SpikeController spikeInstance = spikePrefab.Spawn(levelPieceTransform, spike.position, Quaternion.identity);
                spikeInstance.transform.localScale = new Vector3(spike.scale, spike.scale, 1);
                spikeInstance.FixShadowPosition();

                levelPiece.spikes.Add(spikeInstance);
            }
        }
    }