OlympusGame.Startup.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using Cysharp.Threading.Tasks;
  3. using UnityEngine;
  4. namespace Olympus
  5. {
  6. public sealed partial class OlympusGame
  7. {
  8. enum StartAvailability { NotChecked, Checking, Allowed, Blocked, Failed }
  9. StartAvailability startAvailability;
  10. bool CanStartGame => startAvailability == StartAvailability.Allowed;
  11. void InitializeAppRuntime()
  12. {
  13. try { AppRuntimes.Initialization(); }
  14. catch (Exception e)
  15. {
  16. startAvailability = StartAvailability.Failed;
  17. Debug.LogError("App initialization failed: " + e.GetType().Name);
  18. }
  19. }
  20. // One request per game instance; rebuilding the identity page reuses its result.
  21. async void CheckStartAvailability(Func<UniTask<bool>> checkVersion)
  22. {
  23. if (startAvailability != StartAvailability.NotChecked) return;
  24. startAvailability = StartAvailability.Checking;
  25. RefreshStartAvailability();
  26. try
  27. {
  28. bool handledByPlatform = await checkVersion().AttachExternalCancellation(destroyCancellationToken);
  29. if (!this) return;
  30. startAvailability = handledByPlatform ? StartAvailability.Blocked : StartAvailability.Allowed;
  31. }
  32. catch (OperationCanceledException) when (!this || destroyCancellationToken.IsCancellationRequested)
  33. {
  34. return;
  35. }
  36. catch (Exception e)
  37. {
  38. if (!this) return;
  39. startAvailability = StartAvailability.Failed;
  40. Debug.LogWarning("Start availability check failed: " + e.GetType().Name);
  41. }
  42. RefreshStartAvailability();
  43. }
  44. void RefreshStartAvailability()
  45. {
  46. if (currentScreen != "Start" || !suiteView || suiteView.screen != "Start") return;
  47. suiteView.Button("GAME START").interactable = CanStartGame;
  48. string status = startAvailability == StartAvailability.Allowed
  49. ? "SINGLE PLAYER · SAVED ON THIS DEVICE"
  50. : startAvailability == StartAvailability.Blocked
  51. ? "GAME START IS UNAVAILABLE"
  52. : startAvailability == StartAvailability.Failed
  53. ? "UNABLE TO CHECK. PLEASE RESTART."
  54. : "CHECKING AVAILABILITY...";
  55. Set(suiteView, "Offline label", status);
  56. }
  57. }
  58. }