설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InitializeGamingServices.cs 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using Unity.Services.Core;
  3. using Unity.Services.Core.Environments;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace Samples.Purchasing.Core.InitializeGamingServices
  7. {
  8. public class InitializeGamingServices : MonoBehaviour
  9. {
  10. public Text informationText;
  11. const string k_Environment = "production";
  12. void Awake()
  13. {
  14. // Uncomment this line to initialize Unity Gaming Services.
  15. // Initialize(OnSuccess, OnError);
  16. }
  17. void Initialize(Action onSuccess, Action<string> onError)
  18. {
  19. try
  20. {
  21. var options = new InitializationOptions().SetEnvironmentName(k_Environment);
  22. UnityServices.InitializeAsync(options).ContinueWith(task => onSuccess());
  23. }
  24. catch (Exception exception)
  25. {
  26. onError(exception.Message);
  27. }
  28. }
  29. void OnSuccess()
  30. {
  31. var text = "Congratulations!\nUnity Gaming Services has been successfully initialized.";
  32. informationText.text = text;
  33. Debug.Log(text);
  34. }
  35. void OnError(string message)
  36. {
  37. var text = $"Unity Gaming Services failed to initialize with error: {message}.";
  38. informationText.text = text;
  39. Debug.LogError(text);
  40. }
  41. void Start()
  42. {
  43. if (UnityServices.State == ServicesInitializationState.Uninitialized)
  44. {
  45. var text =
  46. "Error: Unity Gaming Services not initialized.\n" +
  47. "To initialize Unity Gaming Services, open the file \"InitializeGamingServices.cs\" " +
  48. "and uncomment the line \"Initialize(OnSuccess, OnError);\" in the \"Awake\" method.";
  49. informationText.text = text;
  50. Debug.LogError(text);
  51. }
  52. }
  53. }
  54. }