CreateOrAdopt.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Cinemachine;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. /* 第一次创建狗的时候选择创建或者是领养
  5. */
  6. public class CreateOrAdopt : MonoBehaviour
  7. {
  8. private Label message;
  9. private Button create, adopt;
  10. GameObject canvasPlaceholder, initDogCanvas, CreateAdoptCanvas;
  11. // Start is called once before the first execution of Update after the MonoBehaviour is created
  12. void Start()
  13. {
  14. var root = GetComponent<UIDocument>().rootVisualElement;
  15. message = root.Q<Label>("message");
  16. create = root.Q<Button>("create");
  17. adopt = root.Q<Button>("adopt");
  18. canvasPlaceholder = GameObject.Find("Canvas Placeholder");
  19. initDogCanvas = canvasPlaceholder.transform.Find("Init Dog Canvas").gameObject;
  20. CreateAdoptCanvas = canvasPlaceholder.transform.Find("Create Or Adopt Canvas").gameObject;
  21. create.RegisterCallback<ClickEvent>(e => CreateClick(e));
  22. adopt.RegisterCallback<ClickEvent>(e => AdoptClick(e));
  23. string textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "InitDogUI", "button", "create", EnviromentSetting.languageCode });
  24. create.text = textValue;
  25. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "InitDogUI", "button", "adopt", EnviromentSetting.languageCode });
  26. adopt.text = textValue;
  27. textValue = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "InitDogUI", "label", "create or adopt msg", EnviromentSetting.languageCode });
  28. message.text = textValue;
  29. if (UserProperty.dogs.Count > 0)
  30. {
  31. SwitchToCreate();
  32. }
  33. }
  34. // Update is called once per frame
  35. //void Update()
  36. //{
  37. //}
  38. void SwitchToCreate()
  39. {
  40. initDogCanvas.SetActive(true);
  41. CreateAdoptCanvas.SetActive(false);
  42. }
  43. void SwitchToAdopt()
  44. {
  45. // todo 扫码从别人那边继承狗
  46. }
  47. void CreateClick(ClickEvent e)
  48. {
  49. SwitchToCreate();
  50. }
  51. void AdoptClick(ClickEvent e)
  52. {
  53. SwitchToAdopt();
  54. }
  55. }