Пример #1
0
    /// <summary>
    /// Awake is called on the first frame of instantation.
    /// </summary>
    private void Awake()
    {
        persistentController = GameObject.FindWithTag("Persistent").GetComponent <PersistentControl>();
        squareStageSelect.onClick.AddListener(() => persistentController.SelectFromDefaultStages("Square"));
        squareStageSelect.onClick.AddListener(() => persistentController.PlayGame());
        crossStageSelect.onClick.AddListener(() => persistentController.SelectFromDefaultStages("Cross"));
        crossStageSelect.onClick.AddListener(() => persistentController.PlayGame());
        foreach (Transform child in loadStageContentDisplay.transform)
        {
            Destroy(child.gameObject);
        }
        List <Stage> customStages = SaveData.GetCustomStages();

        for (int i = 0; i < customStages.Count; i++)
        {
            Stage      stage            = customStages[i];
            GameObject thisStageDisplay = GameObject.Instantiate(loadStageSinglePrefab, loadStageContentDisplay.transform);
            thisStageDisplay.transform.localPosition = new Vector3(0, -(i * 25), 0);
            StageSelectionDisplay thisDisplayScript = thisStageDisplay.GetComponent <StageSelectionDisplay>();
            thisDisplayScript.SetStageName(stage.Name);
            thisDisplayScript.SetMultiplier(stage.SpawnMultiplier);
            thisDisplayScript.SetPowerupsSpawn(stage.CanPowerupsSpawn);
            thisStageDisplay.transform.GetChild(thisStageDisplay.transform.childCount - 1).GetComponent <Button>()
            .onClick.AddListener(() => persistentController.PlayGame());
        }
        loadStageContentDisplay.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 25 * customStages.Count);
    }
    /// <summary>
    /// Displays the load screen window, refreshing the list of possible stages to choose from.
    /// </summary>
    public void OpenLoadStageScreen()
    {
        foreach (Transform child in loadStageContentDisplay.transform)
        {
            Destroy(child.gameObject);
        }
        List <Stage> customStages = SaveData.GetCustomStages();

        for (int i = 0; i < customStages.Count; i++)
        {
            Stage      stage            = customStages[i];
            GameObject thisStageDisplay = GameObject.Instantiate(loadStageSinglePrefab, loadStageContentDisplay.transform);
            thisStageDisplay.transform.localPosition = new Vector3(0, -(i * 25), 0);
            StageSelectionDisplay thisDisplayScript = thisStageDisplay.GetComponent <StageSelectionDisplay>();
            thisDisplayScript.SetStageName(stage.Name);
            thisDisplayScript.SetMultiplier(stage.SpawnMultiplier);
            thisDisplayScript.SetPowerupsSpawn(stage.CanPowerupsSpawn);
        }
        loadStageContentDisplay.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 25 * customStages.Count);
    }