コード例 #1
0
ファイル: LoadNewGameManager.cs プロジェクト: 70-lab/Theo
        public void Start()
        {
            // Load data file
            _ec = ErrorController.Instance;
            _dc = DataController.Instance;

            saveInfo = new SaveInfo();

            if (!_dc.LoadData<SaveInfo>(ref saveInfo))
            {
                _dc.AddData(saveInfo);
                _dc.SaveAll();
            }

            // Check window elements

            if (ActionButtons.Length != SaveInfo.SavesCount)
            {
                _ec.PushError("Bad number of load buttons.", this, ErrorType.Error, true);
                return;
            }

            // Disable control buttons

            StartButton.GetComponent<Button>().interactable = false;

            DeleteButton.GetComponent<Button>().interactable = false;
            DeleteButton.GetComponentInChildren<Text>().text = _deleteButtonText;
            DeleteButton.GetComponent<Button>().onClick.AddListener(() => DeleteGame());

            // Set actions to buttons

            for (int i = 0; i < ActionButtons.Length; i++)
            {
                Button button = ActionButtons[i].GetComponent<Button>();
                int index = i;

                if (button == null)
                {
                    _ec.PushError("Bad element in action buttons list.", this, ErrorType.Error, true);
                    return;
                }

                button.onClick.AddListener(() => ActionButtonClick(index));
                button.GetComponentInChildren<Text>().text = saveInfo.Info[i].IsNewGame ? "Start new game" : saveInfo.Info[i].Name;
            }
        }