1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using Unity.Services.Core;
- using Unity.Services.Core.Environments;
- using UnityEngine;
- using UnityEngine.UI;
-
- namespace Samples.Purchasing.Core.InitializeGamingServices
- {
- public class InitializeGamingServices : MonoBehaviour
- {
- public Text informationText;
-
- const string k_Environment = "production";
-
- void Awake()
- {
- // Uncomment this line to initialize Unity Gaming Services.
- // Initialize(OnSuccess, OnError);
- }
-
- void Initialize(Action onSuccess, Action<string> onError)
- {
- try
- {
- var options = new InitializationOptions().SetEnvironmentName(k_Environment);
-
- UnityServices.InitializeAsync(options).ContinueWith(task => onSuccess());
- }
- catch (Exception exception)
- {
- onError(exception.Message);
- }
- }
-
- void OnSuccess()
- {
- var text = "Congratulations!\nUnity Gaming Services has been successfully initialized.";
- informationText.text = text;
- Debug.Log(text);
- }
-
- void OnError(string message)
- {
- var text = $"Unity Gaming Services failed to initialize with error: {message}.";
- informationText.text = text;
- Debug.LogError(text);
- }
-
- void Start()
- {
- if (UnityServices.State == ServicesInitializationState.Uninitialized)
- {
- var text =
- "Error: Unity Gaming Services not initialized.\n" +
- "To initialize Unity Gaming Services, open the file \"InitializeGamingServices.cs\" " +
- "and uncomment the line \"Initialize(OnSuccess, OnError);\" in the \"Awake\" method.";
- informationText.text = text;
- Debug.LogError(text);
- }
- }
- }
- }
|