Exemplo n.º 1
0
    void Awake()
    {
        if (mInstance == null)
        {
            mInstance = this;
            DontDestroyOnLoad(gameObject);

            GJAPI.Init(gameID, privateKey);

            GJAPI.Users.VerifyCallback     += OnVerifyUser;
            GJAPI.Trophies.GetAllCallback  += OnTrophiesGrab;
            GJAPI.Trophies.AddCallback     += OnTrophyAdd;
            GJAPI.Scores.GetTablesCallback += OnScoresGrab;
            GJAPI.Scores.AddCallback       += OnScoreAdd;

            if (Achievement.instance)
            {
                Achievement.instance.RegisterService(this);
            }

            if (Leaderboard.instance)
            {
                Leaderboard.instance.RegisterService(this);
            }

            if (userGrabFromWeb)
            {
                mState = State.GrabUser;
                GJAPIHelper.Users.GetFromWeb(OnGrabUser);
            }
            else
            {
                //TODO: login window
                if (!string.IsNullOrEmpty(userName))
                {
                    if (string.IsNullOrEmpty(userToken))
                    {
                        mState   = State.None;
                        mIsGuest = true;
                    }
                    else
                    {
                        mState   = State.VerifyUser;
                        mIsGuest = false;
                        GJAPI.Users.Verify(userName, userToken);
                    }
                }
                else
                {
                    mState = State.RequireLogin;
                }
            }
        }
        else
        {
            DestroyImmediate(gameObject);
        }
    }
Exemplo n.º 2
0
    void OnDestroy()
    {
        if (mInstance == this)
        {
            GJAPI.Users.VerifyCallback     -= OnVerifyUser;
            GJAPI.Trophies.GetAllCallback  -= OnTrophiesGrab;
            GJAPI.Trophies.AddCallback     -= OnTrophyAdd;
            GJAPI.Scores.GetTablesCallback -= OnScoresGrab;
            GJAPI.Scores.AddCallback       -= OnScoreAdd;

            if (Achievement.instance)
            {
                Achievement.instance.UnregisterService(this);
            }

            if (Leaderboard.instance)
            {
                Leaderboard.instance.UnregisterService(this);
            }

            mInstance = null;
        }
    }