コード例 #1
0
        void Start()
        {
            singlePlayerButton.onClick.AddListener(SceneLoader.instance.GoToSingleplayerMenu);
            mainMenuButton.onClick.AddListener(SceneLoader.instance.GoToMainMenu);

            saveSlots = new List <GameObject>();

            campaignActionButton.interactable = false;

            var allSlots = CampaignManager.instance.CampaignDataSlots
                           .OrderByDescending(slot => slot.TimeStamp);

            if (allSlots.Count() == 0)
            {
                var button = CreateButton("Start New Story...");
                button.onClick.AddListener(() => {
                    selectedGameObject = button.gameObject;
                    var buttonImage    = selectedGameObject.GetComponent <Image>();
                    buttonImage.color  = SELECTED_COLOR;
                    campaignActionButton.interactable = true;
                });
                var actionLabel = campaignActionButton.gameObject.GetComponentInChildren <TextMeshProUGUI>();
                actionLabel.text = "Start";
                campaignActionButton.onClick.AddListener(() => {
                    SceneLoader.instance.GoToCampaignNewStoryMenu();
                });
            }
            else
            {
                foreach (var slot in allSlots)
                {
                    var button = CreateButton(CampaignManager.DataToString(slot));
                    button.onClick.AddListener(() => {
                        if (selectedGameObject != null)
                        {
                            var selectedButton   = selectedGameObject.GetComponent <Image>();
                            selectedButton.color = UNSELECTED_COLOR;
                        }
                        selectedSaveSlot   = slot;
                        selectedGameObject = button.gameObject;
                        var buttonImage    = selectedGameObject.GetComponent <Image>();
                        buttonImage.color  = SELECTED_COLOR;
                        campaignActionButton.interactable = true;
                    });
                }

                campaignActionButton.onClick.AddListener(LoadButton);
            }
            campaignCancelButton.onClick.AddListener(() => {
                SceneLoader.instance.GoToLastMenu();
            });
        }
コード例 #2
0
        private void Awake()
        {
            //Check if instance already exists
            if (instance == null)
            {
                //if not, set instance to this
                instance = this;
            }

            //If instance already exists and it's not this:
            else if (instance != this)
            {
                //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
                Destroy(gameObject);
            }

            DontDestroyOnLoad(this.gameObject);
        }
コード例 #3
0
        void Start()
        {
            saveSlots = new List <GameObject>();

            saveSlots.Add(campaignCreateNewDataButton.gameObject);

            campaignSaveButton.interactable = false;

            campaignCreateNewDataButton.onClick.AddListener(() => {
                if (selectedGameObject != null)
                {
                    var selectedButton   = selectedGameObject.GetComponent <Image>();
                    selectedButton.color = UNSELECTED_COLOR;
                }
                selectedSaveSlot   = null;
                selectedGameObject = campaignCreateNewDataButton.gameObject;
                var buttonImage    = selectedGameObject.GetComponent <Image>();
                buttonImage.color  = SELECTED_COLOR;
                campaignSaveButton.interactable = true;
            });

            var allSlots = CampaignManager.instance.CampaignDataSlots
                           .OrderByDescending(slot => slot.TimeStamp);

            foreach (var slot in allSlots)
            {
                var button = CreateButton(CampaignManager.DataToString(slot));
                button.onClick.AddListener(() => {
                    if (selectedGameObject != null)
                    {
                        var selectedButton   = selectedGameObject.GetComponent <Image>();
                        selectedButton.color = UNSELECTED_COLOR;
                    }
                    selectedSaveSlot   = slot;
                    selectedGameObject = button.gameObject;
                    var buttonImage    = selectedGameObject.GetComponent <Image>();
                    buttonImage.color  = SELECTED_COLOR;
                    campaignSaveButton.interactable = true;
                });
            }

            campaignSaveButton.onClick.AddListener(SaveButton);
            campaignContinueButton.onClick.AddListener(ContinueButton);
        }
コード例 #4
0
        private void SaveButton()
        {
            CampaignData newData = null;

            if (selectedSaveSlot == null)
            {
                newData = CampaignManager.instance.SaveNewCampaign();
            }
            else
            {
                newData = CampaignManager.instance.SaveCampaign(selectedSaveSlot);
            }

            if (newData != null)
            {
                var newLabel = selectedGameObject.GetComponentInChildren <TextMeshProUGUI>();
                newLabel.text = CampaignManager.DataToString(newData);
                dataSaved     = true;
            }
        }