115 lines
3.4 KiB
C#
115 lines
3.4 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace OCTOPUS_TWIN
|
|
{
|
|
public class ProjectItemView : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
|
{
|
|
[SerializeField] private TextMeshProUGUI textTitle;
|
|
[SerializeField] private TextMeshProUGUI textDesc;
|
|
[SerializeField] private Image imageThumbnail;
|
|
[SerializeField] private GameObject imageLock;
|
|
[SerializeField] private Button btnSelect;
|
|
[SerializeField] private Image hoverOverlayImage;
|
|
|
|
[Header("애니메이션 시간 (초)")]
|
|
[SerializeField] private float fadeDuration = 0.3f;
|
|
|
|
private ProjectData myData;
|
|
private bool _isLocked = false;
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (hoverOverlayImage == null || _isLocked == true)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 실행 중이던 이전 애니메이션이 있다면 즉시 중단 (버벅임 방지)
|
|
hoverOverlayImage.DOKill();
|
|
|
|
// 색상을 1로 duration 동안 변경
|
|
hoverOverlayImage.DOFade(1f, fadeDuration);
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
FadeOut();
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
FadeOut();
|
|
|
|
// 클릭 후 버튼에 남는 '선택된 상태' 잔상 제거
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
}
|
|
|
|
private void FadeOut()
|
|
{
|
|
if (hoverOverlayImage == null) return;
|
|
hoverOverlayImage.DOKill();
|
|
hoverOverlayImage.DOFade(0f, fadeDuration);
|
|
}
|
|
|
|
// UI 갱신
|
|
private void UpdateUI(ProjectData data)
|
|
{
|
|
myData = data;
|
|
if (textTitle) textTitle.text = data.projectName;
|
|
if (textDesc) textDesc.text = data.description;
|
|
if (imageThumbnail) imageThumbnail.sprite = data.thumbnail;
|
|
|
|
if (hoverOverlayImage != null)
|
|
{
|
|
hoverOverlayImage.sprite = data.hover;
|
|
|
|
// 처음엔 투명하게 숨김
|
|
Color c = hoverOverlayImage.color;
|
|
c.a = 0f;
|
|
hoverOverlayImage.color = c;
|
|
}
|
|
}
|
|
|
|
// 클릭 가능한 프로젝트 세팅
|
|
public void Setup(ProjectData data, Action<ProjectData> onClickCallback)
|
|
{
|
|
UpdateUI(data);
|
|
|
|
imageLock.SetActive(false); // 잠금 화면 해제
|
|
|
|
// 재사용될 때를 대비해 버튼을 반드시 다시 켜줘야 함
|
|
btnSelect.enabled = true;
|
|
btnSelect.interactable = true; // 시각적 활성화
|
|
|
|
btnSelect.onClick.RemoveAllListeners();
|
|
btnSelect.onClick.AddListener(() => onClickCallback?.Invoke(myData));
|
|
|
|
_isLocked = false;
|
|
|
|
}
|
|
|
|
// 열리지 않는 프로젝트 세팅
|
|
public void Setup(ProjectData data, Action onLockedClick)
|
|
{
|
|
UpdateUI(data);
|
|
|
|
// 잠금 화면 설정
|
|
imageLock.SetActive(true);
|
|
|
|
// 버튼 기능 끄지 않음
|
|
btnSelect.enabled = true;
|
|
btnSelect.interactable = true;
|
|
|
|
// 안전을 위해 리스너 제거
|
|
btnSelect.onClick.RemoveAllListeners();
|
|
btnSelect.onClick.AddListener(() => onLockedClick?.Invoke());
|
|
|
|
_isLocked = true;
|
|
}
|
|
}
|
|
} |