12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UIElements;
- public class StatusController : MonoBehaviour
- {
- public Button backButton;
- public Label nameLabel, genderLabel, breedLabel, hostLabel, hostnameLabel, ageLabel, ageValueLabel, statusLabel, statusValueLabel;
- // Start is called before the first frame update
- void Start()
- {
- var root = GetComponent<UIDocument>().rootVisualElement;
- backButton = root.Q<Button>("back");
- nameLabel = root.Q<Label>("name");
- genderLabel = root.Q<Label>("gender");
- breedLabel = root.Q<Label>("breed");
- hostLabel = root.Q<Label>("host");
- hostnameLabel = root.Q<Label>("hostname");
- ageLabel = root.Q<Label>("age");
- ageValueLabel = root.Q<Label>("ageValue");
- statusLabel = root.Q<Label>("status");
- statusValueLabel = root.Q<Label>("statusValue");
- StatusPageUpdate();
- }
- // Update is called once per frame
- //void Update()
- //{
- //}
- void BackPressed()
- {
- if (backButton != null)
- {
- var root = GetComponent<UIDocument>();
- Destroy(GameObject.Find(root.GetComponentInParent<Canvas>().name));
- }
- }
- void StatusPageUpdate()
- {
- backButton.clicked += BackPressed;
- nameLabel.text = DogProperty.name;
- if (DogProperty.gender == 1) {
- genderLabel.text = "♂";
- }
- else
- {
- genderLabel.text = "♀";
- }
- breedLabel.text = DogProperty.breed;
- hostnameLabel.text = UserProperty.name;
- // 计算狗生日和现在时间差
- TimeSpan ts = System.DateTime.Now - DogProperty.brithday;
- ageValueLabel.text = ts.Days.ToString();
- }
- }
|