/// <summary> /// Helper method to fill in an Achievement Display given an Achievement /// </summary> /// <param name="curr"> Current Display object </param> /// <param name="a"> Achievement to use </param> public void MakeDisplay(GameObject curr, Achievement a) { // Get the Tiers child Transform tiers = curr.transform.Find("Tiers"); // Get the Progress Bar child Transform progressBars = curr.transform.Find("Progress Bars"); // Create a tier for every activation value if (a is A_Tiered) { A_Tiered at = (A_Tiered)a; for (int i = 0; i < at.activationValues.Length; i++) { Instantiate(tierPrefab, tiers); Instantiate(progressBarPrefab, progressBars); } // Set size of tier GridLayoutGroup tglg = tiers.GetComponent <GridLayoutGroup>(); tglg.cellSize = new Vector2(tglg.cellSize.x / at.activationValues.Length, tglg.cellSize.y); // Set size of progress bars GridLayoutGroup pbglg = progressBars.GetComponent <GridLayoutGroup>(); pbglg.cellSize = new Vector2(pbglg.cellSize.x / at.activationValues.Length, pbglg.cellSize.y); // Set progress bars int currentValue = at.currentValue; for (int i = 0; i < at.activationValues.Length; i++) { // Current working bar Transform bar = progressBars.GetChild(i); // This tiers max int max = at.activationValues[i]; // Check if this bar needs scaled at all, break if not if (i > 0 && currentValue < at.activationValues[i - 1]) { break; } // Check if this bar has been met/exceeded else if (currentValue >= max) { bar.localScale = new Vector3(1f, bar.localScale.y, bar.localScale.z); } // Set the bar scale else { bar.localScale = new Vector3(currentValue / max, bar.localScale.y, bar.localScale.z); } } } else if (a is A_Repeatable) { A_Repeatable ar = (A_Repeatable)a; // create tiers and progress bars for (int i = 0; i < ar.repeatValue; i++) { Instantiate(tierPrefab, tiers); Instantiate(progressBarPrefab, progressBars); } // Set size of tier GridLayoutGroup tglg = tiers.GetComponent <GridLayoutGroup>(); tglg.cellSize = new Vector2(tglg.cellSize.x / ar.repeatValue, tglg.cellSize.y); // Set size of progress bars GridLayoutGroup pbglg = progressBars.GetComponent <GridLayoutGroup>(); pbglg.cellSize = new Vector2(pbglg.cellSize.x / ar.repeatValue, pbglg.cellSize.y); int currentValue = ar.currentValue % ar.repeatValue; for (int j = 0; j < ar.repeatValue; j++) { // Current working bar Transform bar = progressBars.GetChild(j); // set bar to full if past or at progress if (j < currentValue) { bar.localScale = new Vector3(1f, bar.localScale.y, bar.localScale.z); } else { break; } } } /** Set fields in display */ // Name curr.transform.Find("Name").gameObject.GetComponent <TMP_Text>().text = a.achievementMessage; // Description curr.transform.Find("Description").gameObject.GetComponent <TMP_Text>().text = a.ToString(); // Current Count curr.transform.Find("Current Count").gameObject.GetComponent <TMP_Text>().text = "Current Count: " + a.currentValue.ToString(); // Next Count & set finished if (a is A_Tiered) { A_Tiered at = (A_Tiered)a; if (!at.IsComplete()) { curr.transform.Find("Next Count").gameObject.GetComponent <TMP_Text>().text = "Next Count: " + at.activationValues[at.nextTier].ToString(); curr.transform.Find("Finished").gameObject.SetActive(false); } else { curr.transform.Find("Next Count").gameObject.GetComponent <TMP_Text>().text = "Achieved"; curr.transform.Find("Finished").gameObject.SetActive(true); } } }
private void FixedUpdate() { // Select "Return to Main" button based on screen if (!playing && Gamepad.current[GamepadButton.B].isPressed && currentMenu != MainMenu) { if (currentMenu == AchievementsMenu) { // Clear selected object EventSystem.current.SetSelectedGameObject(null); // Set button to OfflineFirst EventSystem.current.SetSelectedGameObject(achievementsReturnButton); } else if (currentMenu == LoadoutMenu) { // Clear selected object EventSystem.current.SetSelectedGameObject(null); // Set button to OfflineFirst EventSystem.current.SetSelectedGameObject(loadoutReturnButton); } else if (currentMenu == TrainingMenu) { // Clear selected object EventSystem.current.SetSelectedGameObject(null); // Set button to OfflineFirst EventSystem.current.SetSelectedGameObject(trainingReturnButton); } } if (SceneManager.GetSceneByName("L_MainMenu").isLoaded) { // update Achievements Menu if (AchievementsMenu.activeSelf) { for (int i = 0; i < AchievementManager.Instance().achievements.Count; i++) { // Get Achievement Achievement a = AchievementManager.Instance().achievements[i]; // Get Achievement Display Transform curr = achievementContent.transform.GetChild(i); // Get Progress Bars for Display Transform progressBars = curr.Find("Progress Bars"); // Update progress bars if tiered if (a is A_Tiered) { // cast A_Tiered at = (A_Tiered)a; int currentValue = at.currentValue; for (int j = 0; j < at.activationValues.Length; j++) { // Current working bar Transform bar = progressBars.GetChild(j); // This tiers max int max = at.activationValues[j]; // Check if this bar needs scaled at all -> Zero the scale if (j > 0 && currentValue < at.activationValues[j - 1]) { bar.localScale = new Vector3(0f, bar.localScale.y, bar.localScale.z); } // Check if this bar has been met/exceeded -> Max the scale else if (currentValue >= max) { bar.localScale = new Vector3(1f, bar.localScale.y, bar.localScale.z); } // Set the bar scale else { float percent = 0f; if (j > 0) { int delta = at.activationValues[j - 1]; percent = (currentValue - delta) / ((float)max - delta); } else { percent = currentValue / (float)max; } /*float percent = currentValue / (float)max;*/ bar.localScale = new Vector3(percent, bar.localScale.y, bar.localScale.z); } } } else if (a is A_Repeatable) { A_Repeatable ar = (A_Repeatable)a; int currentValue = ar.currentValue % ar.repeatValue; for (int j = 0; j < ar.repeatValue; j++) { // Current working bar Transform bar = progressBars.GetChild(j); // set bar to full if past or at progress if (j < currentValue) { bar.localScale = new Vector3(1f, bar.localScale.y, bar.localScale.z); } else { bar.localScale = new Vector3(0f, bar.localScale.y, bar.localScale.z); } } } /** Set fields in display */ // Name curr.transform.Find("Name").gameObject.GetComponent <TMP_Text>().text = a.achievementMessage; // Description curr.transform.Find("Description").gameObject.GetComponent <TMP_Text>().text = a.ToString(); // Current Count curr.transform.Find("Current Count").gameObject.GetComponent <TMP_Text>().text = "Current Count: " + a.currentValue.ToString(); // Next Count & set finished if (a is A_Tiered) { A_Tiered at = (A_Tiered)a; if (!at.IsComplete() && at.nextTier < at.activationValues.Length) { curr.transform.Find("Next Count").gameObject.GetComponent <TMP_Text>().text = "Next Count: " + at.activationValues[at.nextTier].ToString(); curr.transform.Find("Finished").gameObject.SetActive(false); } else { curr.transform.Find("Next Count").gameObject.GetComponent <TMP_Text>().text = "Achieved"; curr.transform.Find("Finished").gameObject.SetActive(true); } } } } } }