Exemple #1
0
        /// <summary>
        /// Initialize the CotcSdk's Cloud instance.
        /// </summary>
        public static void Handling_InitializeCloud()
        {
            // Find the CotcGameObject instance in the scene
            CotcGameObject cotcGameObject = GameObject.FindObjectOfType <CotcGameObject>();

            if (cotcGameObject == null)
            {
                DebugLogs.LogError("[CotcSdkTemplate:CloudFeatures] Please attach a CotcGameObject script on an active object of your scene! (CotcSdk features are not available otherwise)");
                return;
            }

            // Register to the UnhandledException event
            Promise.UnhandledException += LogUnhandledException;

            // Get and keep the Cloud instance reference
            Backend_GetCloud(cotcGameObject, InitializeCloud_OnSuccess, InitializeCloud_OnError);
        }
Exemple #2
0
        /// <summary>
        /// Get the CotcSdk's Cloud instance.
        /// </summary>
        /// <param name="cotcGameObject">CotcSdk's CotcGameObject instance.</param>
        /// <param name="OnSuccess">The callback in case of request success.</param>
        /// <param name="OnError">The callback in case of request error.</param>
        public static void Backend_GetCloud(CotcGameObject cotcGameObject, Action <Cloud> OnSuccess = null, Action <ExceptionError> OnError = null)
        {
            // Call the API method which returns a Cloud result
            cotcGameObject.GetCloud()
            // Result if everything went well
            .Done(delegate(Cloud cloudInstance)
            {
                DebugLogs.LogVerbose("[CotcSdkTemplate:CloudFeatures] GetCloud success");

                // Keep the Cloud instance reference
                cloud = cloudInstance;

                // Register to the HttpRequestFailedHandler event
                cloud.HttpRequestFailedHandler = RetryFailedRequestOnce;

                // Call the OnSuccess action if any callback registered to it
                if (OnSuccess != null)
                {
                    OnSuccess(cloudInstance);
                }

                // Call the CloudInitialized event if any callback registered to it
                if (Event_CloudInitialized != null)
                {
                    Event_CloudInitialized(cloud);
                }
            },
                  // Result if an error occured
                  delegate(Exception exception)
            {
                // Call the OnError action if any callback registered to it
                if (OnError != null)
                {
                    OnError(ExceptionTools.GetExceptionError(exception));
                }
                // Else, log the error (expected to be a CotcException)
                else
                {
                    ExceptionTools.LogCotcException("CloudFeatures", "GetCloud", exception);
                }
            });
        }
Exemple #3
0
    public void OnEmailConnexionClick()
    {
        CotcGameObject cotc  = FindObjectOfType <CotcGameObject>();
        string         email = GameObject.Find("Email").GetComponent <InputField>().text;
        string         mdp   = GameObject.Find("MotDePasse").GetComponent <InputField>().text;

        cotc.GetCloud().Done(cloud => {
            cloud.Login(
                network: "email",
                networkId: email,
                networkSecret: mdp)
            .Done(gamer => {
                Player = gamer;
                Debug.Log("Signed in succeeded (ID = " + gamer.GamerId + ")");
                Debug.Log("Login data: " + gamer);
                Debug.Log("Server time: " + gamer["servertime"]);
                connectedWithAccount = true;
                GuiControl.OnReturnClick();
            }, ex => {
                // The exception should always be CotcException
                CotcException error = (CotcException)ex;
                if (error.ServerData["name"] == "BadArgument")
                {
                    GameObject.Find("Error").GetComponent <Text>().text = "Erreur, l'adresse e-mail ou le mot de passe n'est pas valide.";
                }
                else if (error.ServerData["name"] == "BadUserCredentials")
                {
                    GameObject.Find("Error").GetComponent <Text>().text = "Erreur, le mot de passe n'est pas correcte.";
                }
                else
                {
                    GameObject.Find("Error").GetComponent <Text>().text = "Erreur.";
                }
            });
        });
    }
Exemple #4
0
    public void AnonymeConnexion()
    {
        CotcGameObject cotc = FindObjectOfType <CotcGameObject>();

        cotc.GetCloud().Done(cloud =>
        {
            cloud.LoginAnonymously()
            .Done(gamer =>
            {
                Debug.Log("Signed in succeeded (ID = " + gamer.GamerId + ")");
                Debug.Log("Signed in succeeded (Secret = " + gamer.GamerSecret + ")");
                Debug.Log("Login data: " + gamer);
                Debug.Log("Server time: " + gamer["servertime"]);
                connected = true;
                Player    = gamer;
                SetUserValue("MaxScore", new Bundle(0));
            }, ex =>
            {
                // The exception should always be CotcException
                CotcException error = (CotcException)ex;
                Debug.LogError("Failed to login: "******" (" + error.HttpStatusCode + ")");
            });
        });
    }
 // Start is called before the first frame update
 void Start()
 {
     cb = CotcSdk.GetComponent <CotcGameObject>();
     cb.GetCloud().Done(cloud => { Cloud = cloud; });
 }