TargetView.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. private void Start()
  38. {
  39. if (GameMgr.HideTargetView) {
  40. Show(false);
  41. GameMgr.HideTargetView = false;
  42. }
  43. }
  44. void OnEnable()
  45. {
  46. RefreshButton();
  47. }
  48. void OnDisable()
  49. {
  50. RefreshButton();
  51. }
  52. void OnDestroy()
  53. {
  54. if (_ins == null) _ins = null;
  55. }
  56. private static TargetView _ins = null;
  57. public static TargetView ins {
  58. get {
  59. if (_ins == null) {
  60. _ins = GameObject.Find("Canvas/GameAssistUI/TargetView").GetComponent<TargetView>();
  61. }
  62. return _ins;
  63. }
  64. }
  65. }