ui基本完毕,修了一大把的bug
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using GameServer.Client;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class StartupSettingsApplier : MonoBehaviour
|
||||
{
|
||||
private const string BootstrapObjectName = "[StartupSettingsApplier]";
|
||||
private static StartupSettingsApplier _instance;
|
||||
private bool _started;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
private static void Bootstrap()
|
||||
{
|
||||
if (_instance != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject go = new GameObject(BootstrapObjectName);
|
||||
_instance = go.AddComponent<StartupSettingsApplier>();
|
||||
DontDestroyOnLoad(go);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_started = true;
|
||||
ApplyStartupSettings();
|
||||
StartCoroutine(SyncLeaderboardConsentRoutine());
|
||||
}
|
||||
|
||||
private void ApplyStartupSettings()
|
||||
{
|
||||
graphicSettings.ApplySavedDisplaySettingsAtStartup(this);
|
||||
ApplySavedAudioSettings();
|
||||
}
|
||||
|
||||
private void ApplySavedAudioSettings()
|
||||
{
|
||||
audioSettingsPreloader[] preloaders = FindObjectsByType<audioSettingsPreloader>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||||
for (int i = 0; i < preloaders.Length; i++)
|
||||
{
|
||||
audioSettingsPreloader preloader = preloaders[i];
|
||||
if (preloader == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
preloader.ApplyAudioSettings();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"[StartupSettingsApplier] Failed to apply audio settings via scene preloader: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator SyncLeaderboardConsentRoutine()
|
||||
{
|
||||
float timeoutAt = Time.realtimeSinceStartup + 8f;
|
||||
while (NetworkManager.Instance == null && Time.realtimeSinceStartup < timeoutAt)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
NetworkManager networkManager = NetworkManager.Instance;
|
||||
if (networkManager == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
bool isJoined = LeaderboardConsentUtility.HasLeaderboardConsent();
|
||||
var task = networkManager.UpdateLeaderboardMembership(isJoined);
|
||||
while (!task.IsCompleted)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (task.IsFaulted)
|
||||
{
|
||||
Exception ex = task.Exception;
|
||||
Debug.LogWarning($"[StartupSettingsApplier] Failed to sync leaderboard consent on startup: {ex?.GetBaseException().Message}");
|
||||
yield break;
|
||||
}
|
||||
|
||||
LeaderboardMembershipResponse response = task.Result;
|
||||
if (response != null)
|
||||
{
|
||||
LeaderboardConsentUtility.SetLeaderboardConsent(response.is_joined);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user