using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class TabItem : MonoBehaviour { public CustomItem customItem; public Image showIcon; public Text nameText; public Sprite nochoseSprite; public Sprite choseSprite; public Font nochoseFont; public Font choseFont; public Vector2 posPercent; private RectTransform parentRectTransform; private RectTransform rectTransform; void Awake() { parentRectTransform = transform.parent.GetComponent(); rectTransform=GetComponent(); #if UNITY_EDITOR Debug.Log("地图比例:"+gameObject.name + " " + rectTransform.anchoredPosition.x / parentRectTransform.rect.width + " " + rectTransform.anchoredPosition.y / parentRectTransform.rect.height); #endif } void Update() { rectTransform.anchoredPosition = new Vector2(posPercent.x * parentRectTransform.rect.width, posPercent.y * parentRectTransform.rect.height); } public void PointIn(BaseEventData data) { showIcon.gameObject.SetActive(true); GetComponent().sprite = choseSprite; //联动 if (customItem != null) { nameText.fontSize = 80; nameText.font = choseFont; nameText.color= Color.white; customItem.PointIn(null); } } public void PointOut(BaseEventData data) { //选中此关区,不切换状态 if (customItem != null && FirstPanel.currentChoseCustonItem == customItem) { return; } SetNoChoseState(); } /// /// 未选中状态 /// public void SetNoChoseState() { showIcon.gameObject.SetActive(false); GetComponent().sprite = nochoseSprite; //联动 if (customItem != null) { nameText.fontSize = 60; nameText.font = nochoseFont; nameText.color = new Color(148f / 255f, 184f / 255f, 1, 1); customItem.PointOut(null); } } /// /// 点击海关标签 /// /// public void Click(BaseEventData data) { if (customItem != null) { //点海关,进入海关页面 customItem.EnterCity(); //其他状态取消 FirstPanel.instance.tab.GetComponentsInChildren().ToList().ForEach(a => { if(a!=this) { a.SetNoChoseState(); } else { //标签状态选中 a.PointIn(null); } }); } } }