void setRopeLengthRelative(float value) { limitHinge(PendulumWeight.GetComponent <HingeJoint>(), 0); Vector3 currPos = PendulumWeight.transform.position; var obj = PendulumWeight.transform.Find("weight_obj"); var pos = obj.transform.position; float newVal = Math.Max(-RopeMaxLength, -ropeLength + value); newVal = Math.Min(newVal, -RopeMinLength); ropeLength = -newVal; pos.Set(transform.position.x, transform.position.y - ropeLength, transform.position.z); obj.transform.position = pos; /* * double theoretical_freq = 1 / (2 * Math.PI) * Math.Sqrt(Physics.gravity.magnitude / ropeLength); * var ec = GameEventBuilder.EnvironmentVariable( * this.name, * "theoretical_frequency", * theoretical_freq * ).Add( * GameEventBuilder.EnvironmentVariable( * this.name, * "theoretical_period", * 1 / theoretical_freq * ) * ); */ GuiPendulum.ShowFeedback( AssessmentManager.Instance.Send( GameEventBuilder.UseObject("operation", "ropelength_change") ).Feedback ); }
private static ColorCode ButtonSendPressed(TaskEntryManager.ButtonPressedEvent evt) { var msg = GameEventBuilder.AnswerQuestion(evt.Sender.VariableName, GetRealValue(evt.Sender.Text, evt.Sender.VariableType)); foreach (var inp in evt.ComponentGroup.InputFields) { var val = GetRealValue(inp.GUIField.text, inp.FBField.VariableType); msg.Add( GameEventBuilder.AnswerQuestion(inp.FBField.VariableName, val) ); } foreach (var inp in evt.ComponentGroup.DropDowns) { var val = GetRealValue(inp.GUIDropdown.options[inp.GUIDropdown.value].text, inp.FBDropdown.VariableType); msg.Add( GameEventBuilder.AnswerQuestion(inp.FBDropdown.VariableName, val) ); } foreach (var inp in evt.ComponentGroup.Toggles) { var val = GetRealValue(inp.GUIToggle.isOn.ToString(), inp.FBToggle.VariableType); msg.Add( GameEventBuilder.AnswerQuestion(inp.FBToggle.VariableName, val) ); } var fb = Send(msg); ShowFeedback(fb); return(fb.Any(e => e.ColorCode == ColorCode.Mistake) ? ColorCode.Mistake : fb.Any(e => e.ColorCode == ColorCode.Hint) ? ColorCode.Hint : ColorCode.Success); }
private void checkKeyboardInput() { if (!Input.anyKeyDown) { return; } if (GuiPendulum.isFocused()) { return; } if (Input.GetKeyDown(KeyCode.W)) { } if (Input.GetKeyDown(KeyCode.S)) { } if (Input.GetKeyDown(KeyCode.A)) { weight -= WeightChangeStepSize; GuiPendulum.ShowFeedback( AssessmentManager.Instance.Send( GameEventBuilder.UseObject("pendulum_weight", "decrease") ).Feedback ); } if (Input.GetKeyDown(KeyCode.D)) { weight += WeightChangeStepSize; GuiPendulum.ShowFeedback( AssessmentManager.Instance.Send( GameEventBuilder.UseObject("pendulum_weight", "increase") ).Feedback ); } if (Input.GetKeyDown(KeyCode.Q)) { Stopwatch.SendMessage("SWStart"); } if (Input.GetKeyDown(KeyCode.E)) { Stopwatch.SendMessage("SWStop"); } if (Input.GetKeyDown(KeyCode.Space)) { ExitExperiment(); } }
public static void ShowFeedback(FeedbackEntry[] feedback) { if (feedback.Length == 0) { return; } foreach (var fb in feedback) { if (fb.Type == FeedbackType.Technical) { if (fb.Text.ToLower() == "clear") { Clear(); Clear(); //dunno why we have to do that... Unity... } else if (fb.Text.ToLower().StartsWith("entersection")) { ShowFeedback(Send( GameEventBuilder.EnterSection(fb.Text.Split(':')[1]) )); } else if (fb.Text.ToLower() == "cleartext") { Instance.defaultText(); } } else if (fb.IsQuestion) { string text = fb.Text.Contains(";") ? fb.Text.Split(';').Aggregate((prev, curr) => LanguageManager.Instance.GetString(prev.Trim()) + " " + LanguageManager.Instance.GetString(curr.Trim())) : LanguageManager.Instance.GetString(fb.Text); var args = new TaskEntryManager.AddElementArguments() { Inputs = fb.Inputs, Text = text, SendHandler = ButtonSendPressed, }; Instance.TEM.AddElement(args); } else { ShowText(fb); } } }
private void CalculatorButtonPressed(Calculator.CalculatorButtonPressedEvent evt) { if (evt.Name != "enter") { return; } var ge = GameEventBuilder .EnvironmentVariable(name, "calculated_value", evt.CurrentNumber) .Add(GameEventBuilder.UseObject("operation", "submit-value")); var res = AssessmentManager.Instance.Send(ge); GuiPendulum.ShowFeedback(res.Feedback); }
public void Update() { HingeJoint joint = PendulumWeight.GetComponent <HingeJoint>(); joint.GetComponent <Rigidbody>().WakeUp(); if (Input.GetMouseButtonUp(0) && mouseDown) { Debug.Log("Sending Release action"); IterationResult res = AssessmentManager.Instance.Send(GameEventBuilder.UseObject("operation", "release")); GuiPendulum.ShowFeedback(res.Feedback); mouseDown = false; joint.useLimits = false; //AssessmentManager.Instance.PrintSummary(); } else if (Input.GetMouseButtonDown(0) || mouseDown) { if (!mouseDown) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (hit.transform.name == PendulumWeight.name) { mouseDown = true; mouseStart = Input.mousePosition; } else if (hit.transform.name == Stopwatch.name) { if (Stopwatch.GetComponent <StopWatch>().isRunning) { Stopwatch.SendMessage("SWStop"); } else { Stopwatch.SendMessage("SWStart"); } } else if (hit.transform.name == SlowMoObject.name) { if (slow) { Time.timeScale = 1.0f; GuiPendulum.ShowFeedback( AssessmentManager.Instance.Send( GameEventBuilder.UseObject("timelaps", "deactivate") ).Feedback ); } else { Time.timeScale = 0.2f; GuiPendulum.ShowFeedback( AssessmentManager.Instance.Send( GameEventBuilder.UseObject("timelaps", "activate") ).Feedback ); } Time.fixedDeltaTime = 0.02F * Time.timeScale; slow = !slow; } } } if (mouseDown) { //relative mouse movement / (scaling factor for easy use) var angle = ((mouseStart.x - Input.mousePosition.x) / (ropeLength * 10)); //Everything above 140 degrees seems to freak out unity enormously, just don't allow it angle = Math.Min(Math.Max(-140f, angle), 140f); limitHinge(joint, angle); } } else if (Input.GetMouseButtonDown(1)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (hit.transform.name == Stopwatch.name) { Stopwatch.SendMessage("SWReset"); } } } if (Input.GetAxis("Mouse ScrollWheel") > 0) { setRopeLengthRelative(RopeLengthChangeStepSize); } else if (Input.GetAxis("Mouse ScrollWheel") < 0) { setRopeLengthRelative(-RopeLengthChangeStepSize); } checkKeyboardInput(); assertPosition(); drawRopeAndAngle(); adjustWeight(); setText(); }
private void StopWatchStop(StopWatch.StopWatchEvent evt) { var res = AssessmentManager.Instance.Send(GameEventBuilder.UseObject("operation", "sw-stop")); GuiPendulum.ShowFeedback(res.Feedback); }
private static FeedbackEntry[] Send <T>(string name, T value) { return(Send(GameEventBuilder.AnswerQuestion(name, value))); }
private static void ButtonBoolPressed(string VariableName, bool value) { AssessmentManager.Instance.Send( GameEventBuilder.EnvironmentVariable("assessment", VariableName, value) ); }