StatusController.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UIElements;
  6. public class StatusController : MonoBehaviour
  7. {
  8. public Button backButton;
  9. public Label nameLabel, genderLabel, breedLabel, hostLabel, hostnameLabel, ageLabel, ageValueLabel, statusLabel, statusValueLabel;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. var root = GetComponent<UIDocument>().rootVisualElement;
  14. backButton = root.Q<Button>("back");
  15. nameLabel = root.Q<Label>("name");
  16. genderLabel = root.Q<Label>("gender");
  17. breedLabel = root.Q<Label>("breed");
  18. hostLabel = root.Q<Label>("host");
  19. hostnameLabel = root.Q<Label>("hostname");
  20. ageLabel = root.Q<Label>("age");
  21. ageValueLabel = root.Q<Label>("ageValue");
  22. statusLabel = root.Q<Label>("status");
  23. statusValueLabel = root.Q<Label>("statusValue");
  24. StatusPageUpdate();
  25. }
  26. // Update is called once per frame
  27. //void Update()
  28. //{
  29. //}
  30. void BackPressed()
  31. {
  32. if (backButton != null)
  33. {
  34. var root = GetComponent<UIDocument>();
  35. Destroy(GameObject.Find(root.GetComponentInParent<Canvas>().name));
  36. }
  37. }
  38. void StatusPageUpdate()
  39. {
  40. backButton.clicked += BackPressed;
  41. nameLabel.text = DogProperty.name;
  42. if (DogProperty.gender == 1) {
  43. genderLabel.text = "♂";
  44. }
  45. else
  46. {
  47. genderLabel.text = "♀";
  48. }
  49. breedLabel.text = DogProperty.breed;
  50. hostnameLabel.text = UserProperty.name;
  51. // 计算狗生日和现在时间差
  52. TimeSpan ts = System.DateTime.Now - DogProperty.brithday;
  53. ageValueLabel.text = ts.Days.ToString();
  54. }
  55. }