73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
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>();
|
|
rectTransform=GetComponent<RectTransform>();
|
|
//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<Image>().sprite = choseSprite;
|
|
//联动
|
|
if (customItem != null)
|
|
{
|
|
nameText.fontSize = 20;
|
|
nameText.font = choseFont;
|
|
nameText.color= Color.white;
|
|
customItem.PointIn(null);
|
|
}
|
|
}
|
|
|
|
public void PointOut(BaseEventData data)
|
|
{
|
|
showIcon.gameObject.SetActive(false);
|
|
GetComponent<Image>().sprite = nochoseSprite;
|
|
//联动
|
|
if(customItem != null)
|
|
{
|
|
nameText.fontSize = 15;
|
|
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();
|
|
}
|
|
}
|
|
}
|