コード例 #1
0
    private void LoadLevel(LevelConfig level)
    {
        correctAngles  = level.GetCorrectCannonAngles();
        angleTolerance = level.GetAngleTolerance();

        FindObjectOfType <CanvasManipulator>().NewLevel();

        if (cannonCoroutine != null)
        {
            StopCoroutine(cannonCoroutine);
        }

        if (FindObjectsOfType <Ball>().Length != 0)
        {
            foreach (Ball ball in FindObjectsOfType <Ball>())
            {
                Destroy(ball.gameObject);
            }
        }

        if (FindObjectOfType <Cannon>() == null)
        {
            Instantiate(cannonPrefab, level.GetCannonPosition(), Quaternion.identity);
        }


        prevPlatformsDestroyed = false;
        int prevPlatforms = platforms.Count;

        var magneticFieldPositions = level.GetMagneticFieldPositions();

        if (magneticFieldPositions.Count != 0)
        {
            for (int i = 0; i < magneticFieldPositions.Count; i++)
            {
                var mf = Instantiate(magneticFieldPrefab, level.GetMagneticFieldPositions()[i] + new Vector3(0, 16, 0), Quaternion.identity);
                mf.transform.localScale *= level.GetMagneticFieldScales()[i];
                mf.GetComponent <MagneticField>().SetPower(level.GetMagneticFieldPowers()[i]);
                mf.GetComponent <MagneticField>().SetTurnSpeed(level.GetMagneticFieldScales()[i]);
                platforms.Add(mf);
            }
        }

        var boostPositions = level.GetBoostPositions();

        if (boostPositions.Count != 0)
        {
            for (int i = 0; i < boostPositions.Count; i++)
            {
                var boost = Instantiate(bonusPrefab, level.GetBoostPositions()[i] + new Vector3(0, 16, 0), Quaternion.identity);
                boost.GetComponent <Bonus>().SetBoost(level.GetBoosts()[i]);
                platforms.Add(boost);
            }
        }
        CreateAllWalls(level);

        CreateObstacles(level);

        if (FindObjectOfType <Target>())
        {
            if (FindObjectOfType <Cannon>())
            {
                FindObjectOfType <Cannon>().gameObject.transform.position = level.GetCannonPosition() + new Vector3(0, 16, 0);
            }
            Destroy(FindObjectOfType <Target>().gameObject);
        }

        foreach (GameObject element in platforms)
        {
            StartCoroutine(Move(element, prevPlatforms, level));
        }

        if (FindObjectOfType <Cannon>().gameObject.transform.position.y > -4)
        {
            cannonCoroutine = StartCoroutine(MoveCannon());
        }

        FindObjectOfType <Cannon>().StopMoving();
    }