Пример #1
0
    void OnGUI()
    {
        gui.Label(10, 10, 500, 50, (current == APP_US ? "US:" : "JP:") + current.AppID);
        if (gui.Button(10, 55, 245, 100, "Switch APP to US"))
        {
            this.current = APP_US;
            KiiInitializeBehaviour.Instance.SwitchApp(this.current.AppID, this.current.AppKey, this.current.Site);
            this.message = string.Format("Switch APP to {0} : {1}\n", this.current.Site, this.current.AppID);
        }
        if (gui.Button(265, 55, 245, 100, "Switch APP to JP"))
        {
            this.current = APP_JP;
            KiiInitializeBehaviour.Instance.SwitchApp(this.current.AppID, this.current.AppKey, this.current.Site);
            this.message = string.Format("Switch APP to {0} : {1}\n", this.current.Site, this.current.AppID);
        }
        if (gui.Button(10, 160, 160, 100, "Create Random User"))
        {
            this.message = "";
            string  username = "******" + DateTime.Now.Ticks.ToString();
            KiiUser user     = KiiUser.BuilderWithName(username).Build();
            user.Register("pa$$sword", (KiiUser u, Exception e1) => {
                if (e1 == null)
                {
                    this.message = "SUCCESS:\nuser="******"Failed to register user", e1);
                }
            });
        }
        if (gui.Button(180, 160, 160, 100, "Facebook Login"))
        {
            this.message = "";
            var connector = this.gameObject.AddComponent <KiiSocialNetworkConnector> ();
            connector.LogIn(Provider.FACEBOOK,
                            (KiiUser user, Provider provider, Exception exception) => {
                if (exception == null)
                {
                    this.message = "SUCCESS:\nuser="******"Failed to login with social connector", exception);
                }
                // Destroy connector if required.
                Destroy(connector);
            });
        }
        if (gui.Button(350, 160, 160, 100, "Show user info"))
        {
            this.message = "";
            KiiUser u = KiiUser.CurrentUser;
            if (u == null)
            {
                this.message = "User is not logged in :P";
                return;
            }
            this.message  = "*** User tokens ***\n";
            this.message += GetDictionaryContents(u.GetAccessTokenDictionary());
            this.message += "\n*** Social tokens ***\n";
            this.message += GetDictionaryContents(u.GetSocialAccessTokenDictionary());
        }
        if (gui.Button(10, 265, 160, 100, "Create 5-Object\n(1 Object/sec)"))
        {
            this.message = "";
            KiiUser u = KiiUser.CurrentUser;
            if (u == null)
            {
                this.message = "User is not logged in :P";
                return;
            }
            StartCoroutine(CreateNewObjects(5));
        }
        if (gui.Button(10, 370, 160, 100, string.Format("Create topic\n({0})", topicname)))
        {
            this.message = "";
            KiiUser u = KiiUser.CurrentUser;
            if (u == null)
            {
                this.message = "User is not logged in :P";
                return;
            }
            KiiTopic topic = u.Topic(topicname);
            topic.Save((KiiTopic retTopic, Exception retException) => {
                if (retException == null)
                {
                    this.message = "SUCCESS:\ntopic=" + retTopic.Uri.ToString();
                }
                else
                {
                    this.ShowException("Failed to create topic", retException);
                }
            });
        }
        if (gui.Button(180, 370, 160, 100, "Subscribe topic"))
        {
            this.message = "";
            KiiUser u = KiiUser.CurrentUser;
            if (u == null)
            {
                this.message = "User is not logged in :P";
                return;
            }
            KiiTopic topic = u.Topic(topicname);
            u.PushSubscription.Subscribe(topic, (KiiSubscribable retSub, Exception retException) => {
                if (retException == null)
                {
                    this.message = "SUCCESS:\nsubscribed topic=" + ((KiiTopic)retSub).Uri.ToString();
                }
                else
                {
                    this.ShowException("Failed to subscribe topic", retException);
                }
            });
        }
        if (gui.Button(350, 370, 160, 100, "Check topic existence"))
        {
            this.message = "";
            KiiUser u = KiiUser.CurrentUser;
            if (u == null)
            {
                this.message = "User is not logged in :P";
                return;
            }
            KiiTopic topic = u.Topic(topicname);
            try
            {
                bool retExists = topic.Exists();
                this.message = "SUCCESS:\ntopic existence=" + retExists;
            }
            catch (Exception e)
            {
                this.ShowException("Failed to check topic existence", e);
            }
        }
        if (gui.Button(10, 480, 160, 100, "Install Push"))
        {
            this.message = "";
            KiiUser u = KiiUser.CurrentUser;
            if (u == null)
            {
                this.message = "User is not logged in :P";
                return;
            }
                        #if UNITY_IPHONE
            bool development = true;
            KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS;
                        #elif UNITY_ANDROID
            bool development = true;
            KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID;
                        #else
            this.message = "Push feature does not support on this platform :P";
            return;
                        #endif

            this.kiiPushPlugin.RegisterPush((string pushToken, Exception e0) => {
                if (e0 != null)
                {
                    this.ShowException("Failed to register push : " + this.kiiPushPlugin.SenderID, e0);
                    return;
                }
                this.message = "Push token : " + pushToken;
                KiiUser.PushInstallation(development).Install(pushToken, deviceType, (Exception e1) => {
                    if (e1 != null)
                    {
                        this.ShowException("Failed to install push", e1);
                    }
                    else
                    {
                        this.message += "SUCCESS:\ninstall push=" + pushToken;
                        SavePushInformation(deviceType, pushToken);
                    }
                });
            });
        }
        if (gui.Button(180, 480, 160, 100, "Uninstall Push"))
        {
            this.message = "";
            KiiUser u = KiiUser.CurrentUser;
            if (u == null)
            {
                this.message = "User is not logged in :P";
                return;
            }
                        #if UNITY_IPHONE
            bool development = true;
            KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS;
                        #elif UNITY_ANDROID
            bool development = true;
            KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID;
                        #else
            this.message = "Push feature does not support on this platform :P";
            return;
                        #endif

            string pushToken = LoadPushInformation(deviceType);
            KiiUser.PushInstallation(development).Uninstall(pushToken, deviceType, (Exception e0) => {
                if (e0 != null)
                {
                    this.ShowException("Failed to uninstall push", e0);
                    return;
                }
                this.kiiPushPlugin.UnregisterPush((Exception e1) => {
                    if (e1 != null)
                    {
                        this.ShowException("Failed to unregister push", e1);
                    }
                    else
                    {
                        this.message = "SUCCESS:\nuninstall push=" + pushToken;
                        ClearPushInformation(deviceType);
                    }
                });
            });
        }
        if (gui.Button(350, 480, 160, 100, "Send Push"))
        {
            this.message = "";
            KiiUser u = KiiUser.CurrentUser;
            if (u == null)
            {
                this.message = "User is not logged in :P";
                return;
            }

            KiiTopic topic = u.Topic(topicname);

            // Build a push message.
            KiiPushMessageData data = new KiiPushMessageData()
                                      .Put("message", "Hi, switch app :)");
            KiiPushMessage message = KiiPushMessage.BuildWith(data).SendAppID(true).Build();

            // Send the push message.
            topic.SendMessage(message, (KiiPushMessage retMessage, Exception retException) => {
                if (retException == null)
                {
                    this.message = "SUCCESS:\nsend message=" + retMessage.ToString();
                }
                else
                {
                    this.ShowException("Failed to send message", retException);
                }
            });
        }
        int messageHeight = 590;
        gui.Label(10, messageHeight, 500, screenHeight - messageHeight, this.message);
    }
Пример #2
0
    void OnGUI()
    {
        ScalableGUI gui = new ScalableGUI();

        if (pushScreen == true && apnsScreen == false && gcmScreen == false)
        {
            if (gui.Button(0, 10, 160, 50, "<< Back to main"))
            {
                pushScreen = false;
            }
            gui.Label(5, 70, 310, 30, "Push settings screen", 18);
            if (gui.Toggle(0, 100, 160, 50, pushSetting.SendAppID, "SendAppID"))
            {
                pushSetting.SendAppID = !pushSetting.SendAppID;
            }
            if (gui.Toggle(160, 100, 160, 50, pushSetting.SendObjectScope, "SendObjectScope"))
            {
                pushSetting.SendObjectScope = !pushSetting.SendObjectScope;
            }
            if (gui.Toggle(0, 150, 160, 50, pushSetting.SendOrigin, "SendOrigin"))
            {
                pushSetting.SendOrigin = !pushSetting.SendOrigin;
            }
            if (gui.Toggle(160, 150, 160, 50, pushSetting.SendSender, "SendSender"))
            {
                pushSetting.SendSender = !pushSetting.SendSender;
            }
            if (gui.Toggle(0, 200, 160, 50, pushSetting.SendTopicId, "SendTopicId"))
            {
                pushSetting.SendTopicId = !pushSetting.SendTopicId;
            }
            if (gui.Toggle(160, 200, 160, 50, pushSetting.SendWhen, "SendWhen"))
            {
                pushSetting.SendWhen = !pushSetting.SendWhen;
            }
            if (gui.Toggle(0, 250, 160, 50, pushSetting.SendToProduction, "SendToProduction"))
            {
                pushSetting.SendToProduction = !pushSetting.SendToProduction;
            }
            if (gui.Toggle(160, 250, 160, 50, pushSetting.SendToDevelopment, "SendToDevelopment"))
            {
                pushSetting.SendToDevelopment = !pushSetting.SendToDevelopment;
            }
        }
        else if (pushScreen == false && apnsScreen == true && gcmScreen == false)
        {
            if (gui.Button(0, 10, 160, 50, "<< Back to main"))
            {
                apnsScreen = false;
            }
            gui.Label(5, 70, 310, 30, "APNs settings screen", 18);
            if (gui.Toggle(0, 100, 160, 50, (apnsSetting.ContentAvailable == 1) ? true : false, "content-available"))
            {
                if (apnsSetting.ContentAvailable == 0)
                {
                    apnsSetting.ContentAvailable = 1;
                }
                else
                {
                    apnsSetting.ContentAvailable = 0;
                }
            }
            gui.Label(5, 160, 310, 20, "APNs alert body", 10);
            apnsSetting.AlertBody = gui.TextField(0, 190, 320, 50, apnsSetting.AlertBody);
        }
        else if (pushScreen == false && apnsScreen == false && gcmScreen == true)
        {
            if (gui.Button(0, 10, 160, 50, "<< Back to main"))
            {
                gcmScreen = false;
            }
            gui.Label(5, 70, 310, 30, "GCM settings screen", 18);
        }
        else
        {
            gui.Label(5, 5, 310, 20, "Push2User scene");
            if (gui.Button(200, 5, 120, 35, "-> Push2App"))
            {
                this.kiiPushPlugin.OnPushMessageReceived -= this.receivedCallback;
                Application.LoadLevel("push2app");
            }

            this.payload = gui.TextField(0, 45, 320, 50, this.payload);

            if (gui.Button(0, 100, 160, 40, "Send Message"))
            {
                sendMessage();
            }
            if (gui.Button(160, 100, 160, 40, "Clear Log"))
            {
                this.message = "--- Logs will show here ---";
            }
            if (gui.Button(0, 140, 160, 40, "Register Push"))
            {
                Invoke("registerPush", 0);
            }
            if (gui.Button(160, 140, 160, 40, "Unregister Push"))
            {
                this.kiiPushPlugin.UnregisterPush((Exception e) => {
                    if (e != null)
                    {
                        Debug.Log("#####" + e.Message);
                        Debug.Log("#####" + e.StackTrace);
                        this.ShowException("#####Unregister push is failed!!", e);
                        return;
                    }
                    this.message = "#####Unregister push is successful!!";
                });
            }
            if (gui.Button(0, 180, 160, 40, "Subscribe topic"))
            {
                KiiUser             user         = KiiUser.CurrentUser;
                KiiTopic            topic        = user.Topic(TOPIC_NAME);
                KiiPushSubscription subscription = user.PushSubscription;
                subscription.Subscribe(topic, (KiiSubscribable target, Exception e) => {
                    if (e != null)
                    {
                        Debug.Log("#####" + e.Message);
                        Debug.Log("#####" + e.StackTrace);
                        this.ShowException("#####Subscribe is failed!!", e);
                        return;
                    }
                    this.message = "#####Subscribe is successful!!";
                });
            }
            if (gui.Button(160, 180, 160, 40, "Unsubscribe topic"))
            {
                KiiUser             user         = KiiUser.CurrentUser;
                KiiTopic            topic        = user.Topic(TOPIC_NAME);
                KiiPushSubscription subscription = user.PushSubscription;
                subscription.Unsubscribe(topic, (KiiSubscribable target, Exception e) => {
                    if (e != null)
                    {
                        Debug.Log("#####" + e.Message);
                        Debug.Log("#####" + e.StackTrace);
                        this.ShowException("#####Unsubscribe is failed!!", e);
                        return;
                    }
                    this.message = "#####Unsubscribe is successful!!";
                });
            }
            if (gui.Button(0, 220, 160, 40, "Check subscription"))
            {
                KiiUser             user         = KiiUser.CurrentUser;
                KiiTopic            topic        = user.Topic(TOPIC_NAME);
                KiiPushSubscription subscription = user.PushSubscription;
                subscription.IsSubscribed(topic, (KiiSubscribable target, bool isSubscribed, Exception e) => {
                    if (e != null)
                    {
                        Debug.Log("#####" + e.Message);
                        Debug.Log("#####" + e.StackTrace);
                        this.ShowException("#####Check subscription is failed!!", e);
                        return;
                    }
                    this.message = "#####Subscription status : " + isSubscribed;
                });
            }


            if (gui.Button(160, 220, 160, 40, "Push settings >>"))
            {
                pushScreen = true;
            }
            if (gui.Toggle(0, 260, 160, 40, apnsSetting.Enable, "Enable APNs"))
            {
                apnsSetting.Enable = !apnsSetting.Enable;
            }
            GUI.enabled = apnsSetting.Enable;
            if (gui.Button(160, 260, 160, 40, "APNs settings >>"))
            {
                apnsScreen = true;
            }
            GUI.enabled = true;
            if (gui.Toggle(0, 300, 160, 40, gcmSetting.Enable, "Enable GCM"))
            {
                gcmSetting.Enable = !gcmSetting.Enable;
            }
            GUI.enabled = gcmSetting.Enable;
            if (gui.Button(160, 300, 160, 40, "GCM settings >>"))
            {
                gcmScreen = true;
            }
            GUI.enabled = true;
            gui.TextArea(5, 350, 310, 130, this.message, 10);
        }
    }