TargetView.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. /* 靶子画中画 */
  6. public class TargetView : MonoBehaviour
  7. {
  8. public void Show(bool value)
  9. {
  10. this.gameObject.SetActive(value);
  11. }
  12. public bool IsOpen()
  13. {
  14. return this.gameObject.activeSelf;
  15. }
  16. public void ReverseActive()
  17. {
  18. this.gameObject.SetActive(!this.gameObject.activeSelf);
  19. }
  20. [SerializeField] Button button;
  21. void RefreshButton()
  22. {
  23. Transform icon1 = button.transform.Find("Icon1");
  24. Transform icon2 = button.transform.Find("Icon2");
  25. if (IsOpen()) {
  26. icon1.gameObject.SetActive(false);
  27. icon2.gameObject.SetActive(true);
  28. button.transform.Find("Text").gameObject.SetActive(false);
  29. button.GetComponentInChildren<TextAutoLanguage>()?.SetText(205);
  30. } else {
  31. icon1.gameObject.SetActive(true);
  32. icon2.gameObject.SetActive(false);
  33. button.transform.Find("Text").gameObject.SetActive(true);
  34. button.GetComponentInChildren<TextAutoLanguage>().SetText(204);
  35. }
  36. }
  37. void OnEnable()
  38. {
  39. RefreshButton();
  40. }
  41. void OnDisable()
  42. {
  43. RefreshButton();
  44. }
  45. void OnDestroy()
  46. {
  47. if (_ins == null) _ins = null;
  48. }
  49. private static TargetView _ins = null;
  50. public static TargetView ins {
  51. get {
  52. if (_ins == null) {
  53. _ins = GameObject.Find("Canvas/GameAssistUI/TargetView").GetComponent<TargetView>();
  54. }
  55. return _ins;
  56. }
  57. }
  58. }