using MS; using UnityEngine; using UnityEngine.UI; /// /// Add list of achievements to screen /// public class AchievenmentListIngame : MonoBehaviour { public GameObject scrollContent; public GameObject prefab; public Popup Menu; public Dropdown Filter; public Text CountText; public Text CompleteText; public Scrollbar Scrollbar; private bool MenuOpen = false; [Tooltip("Key used to open UI menu. Set to \"None\" to prevent menu from opening with any key press")] // public KeyCode OpenMenuKey; //Key to open in-game menu /// /// Adds all achievements to the UI based on a filter /// /// Filter to use (All, Achieved or Unachieved) private void AddAchievements(string Filter) { foreach (Transform child in scrollContent.transform) { Destroy(child.gameObject); } AchievementManager AM = AchievementManager.instance; int AchievedCount = AM.GetAchievedCount(); if(CountText) CountText.text = "" + AchievedCount + " / " + AM.States.Count; if(CompleteText) CompleteText.text = "Complete (" + AM.GetAchievedPercentage() + "%)"; for (int i = 0; i < AM.AchievementList.Count; i ++) { if((Filter.Equals("All")) || (Filter.Equals("Achieved") && AM.States[i].Achieved) || (Filter.Equals("Unachieved") && !AM.States[i].Achieved)) { AddAchievementToUI(AM.AchievementList[i], AM.States[i]); } } Scrollbar.value = 1; } public void AddAchievementToUI(AchievementInfromation Achievement, AchievementState State) { UIAchievement UIAchievement = Instantiate(prefab, new Vector3(0f, 0f, 0f), Quaternion.identity).GetComponent(); UIAchievement.Set(Achievement, State); UIAchievement.transform.SetParent(scrollContent.transform); UIAchievement.GetComponent().localScale= Vector3.one; } /// /// Filter out a set of locked or unlocked achievements /// public void ChangeFilter () { AddAchievements(Filter.options[Filter.value].text); } /// /// Closes the UI window. /// public void CloseWindow() { MenuOpen = false; Menu.Close(); } /// /// Opens the UI window. /// public void OpenWindow() { MenuOpen = true; Menu.Open(); AddAchievements("All"); } /// /// Toggles the state of the UI window open or closed /// public void ToggleWindow() { if (MenuOpen){ CloseWindow(); } else{ OpenWindow(); } } // private void Update() // { // if(Input.GetKeyDown(OpenMenuKey)) // { // ToggleWindow(); // } // } }