ui基本完毕,修了一大把的bug
This commit is contained in:
@@ -42,6 +42,11 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
|
||||
private static List<dlcButton> allButtons = new List<dlcButton>();
|
||||
private static int selectedIndex = -1;
|
||||
private const string PlayerPrefsKey = "dlc_selected_index";
|
||||
private const string SelectedDlcIdPrefsKey = "dlc_selected_id";
|
||||
// When true, Select() applies visual selection but does NOT persist to
|
||||
// PlayerPrefs. Used during restore so re-selecting (including fallback)
|
||||
// never overwrites the user's genuine last choice.
|
||||
public static bool SuppressSelectionPersist = false;
|
||||
|
||||
private int instanceIndex = -1;
|
||||
private Coroutine hoverCoroutine;
|
||||
@@ -202,11 +207,38 @@ public class dlcButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandle
|
||||
{
|
||||
ApplySelectionToAll(instanceIndex);
|
||||
selectedIndex = instanceIndex;
|
||||
if (SuppressSelectionPersist)
|
||||
{
|
||||
if (VerboseLogs) Debug.Log($"dlcButton.Select: '{gameObject.name}' selected (index {instanceIndex}) without persisting (restore in progress)");
|
||||
return;
|
||||
}
|
||||
PlayerPrefs.SetInt(PlayerPrefsKey, selectedIndex);
|
||||
int dlcId = ResolveOwnDlcId();
|
||||
if (dlcId > 0)
|
||||
{
|
||||
PlayerPrefs.SetInt(SelectedDlcIdPrefsKey, dlcId);
|
||||
}
|
||||
PlayerPrefs.Save();
|
||||
if (VerboseLogs) Debug.Log($"dlcButton.Select: '{gameObject.name}' selected (index {instanceIndex}) and saved to PlayerPrefs");
|
||||
}
|
||||
|
||||
public static string SelectedDlcIdKey => SelectedDlcIdPrefsKey;
|
||||
|
||||
public int ResolveOwnDlcId()
|
||||
{
|
||||
if (dlcDataSO != null && dlcDataSO.dlcID > 0)
|
||||
{
|
||||
return dlcDataSO.dlcID;
|
||||
}
|
||||
|
||||
if (dlcID != null && int.TryParse(dlcID.text, out int parsedId))
|
||||
{
|
||||
return parsedId;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void ApplySelectionToAll(int selectIdx)
|
||||
{
|
||||
for (int i = 0; i < allButtons.Count; i++)
|
||||
|
||||
Reference in New Issue
Block a user