UI HUGE UPDATE
This commit is contained in:
@@ -5,32 +5,44 @@ using System.Collections;
|
||||
|
||||
public class lrPrefab : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
{
|
||||
[Header("sprite")]
|
||||
public Sprite enableSprite;
|
||||
public Sprite availableSprite;
|
||||
public Sprite lockedSprite;
|
||||
public Sprite unknownSprite;
|
||||
public Sprite preSelectSprite;
|
||||
|
||||
[Header("uis")]
|
||||
public Text levelName;
|
||||
public Image levelid_btm;
|
||||
public Image statusImg;
|
||||
public Text thisSkillName;
|
||||
|
||||
[Header("state visuals")]
|
||||
public Sprite lockedStatusSprite;
|
||||
public Color selectableSkillNameColor = Color.white;
|
||||
public Color unavailableSkillNameColor = Color.gray;
|
||||
|
||||
[Header("desOBJ")]
|
||||
public GameObject descriptionPrefab;
|
||||
public float descriptionOffsetX = 80f;
|
||||
|
||||
[Header("material")]
|
||||
public Material grayScale_mtr;
|
||||
|
||||
[Header("preselect pulse")]
|
||||
public float preselectPulseDuration = 0.8f;
|
||||
|
||||
private uLevel_skills owner;
|
||||
private userLevel_skills_SO ownerSo;
|
||||
private userLevel_skills_SO.UserLevelSkillEntry boundEntry;
|
||||
private int boundIndex = -1;
|
||||
private bool isUnlocked = false;
|
||||
private Coroutine hoverCoroutine;
|
||||
private Coroutine preselectPulseCoroutine;
|
||||
private GameObject spawnedDescription;
|
||||
private bool visualDefaultsCached = false;
|
||||
private Sprite defaultStatusSprite;
|
||||
private Material defaultStatusMaterial;
|
||||
private Material defaultLevelIdMaterial;
|
||||
|
||||
public void Bind(uLevel_skills ownerController, userLevel_skills_SO sourceSo, int index, userLevel_skills_SO.UserLevelSkillEntry entry, bool unlocked)
|
||||
{
|
||||
CacheVisualDefaults();
|
||||
|
||||
owner = ownerController;
|
||||
ownerSo = sourceSo;
|
||||
boundIndex = index;
|
||||
@@ -59,21 +71,129 @@ public class lrPrefab : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
thisSkillName.text = shouldHideLockedSkillInfo
|
||||
? "?????"
|
||||
: (boundEntry.skillName ?? string.Empty);
|
||||
thisSkillName.color = isUnlocked ? selectableSkillNameColor : unavailableSkillNameColor;
|
||||
}
|
||||
|
||||
if (statusImg == null)
|
||||
return;
|
||||
|
||||
if (owner != null && owner.IsSkillPreselected(boundIndex))
|
||||
statusImg.sprite = preSelectSprite != null ? preSelectSprite : availableSprite;
|
||||
else if (boundEntry.isEnabled)
|
||||
statusImg.sprite = enableSprite;
|
||||
else if (isUnlocked)
|
||||
statusImg.sprite = availableSprite;
|
||||
else if (shouldHideLockedSkillInfo)
|
||||
statusImg.sprite = unknownSprite != null ? unknownSprite : lockedSprite;
|
||||
else
|
||||
statusImg.sprite = lockedSprite;
|
||||
bool isPreselected = owner != null && owner.IsSkillPreselected(boundIndex);
|
||||
ApplyStatusState(isPreselected);
|
||||
}
|
||||
|
||||
private void ApplyStatusState(bool isPreselected)
|
||||
{
|
||||
if (statusImg == null)
|
||||
return;
|
||||
|
||||
StopPreselectPulse();
|
||||
|
||||
if (!isUnlocked)
|
||||
{
|
||||
SetStatusSprite(lockedStatusSprite != null ? lockedStatusSprite : defaultStatusSprite);
|
||||
SetStatusMaterial(defaultStatusMaterial);
|
||||
SetLevelIdMaterial(grayScale_mtr);
|
||||
SetStatusAlpha(1f);
|
||||
return;
|
||||
}
|
||||
|
||||
SetStatusSprite(defaultStatusSprite);
|
||||
|
||||
if (isPreselected)
|
||||
{
|
||||
SetStatusMaterial(defaultStatusMaterial);
|
||||
SetLevelIdMaterial(defaultLevelIdMaterial);
|
||||
StartPreselectPulse();
|
||||
return;
|
||||
}
|
||||
|
||||
if (boundEntry != null && boundEntry.isEnabled)
|
||||
{
|
||||
SetStatusMaterial(defaultStatusMaterial);
|
||||
SetLevelIdMaterial(defaultLevelIdMaterial);
|
||||
SetStatusAlpha(1f);
|
||||
return;
|
||||
}
|
||||
|
||||
SetStatusMaterial(grayScale_mtr);
|
||||
SetLevelIdMaterial(defaultLevelIdMaterial);
|
||||
SetStatusAlpha(1f);
|
||||
}
|
||||
|
||||
private void CacheVisualDefaults()
|
||||
{
|
||||
if (visualDefaultsCached)
|
||||
return;
|
||||
|
||||
visualDefaultsCached = true;
|
||||
defaultStatusSprite = statusImg != null ? statusImg.sprite : null;
|
||||
defaultStatusMaterial = statusImg != null ? statusImg.material : null;
|
||||
defaultLevelIdMaterial = levelid_btm != null ? levelid_btm.material : null;
|
||||
}
|
||||
|
||||
private void SetStatusSprite(Sprite spriteToApply)
|
||||
{
|
||||
if (statusImg == null)
|
||||
return;
|
||||
|
||||
statusImg.sprite = spriteToApply;
|
||||
}
|
||||
|
||||
private void SetStatusMaterial(Material materialToApply)
|
||||
{
|
||||
if (statusImg == null)
|
||||
return;
|
||||
|
||||
statusImg.material = materialToApply;
|
||||
}
|
||||
|
||||
private void SetLevelIdMaterial(Material materialToApply)
|
||||
{
|
||||
if (levelid_btm == null)
|
||||
return;
|
||||
|
||||
levelid_btm.material = materialToApply;
|
||||
}
|
||||
|
||||
private void SetStatusAlpha(float alpha)
|
||||
{
|
||||
if (statusImg == null)
|
||||
return;
|
||||
|
||||
Color color = statusImg.color;
|
||||
color.a = Mathf.Clamp01(alpha);
|
||||
statusImg.color = color;
|
||||
}
|
||||
|
||||
private void StartPreselectPulse()
|
||||
{
|
||||
if (!isActiveAndEnabled || statusImg == null)
|
||||
return;
|
||||
|
||||
preselectPulseCoroutine = StartCoroutine(PreselectPulseRoutine());
|
||||
}
|
||||
|
||||
private void StopPreselectPulse()
|
||||
{
|
||||
if (preselectPulseCoroutine != null)
|
||||
{
|
||||
StopCoroutine(preselectPulseCoroutine);
|
||||
preselectPulseCoroutine = null;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator PreselectPulseRoutine()
|
||||
{
|
||||
float duration = Mathf.Max(0.05f, preselectPulseDuration);
|
||||
float elapsed = 0f;
|
||||
|
||||
while (true)
|
||||
{
|
||||
elapsed += Time.unscaledDeltaTime;
|
||||
float normalizedTime = Mathf.PingPong(elapsed / duration, 1f);
|
||||
SetStatusAlpha(Mathf.Lerp(0.5f, 1f, normalizedTime));
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
@@ -173,6 +293,8 @@ public class lrPrefab : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
StopPreselectPulse();
|
||||
|
||||
if (hoverCoroutine != null)
|
||||
{
|
||||
StopCoroutine(hoverCoroutine);
|
||||
|
||||
Reference in New Issue
Block a user