private void Initialize() { //Read registry keys to setup buttons activity if (!MusicManager.instance.isMusic) { music.GetComponent <Image>().color -= new Color(0, 0, 0, 0.5f); } if (!MusicManager.instance.isSounds) { sound.GetComponent <Image>().color -= new Color(0, 0, 0, 0.5f); } //Attach OnClick methods to menu buttons music.onClick.AddListener(() => StaticBehaviors.MusicClick(music)); sound.onClick.AddListener(() => StaticBehaviors.SoundsClick(sound)); backToGame.onClick.AddListener(() => gameObject.SetActive(false)); backToMainMenu.onClick.AddListener(() => StaticBehaviors.LoadScene(0)); exit.onClick.AddListener(() => Application.Quit()); }
//Provide each directory with data private void SetDirectoryData(GameObject go, string dirName) { currentTask = DataManager.Instance.GetData(dirName); //Get saved data for directory currentInfo = currentTask.savedData; int completeLevels = currentInfo.currentLevel - 1; int dirLength = currentTask.dirLength; go.transform.Find("Image").GetComponent <Image>().sprite = completeLevels == 0 ? defaultPicture : CreateSprite(dirName); //Set up directory view go.transform.Find("Text1").GetComponent <Text>().text = currentTask.localizedDir.ToUpper(); //Should it be unlocked? if (CheckIsLocked(dirName)) { go.transform.Find("Text2").GetComponent <Text>().text = DataManager.Instance.GetLocalizedValue(ElementType.locked_text).ToUpper(); go.GetComponent <Button>().onClick.AddListener(() => MusicManager.instance.PlaySound("wrong")); go.transform.GetComponent <Image>().color -= new Color(0, 0, 0, 0.4f); } else { go.transform.Find("Text2").GetComponent <Text>().text = completeLevels + "\u002f" + dirLength; //Set up progress bar float barPercent = (float)completeLevels / (float)dirLength; RectTransform bar = go.transform.Find("Bar/ProgressBar").GetComponent <RectTransform>(); bar.anchoredPosition += new Vector2((bar.sizeDelta.x * barPercent), 0); if (barPercent < 1) { //Add OnClick methods to directory buttons if there are not completed yet go.GetComponent <Button>().onClick.AddListener(() => DataManager.Instance.currentDir = dirName); go.GetComponent <Button>().onClick.AddListener(() => StaticBehaviors.LoadScene(1)); } else { go.GetComponent <Button>().onClick.AddListener(() => SpawnGallery(dirName)); } } }