TargetView.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.GetComponentInChildren<TextAutoLanguage>().SetText(205);
  29. } else {
  30. icon1.gameObject.SetActive(true);
  31. icon2.gameObject.SetActive(false);
  32. button.GetComponentInChildren<TextAutoLanguage>().SetText(204);
  33. }
  34. }
  35. void OnEnable()
  36. {
  37. RefreshButton();
  38. }
  39. void OnDisable()
  40. {
  41. RefreshButton();
  42. }
  43. void OnDestroy()
  44. {
  45. if (_ins == null) _ins = null;
  46. }
  47. private static TargetView _ins = null;
  48. public static TargetView ins {
  49. get {
  50. if (_ins == null) {
  51. _ins = GameObject.Find("Canvas/GameAssistUI/TargetView").GetComponent<TargetView>();
  52. }
  53. return _ins;
  54. }
  55. }
  56. }