using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /* 靶子画中画 */ public class TargetView : MonoBehaviour { public void Show(bool value) { this.gameObject.SetActive(value); } public bool IsOpen() { return this.gameObject.activeSelf; } public void ReverseActive() { this.gameObject.SetActive(!this.gameObject.activeSelf); } [SerializeField] Button button; void RefreshButton() { Transform icon1 = button.transform.Find("Icon1"); Transform icon2 = button.transform.Find("Icon2"); if (IsOpen()) { icon1.gameObject.SetActive(false); icon2.gameObject.SetActive(true); button.transform.Find("Text").gameObject.SetActive(false); button.GetComponentInChildren()?.SetText(205); } else { icon1.gameObject.SetActive(true); icon2.gameObject.SetActive(false); button.transform.Find("Text").gameObject.SetActive(true); button.GetComponentInChildren().SetText(204); } } private void Start() { if (GameMgr.HideTargetView) { Show(false); GameMgr.HideTargetView = false; } } void OnEnable() { RefreshButton(); } void OnDisable() { RefreshButton(); } void OnDestroy() { if (_ins == null) _ins = null; } private static TargetView _ins = null; public static TargetView ins { get { if (_ins == null) { _ins = GameObject.Find("Canvas/GameAssistUI/TargetView").GetComponent(); } return _ins; } } }