Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.5 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Assertions;
  5. using UnityEngine.UI;
  6. // Show off all the Debug UI components.
  7. public class DebugUISample : MonoBehaviour
  8. {
  9. bool inMenu;
  10. private Text sliderText;
  11. void Start ()
  12. {
  13. DebugUIBuilder.instance.AddButton("Button Pressed", LogButtonPressed);
  14. DebugUIBuilder.instance.AddLabel("Label");
  15. var sliderPrefab = DebugUIBuilder.instance.AddSlider("Slider", 1.0f, 10.0f, SliderPressed, true);
  16. var textElementsInSlider = sliderPrefab.GetComponentsInChildren<Text>();
  17. Assert.AreEqual(textElementsInSlider.Length, 2, "Slider prefab format requires 2 text components (label + value)");
  18. sliderText = textElementsInSlider[1];
  19. Assert.IsNotNull(sliderText, "No text component on slider prefab");
  20. sliderText.text = sliderPrefab.GetComponentInChildren<Slider>().value.ToString();
  21. DebugUIBuilder.instance.AddDivider();
  22. DebugUIBuilder.instance.AddToggle("Toggle", TogglePressed);
  23. DebugUIBuilder.instance.AddRadio("Radio1", "group", delegate(Toggle t) { RadioPressed("Radio1", "group", t); }) ;
  24. DebugUIBuilder.instance.AddRadio("Radio2", "group", delegate(Toggle t) { RadioPressed("Radio2", "group", t); }) ;
  25. DebugUIBuilder.instance.AddLabel("Secondary Tab", 1);
  26. DebugUIBuilder.instance.AddDivider(1);
  27. DebugUIBuilder.instance.AddRadio("Side Radio 1", "group2", delegate(Toggle t) { RadioPressed("Side Radio 1", "group2", t); }, DebugUIBuilder.DEBUG_PANE_RIGHT);
  28. DebugUIBuilder.instance.AddRadio("Side Radio 2", "group2", delegate(Toggle t) { RadioPressed("Side Radio 2", "group2", t); }, DebugUIBuilder.DEBUG_PANE_RIGHT);
  29. DebugUIBuilder.instance.Show();
  30. inMenu = true;
  31. }
  32. public void TogglePressed(Toggle t)
  33. {
  34. Debug.Log("Toggle pressed. Is on? "+t.isOn);
  35. }
  36. public void RadioPressed(string radioLabel, string group, Toggle t)
  37. {
  38. Debug.Log("Radio value changed: "+radioLabel+", from group "+group+". New value: "+t.isOn);
  39. }
  40. public void SliderPressed(float f)
  41. {
  42. Debug.Log("Slider: " + f);
  43. sliderText.text = f.ToString();
  44. }
  45. void Update()
  46. {
  47. if(OVRInput.GetDown(OVRInput.Button.Two) || OVRInput.GetDown(OVRInput.Button.Start))
  48. {
  49. if (inMenu) DebugUIBuilder.instance.Hide();
  50. else DebugUIBuilder.instance.Show();
  51. inMenu = !inMenu;
  52. }
  53. }
  54. void LogButtonPressed()
  55. {
  56. Debug.Log("Button pressed");
  57. }
  58. }