public void SetupList() { IEnumerable <TechniqueMetaData> metaDataCollection = TechniqueFileHelper.GetAllTechniquesMeta(); foreach (Transform child in TechniqueLayout.transform) { if (!metaDataCollection.Any(t => t.TechniqueName == child.name)) { Destroy(child.gameObject); } } foreach (TechniqueMetaData meta in metaDataCollection) { GameObject techniqueGameObject = GameObject.Find(meta.TechniqueName); if (techniqueGameObject == null) { techniqueGameObject = Instantiate(ButtonPrefab); techniqueGameObject.name = meta.TechniqueName; techniqueGameObject.transform.SetParent(TechniqueLayout.transform, false); } Button button = techniqueGameObject.GetComponent <Button>(); TextMeshProUGUI[] texts = button.GetComponentsInChildren <TextMeshProUGUI>(); foreach (TextMeshProUGUI text in texts) { if (text.name == "TechniqueDataText") { text.text = $"Name: {meta.TechniqueName}\n" + $"Recorded by: {meta.UserName}"; } else if (text.name == "UserStatsText") { bool shouldDisplayDefault = !meta.HasBeenAttempted; string date = shouldDisplayDefault ? "N/A" : meta.LastAttemptedDateTime.ToShortDateString(); text.text = $"Last attempted: {date}\n" + $"Last Score: {(shouldDisplayDefault ? "N/A" : (int) meta.LastScorePercent + "%")}\n" + $"Best Score: {(shouldDisplayDefault ? "N/A" : (int) meta.BestScorePercent + "%")}"; } } if (techniqueGameObject.GetComponent <ClickListener>() == null) { ClickListener clickListener = techniqueGameObject.AddComponent <ClickListener>(); clickListener.OnRightClick += delegate { promptToDelete.text = string.Format(DELETE, meta.TechniqueName); VariableHolder.TechniqueToDelete = meta.TechniqueName; MenuControl.OnStateChanged(MenuStates.DeleteTechnique, false); }; clickListener.OnLeftClick += delegate { Technique loadedTechnique = TechniqueFileHelper.Load(meta.TechniqueName); TrainingActions.Init(loadedTechnique); MenuControl.OnStateChanged(MenuStates.TrainingPreview); }; } } }
private void SetupList(IEnumerable <TechniqueMetaData> allMetaData) { foreach (Transform child in techniqueLayout.transform) { Destroy(child.gameObject); } foreach (TechniqueMetaData meta in allMetaData) { GameObject techniqueGameObject = Instantiate(techniqueListItemPrefab); techniqueGameObject.name = meta.TechniqueName; techniqueGameObject.transform.SetParent(techniqueLayout.transform, false); TextMeshProUGUI[] texts = techniqueGameObject.GetComponentsInChildren <TextMeshProUGUI>(); foreach (TextMeshProUGUI text in texts) { switch (text.name) { case "Technique Label": text.text = $"Name: {meta.TechniqueName}\n" + $"Recorded by: {meta.UserName}"; break; case "Attempt Label": if (meta.HasBeenAttempted) { text.text = $"Last attempted: {meta.LastAttemptedDateTime.ToShortDateString()}\n" + $"Last Score: {(int)meta.LastScorePercent + "%"}\n" + $"Best Score: {(int)meta.BestScorePercent + "%"}"; } break; } } Button uploadButton = techniqueGameObject.GetComponentInChildren <Button>(); ClickListener clickListener = uploadButton.gameObject.AddComponent <ClickListener>(); clickListener.OnLeftClick += delegate { Technique loadedTechnique = TechniqueFileHelper.Load(meta.TechniqueName); UnityWebRequest request = null; switch (uploadOption) { case UploadOptions.Technique: request = APIHelper.CreateTechnique(loadedTechnique); break; case UploadOptions.Attempt: request = APIHelper.SendAttempt(loadedTechnique); break; } }; } }