void OnGUI()
    {
        float x      = 50.0f;
        float y      = 50.0f;
        float width  = Screen.width / 2 - x - 25.0f;
        float height = 100.0f;
        float margin = 25.0f;

        if (GUI.Button(new Rect(x, y, width, height), "Register"))
        {
            GCM.Register(SENDER_IDS);
        }

        x += width + margin * 2;

        if (GUI.Button(new Rect(x, y, width, height), "Unregister"))
        {
            GCM.Unregister();
        }

        x -= width + margin * 2;
        y += height + margin;

        if (GUI.Button(new Rect(x, y, width, height), "IsRegistered"))
        {
            _text = "IsRegistered = " + GCM.IsRegistered();
        }

        x += width + margin * 2;

        if (GUI.Button(new Rect(x, y, width, height), "GetRegisterationId"))
        {
            _text = "GetRegistrationId = " + GCM.GetRegistrationId();
        }

        x -= width + margin * 2;
        y += height + margin;

        if (GUI.Button(new Rect(x, y, width, height), "IsRegisteredOnServer"))
        {
            _text = "IsRegisteredOnServer = " + GCM.IsRegisteredOnServer();
        }

        x += width + margin * 2;

        if (GUI.Button(new Rect(x, y, width, height), "SetRegisteredOnServer"))
        {
            GCM.SetRegisteredOnServer(true);
            _text = "SetRegisteredOnServer";
        }

        x -= width + margin * 2;
        y += height + margin;

        if (GUI.Button(new Rect(x, y, width, height), "GetRegisterOnServerLifespan"))
        {
            _text = "GetRegisterOnServerLifespan = " + GCM.GetRegisterOnServerLifespan();
        }

        x += width + margin * 2;

        if (GUI.Button(new Rect(x, y, width, height), "SetRegisterOnServerLifespan"))
        {
            GCM.SetRegisterOnServerLifespan(30 * 1000);                 // 30 sec
            _text = "SetRegisterOnServerLifespan";
        }

        x -= width + margin * 2;
        y += height + margin;

        GUI.TextArea(new Rect(x, y, width * 2 + margin * 2, height), _text);

        y += height + margin;

        if (GUI.Button(new Rect(x, y, width, height), "Next"))
        {
            Application.LoadLevel("SubScene");
        }
    }
Exemple #2
0
    void SetCallbacks()
    {
        Application.RegisterLogCallbackThreaded(HandleLog);

        /*GSApi.GSMessageReceived += (GS, args)=>
         * {
         *      if(args.Message["@class"] as string == ".ChallengeAcceptedMessage"){
         #if UNITY_ANDROID && !UNITY_EDITOR
         *              GCM.ShowToast("Challenge Accepted");
         #else
         *              if (Debug.isDebugBuild) Debug.Log("Challenge Accepted");
         #endif
         *      }
         *      else if(args.Message["@class"] as string == ".ChallengeDeclinedMessage"){
         #if UNITY_ANDROID && !UNITY_EDITOR
         *              GCM.ShowToast("Challenge Declined");
         #else
         *              if (Debug.isDebugBuild) Debug.Log("Challenge Accepted");
         #endif
         *      }
         *      else if(args.Message["@class"] as string == ".ChallengeChatMessage"){
         #if UNITY_ANDROID && !UNITY_EDITOR
         *              GCM.ShowToast("Challenge Chat Recieved");
         #else
         *              if (Debug.isDebugBuild) Debug.Log("Challenge Chat Recieved");
         *              GameGlobals.messageCount++;
         #endif
         *      }
         *
         * };*/
#if UNITY_ANDROID && !UNITY_EDITOR
        FacebookManager.sessionOpenedEvent += delegate()
        {
            if (Debug.isDebugBuild)
            {
                Debug.Log("facebook callback worked");
            }



            //we assume that this can will only be called if session is invalid or we are on a new device.

            Hashtable response = GSApi.facebookConnect(FacebookAccess.getAccessToken());

            if ((string)response["@class"] == ".AuthenticationResponse" && (string)response["authToken"] != null)
            {
                GameGlobals.online = true;
                Hashtable details = GSApi.accountDetails();


                if (details["userId"] != null)
                {
                    GameGlobals.userID = (string)details["userId"];
                }
                if (!GCM.IsRegistered())
                {
                    GCM.Register();
                }
                GSApi.registerForPush(GCM.GetRegistrationId());
            }
            else
            {
                GameGlobals.online = false;
            }
        };
#endif



#if UNITY_ANDROID && !UNITY_EDITOR
        GCM.SetErrorCallback((string errorId) => {
            if (Debug.isDebugBuild)
            {
                Debug.Log("Error!!! " + errorId);
            }
            GCM.ShowToast("Error!!!");
            _text = "Error: " + errorId;
        });

        GCM.SetMessageCallback((Dictionary <string, object> table) => {
            if (Debug.isDebugBuild)
            {
                Debug.Log("Message!!!");
            }
            GCM.ShowToast("Message!!!");
            _text = "Message: " + System.Environment.NewLine;
            foreach (var key in  table.Keys)
            {
                _text += key + "=" + table[key] + System.Environment.NewLine;
            }
        });



        GCM.SetRegisteredCallback((string registrationId) => {
            //if(FacebookAccess.isSessionValid() &&
        });
#endif
    }