Example #1
0
    //void OnDestroy()
    //{
    //    cloudHandler.Disconnect();
    //}

    public void Login(StardomAPICallback callback = null)
    {
        if (!IsInitialized)
        {
            Debug.LogError("Trying to call StardomAPI functions before it's fully initialized");
            return;
        }

        socialHandler.FacebookLogin(delegate(StardomAPIReply reply)
        {
            if (!reply.Success)
            {
                //if authentication fails return the same object with the same message
                if (callback != null)
                {
                    callback(reply);
                }
            }
            else
            {
                // if facebook login succeeds, continue with cloud authentication
                cloudHandler.AuthenticateFacebookUser(socialHandler.Token, (AuthReply rep) =>
                {
                    //try to update user info from fb if needed from server
                    if (rep.Success && rep.updateFromFb || true)
                    {
                        UpdateFacebookInfo((StardomAPIReply updateReply) =>
                        {
                            if (callback != null)
                            {
                                callback(updateReply);
                            }
                        });
                    }
                    else if (callback != null)
                    {
                        callback(rep);
                    }
                });
            }
        });
    }