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 ReceiveTechnique(NetworkMessage message) { StringMessage techniqueJson = message.ReadMessage <StringMessage>(); Technique t = JsonUtility.FromJson <Technique>(techniqueJson.value); TechniqueFileHelper.Save(t); OnTechniqueReceived?.Invoke(); }
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; } }; } }
public void SendTechnique(string techniqueName) { Technique t = TechniqueFileHelper.LoadClean(techniqueName); string techniqueJson = JsonUtility.ToJson(t); foreach (NetworkConnection conn in connections) { SendString(TECHNIQUE_SENT, conn, techniqueJson); } OnTechniqueSent?.Invoke(); }
public void FinishTraining(IEnumerable <Skeleton> recordedFrames) { technique.UserAttemptFrames = recordedFrames.Select(s => (SerializableSkeleton)s).ToArray(); ComparisonData data = comparer.Evaluate(technique); //List<float> totalScores = data.FrameComparisons.Select(x => x.JointScores.Values.Min()).ToList(); //float totalScore = totalScores.Average(); float totalScore = data.TotalScore; technique.LastAttemptedDateTime = DateTime.Now; newRecordLabel.enabled = TechniqueFileHelper.RegisterAttempt(technique, totalScore); FinalScoreBar.UpdateScore(totalScore); }
public void Export() { errorText.text = String.Empty; string techniqueName = TechniqueNameField.text; string userName = UserNameField.text; bool validTechName = ValidTechName(); bool validUserName = ValidUserName(); bool validData = validUserName && validTechName; if (!validUserName) { errorText.text += "Invalid username.\n"; } if (!validTechName) { errorText.text += "Invalid technique name"; } if (validData) { SerializableSkeleton[] techniqueFrames = Playback.SkeletonFrames .Where((s, i) => i >= Playback.StartFrame && i < Playback.EndFrame) .ToArray(); TechniqueFileHelper.Save(new Technique(techniqueName, techniqueFrames, userName)); exportedText.text = $"{techniqueName} exported successfully."; menuControl.OnStateChanged(MenuStates.ExportFinished); } else { menuControl.OnStateChanged(MenuStates.ErrorEdit, false); } }
public void DeleteTechnique() { TechniqueFileHelper.DeleteTechnique(VariableHolder.TechniqueToDelete); deletedConfirmText.text = $"{VariableHolder.TechniqueToDelete} successfully deleted."; }
public void SetupListTechniques() { uploadOption = UploadOptions.Attempt; SetupList(TechniqueFileHelper.GetCleanTechniquesMeta()); }
public void SetupListAttempts() { uploadOption = UploadOptions.Technique; SetupList(TechniqueFileHelper.GetAllAttemptedTechniquesMeta()); }