ui基本完毕,修了一大把的bug
This commit is contained in:
@@ -12,6 +12,8 @@ using UnityEngine.SceneManagement;
|
||||
public class SongDetailsUI : MonoBehaviour
|
||||
{
|
||||
private const string BackSceneName = "selectYourSongFirst";
|
||||
private const float ProgressNumberMinX = -370f;
|
||||
private const float ProgressNumberMaxX = 362f;
|
||||
|
||||
[Header("this_song_SO")]
|
||||
public ScriptableObject this_song_SO;
|
||||
@@ -53,6 +55,7 @@ public class SongDetailsUI : MonoBehaviour
|
||||
public Image progressImage;
|
||||
public GameObject progressNumberObject;
|
||||
public TextMeshProUGUI progressPercentText;
|
||||
public Text progressPercentText2;
|
||||
|
||||
public Image rankLevel_img;
|
||||
public RankConfig rc;
|
||||
@@ -83,6 +86,21 @@ public class SongDetailsUI : MonoBehaviour
|
||||
private UnityAction difficultyHdAction;
|
||||
private UnityAction difficultyInAction;
|
||||
private UnityAction difficultyImAction;
|
||||
private RectTransform progressImageRect;
|
||||
private RectTransform progressNumberRect;
|
||||
private float progressImageFullWidth = -1f;
|
||||
private float progressImageLeftEdgeX;
|
||||
private float progressImageScaleX = 1f;
|
||||
private bool progressUsesMaskWidthMode;
|
||||
[SerializeField] private float progressTweenDuration = 0.35f;
|
||||
[SerializeField] private Ease progressTweenEase = Ease.OutCubic;
|
||||
|
||||
private Tween progressBarTween;
|
||||
private Tween progressNumberTween;
|
||||
private Tween progressTextTween;
|
||||
private float currentProgressVisual;
|
||||
private float currentProgressTextValue;
|
||||
private bool hasStarted;
|
||||
|
||||
private SongData ResolveCurrentSong()
|
||||
{
|
||||
@@ -109,6 +127,7 @@ public class SongDetailsUI : MonoBehaviour
|
||||
private void OnEnable()
|
||||
{
|
||||
currentSong = ResolveCurrentSong();
|
||||
CacheProgressUiGeometry(forceRefresh: false);
|
||||
|
||||
ArenaRoomService roomService = ArenaRoomService.Instance;
|
||||
if (roomService != null)
|
||||
@@ -143,7 +162,12 @@ public class SongDetailsUI : MonoBehaviour
|
||||
|
||||
BindDifficultyButtons();
|
||||
PrepareDifficultyButtons();
|
||||
SyncSongDisplay(true);
|
||||
|
||||
if (hasStarted)
|
||||
{
|
||||
ResetProgressVisualState();
|
||||
SyncSongDisplay(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -153,6 +177,8 @@ public class SongDetailsUI : MonoBehaviour
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
KillProgressTweens();
|
||||
|
||||
ArenaRoomService roomService = ArenaRoomService.Instance;
|
||||
if (roomService != null)
|
||||
{
|
||||
@@ -328,9 +354,12 @@ public class SongDetailsUI : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
hasStarted = true;
|
||||
picDetail.SetActive(false);
|
||||
CacheProgressUiGeometry(forceRefresh: false);
|
||||
BindDifficultyButtons();
|
||||
PrepareDifficultyButtons();
|
||||
ResetProgressVisualState();
|
||||
SyncSongDisplay(true);
|
||||
}
|
||||
|
||||
@@ -757,9 +786,6 @@ public class SongDetailsUI : MonoBehaviour
|
||||
if (difficultyIdText != null)
|
||||
difficultyIdText.text = entry.difficultyLEVEL.ToString("0.0");
|
||||
|
||||
if (progressImage != null)
|
||||
progressImage.fillAmount = entry.levelProgressForThisDifficulty;
|
||||
|
||||
UpdateProgressUI(entry.levelProgressForThisDifficulty);
|
||||
|
||||
// read values from SongData (SO)
|
||||
@@ -807,8 +833,6 @@ public class SongDetailsUI : MonoBehaviour
|
||||
difficultyText.text = difficulty.ToString();
|
||||
if (difficultyIdText != null)
|
||||
difficultyIdText.text = difficulty.ToString();
|
||||
if (progressImage != null)
|
||||
progressImage.fillAmount = 0f;
|
||||
UpdateProgressUI(0f);
|
||||
if (difficultyDesciptionText != null)
|
||||
difficultyDesciptionText.text = "";
|
||||
@@ -827,33 +851,169 @@ public class SongDetailsUI : MonoBehaviour
|
||||
|
||||
private void UpdateProgressUI(float progress)
|
||||
{
|
||||
// 1. Update Text (can exceed 100%)
|
||||
if (progressPercentText != null)
|
||||
{
|
||||
progressPercentText.text = Mathf.FloorToInt(progress * 100f).ToString() + "%";
|
||||
}
|
||||
CacheProgressUiGeometry(forceRefresh: false);
|
||||
|
||||
// 2. Clamp for visual elements (fillAmount and Object position)
|
||||
float clampedProgress = Mathf.Clamp01(progress);
|
||||
|
||||
// Update fillAmount again just in case, though handled in caller
|
||||
if (progressImage != null)
|
||||
AnimateProgressVisual(clampedProgress);
|
||||
AnimateProgressText(progress);
|
||||
}
|
||||
|
||||
private void CacheProgressUiGeometry(bool forceRefresh)
|
||||
{
|
||||
if (progressImage != null && (forceRefresh || progressImageRect == null))
|
||||
{
|
||||
progressImage.fillAmount = clampedProgress;
|
||||
progressImageRect = progressImage.rectTransform;
|
||||
}
|
||||
|
||||
// 3. Update Object Position (Linear transformation: 0% -> -785, 100% -> -195)
|
||||
if (progressNumberObject != null)
|
||||
if (progressNumberObject != null && (forceRefresh || progressNumberRect == null))
|
||||
{
|
||||
RectTransform rect = progressNumberObject.GetComponent<RectTransform>();
|
||||
if (rect != null)
|
||||
{
|
||||
float targetX = Mathf.Lerp(-785f, -195f, clampedProgress);
|
||||
Vector2 anchoredPos = rect.anchoredPosition;
|
||||
anchoredPos.x = targetX;
|
||||
rect.anchoredPosition = anchoredPos;
|
||||
}
|
||||
progressNumberRect = progressNumberObject.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
if (progressImageRect == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (forceRefresh || progressImageFullWidth <= 0f)
|
||||
{
|
||||
progressImageFullWidth = progressImageRect.sizeDelta.x;
|
||||
progressImageScaleX = Mathf.Abs(progressImageRect.localScale.x);
|
||||
progressImageLeftEdgeX = progressImageRect.anchoredPosition.x - (progressImageFullWidth * progressImageScaleX * 0.5f);
|
||||
}
|
||||
|
||||
progressUsesMaskWidthMode = progressImage != null
|
||||
&& progressImage.GetComponent<Mask>() != null
|
||||
&& progressImage.transform.childCount > 0;
|
||||
}
|
||||
|
||||
private void ResetProgressVisualState()
|
||||
{
|
||||
CacheProgressUiGeometry(forceRefresh: false);
|
||||
KillProgressTweens();
|
||||
currentProgressVisual = 0f;
|
||||
currentProgressTextValue = 0f;
|
||||
ApplyProgressBarVisual(0f);
|
||||
ApplyProgressNumberPosition(0f);
|
||||
ApplyProgressTextValue(0f);
|
||||
}
|
||||
|
||||
private void KillProgressTweens()
|
||||
{
|
||||
if (progressBarTween != null && progressBarTween.IsActive())
|
||||
{
|
||||
progressBarTween.Kill();
|
||||
}
|
||||
|
||||
if (progressNumberTween != null && progressNumberTween.IsActive())
|
||||
{
|
||||
progressNumberTween.Kill();
|
||||
}
|
||||
|
||||
if (progressTextTween != null && progressTextTween.IsActive())
|
||||
{
|
||||
progressTextTween.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
private void AnimateProgressVisual(float clampedProgress)
|
||||
{
|
||||
KillProgressTweens();
|
||||
|
||||
progressBarTween = DOTween.To(
|
||||
() => currentProgressVisual,
|
||||
value =>
|
||||
{
|
||||
currentProgressVisual = value;
|
||||
ApplyProgressBarVisual(value);
|
||||
},
|
||||
clampedProgress,
|
||||
progressTweenDuration)
|
||||
.SetEase(progressTweenEase)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
currentProgressVisual = clampedProgress;
|
||||
ApplyProgressBarVisual(clampedProgress);
|
||||
});
|
||||
|
||||
if (progressNumberRect != null)
|
||||
{
|
||||
progressNumberTween = progressNumberRect
|
||||
.DOAnchorPosX(Mathf.Lerp(ProgressNumberMinX, ProgressNumberMaxX, clampedProgress), progressTweenDuration)
|
||||
.SetEase(progressTweenEase);
|
||||
}
|
||||
}
|
||||
|
||||
private void AnimateProgressText(float targetProgressValue)
|
||||
{
|
||||
float safeTargetValue = Mathf.Max(0f, targetProgressValue);
|
||||
|
||||
progressTextTween = DOTween.To(
|
||||
() => currentProgressTextValue,
|
||||
value =>
|
||||
{
|
||||
currentProgressTextValue = value;
|
||||
ApplyProgressTextValue(value);
|
||||
},
|
||||
safeTargetValue,
|
||||
progressTweenDuration)
|
||||
.SetEase(progressTweenEase)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
currentProgressTextValue = safeTargetValue;
|
||||
ApplyProgressTextValue(safeTargetValue);
|
||||
});
|
||||
}
|
||||
|
||||
private void ApplyProgressNumberPosition(float clampedProgress)
|
||||
{
|
||||
if (progressNumberRect == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 anchoredPos = progressNumberRect.anchoredPosition;
|
||||
anchoredPos.x = Mathf.Lerp(ProgressNumberMinX, ProgressNumberMaxX, clampedProgress);
|
||||
progressNumberRect.anchoredPosition = anchoredPos;
|
||||
}
|
||||
|
||||
private void ApplyProgressTextValue(float progressValue)
|
||||
{
|
||||
int percentValue = Mathf.FloorToInt(Mathf.Max(0f, progressValue) * 100f);
|
||||
string textValue = percentValue.ToString() + "%";
|
||||
|
||||
if (progressPercentText != null)
|
||||
{
|
||||
progressPercentText.text = textValue;
|
||||
}
|
||||
|
||||
if (progressPercentText2 != null)
|
||||
{
|
||||
progressPercentText2.text = textValue;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyProgressBarVisual(float clampedProgress)
|
||||
{
|
||||
if (progressImage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (progressUsesMaskWidthMode && progressImageRect != null && progressImageFullWidth > 0f)
|
||||
{
|
||||
float newWidth = progressImageFullWidth * clampedProgress;
|
||||
progressImageRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, newWidth);
|
||||
|
||||
Vector2 anchoredPos = progressImageRect.anchoredPosition;
|
||||
anchoredPos.x = progressImageLeftEdgeX + (newWidth * progressImageScaleX * 0.5f);
|
||||
progressImageRect.anchoredPosition = anchoredPos;
|
||||
return;
|
||||
}
|
||||
|
||||
progressImage.fillAmount = clampedProgress;
|
||||
}
|
||||
|
||||
private ChartFileEntry GetChartEntry(int difficulty)
|
||||
|
||||
Reference in New Issue
Block a user