using System.Collections; using System.Collections.Generic; 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(); //posPercent = new Vector2(); //posPercent.x = rectTransform.anchoredPosition.x / parentRectTransform.rect.width; //posPercent.y= rectTransform.anchoredPosition.y / parentRectTransform.rect.height; //print(gameObject.name +" "+ posPercent.x+" "+ posPercent.y); } 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) { 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(); } } }