using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; namespace SuperScrollView { public class ContentFitterItem : MonoBehaviour { public TextMeshProUGUI mNameText; ContentFitterItemData mItemData; int mItemDataIndex = -1; public Image mImageSelect; public int ItemIndex { get { return mItemDataIndex; } set { mItemDataIndex = value; } } System.Action mOnClickItemCallBack; public void Init(System.Action OnClickItemCallBack = null) { ClickEventListener listener = ClickEventListener.Get(gameObject); listener.SetClickEventHandler(OnButtonClicked); mOnClickItemCallBack = OnClickItemCallBack; } void OnButtonClicked(GameObject obj) { if(mOnClickItemCallBack != null) { mOnClickItemCallBack(mItemDataIndex); } } public void SetItemData(ContentFitterItemData itemData, int itemIndex) { mItemData = itemData; mItemDataIndex = itemIndex; mNameText.text = itemData.mName; mNameText.GetComponent().SetLayoutVertical(); Vector2 size = mNameText.GetComponent().rect.size; RectTransform tf = gameObject.GetComponent(); //float y = size.y+40; //if (y < 75) //{ // y = 75; //} float y = size.y + 40; tf.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, y); } public void SetItemSelected(bool isSelected) { if(mImageSelect != null) { mImageSelect.gameObject.SetActive(isSelected); } if (isSelected) { mNameText.color = new Color(0.278f, 0.831f, 0.921f, 1); } else { mNameText.color = new Color(1, 1, 1, 1); } } } }