示例#1
0
        public void SetUp()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            client = (MockHttpClient)factory.Client;
        }
 /// <summary>
 /// Switchs the app.
 /// </summary>
 /// <param name="appId">AppID.</param>
 /// <param name="appKey">AppID.</param>
 /// <param name="serverUrl">Server URL.</param>
 /// <remarks>
 /// This method is for internal use only. Do not use it from your application.
 /// </remarks>
 public void SwitchApp(string appId, string appKey, string serverUrl)
 {
     Kii.Initialize(appId, appKey, serverUrl,
                    new KiiUnityClientFactoryImpl(), new KiiAsyncUnityClientFactoryImpl());
     KiiAnalytics.Initialize(appId, appKey, serverUrl, this.GetDeviceID(),
                             new KiiUnityClientFactoryImpl(), new KiiAsyncUnityClientFactoryImpl());
     this.AppID     = appId;
     this.AppKey    = appKey;
     this.ServerUrl = serverUrl;
 }
 /// <summary>
 /// Switchs the app.
 /// </summary>
 /// <param name="appId">AppID.</param>
 /// <param name="appKey">AppKey.</param>
 /// <param name="site">Site.</param>
 /// <remarks>
 /// This method is for internal use only. Do not use it from your application.
 /// </remarks>
 public void SwitchApp(string appId, string appKey, Kii.Site site)
 {
     Kii.Initialize(appId, appKey, site,
                    new KiiUnityClientFactoryImpl(), new KiiAsyncUnityClientFactoryImpl());
     KiiAnalytics.Initialize(appId, appKey, ToAnalyticsSite(site), this.GetDeviceID(),
                             new KiiUnityClientFactoryImpl(), new KiiAsyncUnityClientFactoryImpl());
     this.AppID     = appId;
     this.AppKey    = appKey;
     this.Site      = site;
     this.ServerUrl = null;
 }
示例#4
0
    // Get KiiCloud Bucket's score data.
    // Need already KiiCloud logined.
    public static int getHighScore()
    {
        if (KiiUser.CurrentUser == null)
        {
            return(0);
        }
        if (cachedHighScore > 0)
        {
            return(cachedHighScore);
        }
        KiiBucket bucket = Kii.Bucket(BUCKET_NAME);
        KiiQuery  query  = new KiiQuery(KiiClause.Equals(USER_KEY, KiiUser.CurrentUser.ID));

        query.SortByDesc(SCORE_KEY);
        query.Limit = 1;

        try {
            KiiQueryResult <KiiObject> result = bucket.Query(query);
            foreach (KiiObject obj in result)
            {
                int score = obj.GetInt(SCORE_KEY, 0);
                cachedHighScore = score;
                return(score);
            }
            Debug.Log("High score fetched");
            return(0);
        } catch (CloudException e) {
            Debug.Log("Failed to fetch high score: " + e.ToString());
            return(0);
        }

        /* Async version
         * bucket.Query(query, (KiiQueryResult<KiiObject> list, Exception e) =>{
         *      if (e != null)
         *      {
         *              Debug.Log ("Failed to fetch high score: " + e.ToString());
         *      } else {
         *              Debug.Log ("High score fetched");
         *              foreach (KiiObject obj in list) {
         *                      int score = obj.GetInt (SCORE_KEY, 0);
         *                      cachedHighScore = score;
         *                      getHighScore = score;
         *                      return;
         *              }
         *      }
         * });
         */
    }
示例#5
0
 void Awake()
 {
     if (!createNotification)
     {
         // this is the first instance -make it persist
         DontDestroyOnLoad(GameObject.Find("notification"));
         createNotification = true;
     }
     else
     {
         // this must be aduplicate from a scene reload  - DESTROY!
         Destroy(GameObject.Find("notification"));
         Destroy(GameObject.Find("KiiPush"));
     }                       // Kii Cloud SDK Initialize.
     Kii.Initialize(_AppID, _AppKey, Kii.Site.JP);
 }
示例#6
0
    public void Cancel()
    {
        Debug.Log("Cancel");
        bool      validate  = true;
        KiiObject obj       = KiiObject.CreateByUri(objUri);
        KiiBucket appBucket = Kii.Bucket("Games");
        String    id        = "";

        try {
            obj.Refresh();
            id = obj.GetString("_id");
        } catch (Exception e) {
            Debug.Log("Fallo refresh id game: " + e);
        }
        KiiQuery query = new KiiQuery(
            KiiClause.And(
                KiiClause.Equals("gameName", gameName.GetComponent <InputField>().text)
                , KiiClause.NotEquals("_id", id)
                )
            );

        appBucket.Count(query, (KiiBucket b, KiiQuery q, int count, Exception e) => {
            if (e != null)
            {
                validate = false;
                applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Unexpected exception occurred");
                navigationController.GoTo("ALERT_VIEW");
                return;
            }
            if (count > 0)
            {
                validate = false;
                applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Game name already exist");
                navigationController.GoTo("ALERT_VIEW");
                return;
            }
            if (ValidatedFields() && validate)
            {
                navigationController.Back();
            }
            else
            {
                applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Invalid inputs.");
                navigationController.GoTo("ALERT_VIEW");
            }
        });
    }
示例#7
0
 private void _myPing_PingCompleted(object sender, PingCompletedEventArgs e)
 {
     if (e.Reply.Status == IPStatus.Success)
     {
         string reply = e.Reply.Address.ToString();
         if (computerInfo.Keys.Contains(reply))
         {
             try
             {
                 computerInfo[reply].machinename = Dns.GetHostEntry(IPAddress.Parse(reply)).HostName;
                 computerInfo[reply].status      = ComputerStatus.ON_LINE;
                 Kii.Invoke(computerInfo[reply]);
             }
             catch (Exception err)
             {
             }
         }
     }
 }
示例#8
0
 public void SaveImages(string idGame, int i)
 {
     if (imagePaths[i] != null)
     {
         KiiObject obj = Kii.Bucket(idGame).NewKiiObject();
         // Set key-value pairs
         obj ["screenshotName"] = "screenshot-0" + i;
         obj ["idGame"]         = idGame;
         obj.SaveAllFields(true, (KiiObject savedObj, Exception exc) => {
             if (exc != null)
             {
                 Debug.Log(exc);
                 return;
             }
             // Prepare file to upload
             SaveImage(i, savedObj);
         });
     }
 }
示例#9
0
    private IEnumerator CreateNewObjects(int count)
    {
        for (int index = 0; index < count; index++)
        {
            yield return(new WaitForSeconds(1f));

            KiiObject obj = Kii.Bucket("user_bucket").NewKiiObject();
            obj["time"] = DateTime.Now.Ticks;
            obj.Save((KiiObject o, Exception e) => {
                if (e == null)
                {
                    this.message += "SUCCESS:\nobject=" + o.Uri.ToString() + "\n";
                }
                else
                {
                    this.ShowException("Failed to save object", e);
                }
            });
        }
    }
示例#10
0
    void ScoreLoop()
    {
        if (count < 27)
        {
            gameTime = Time.timeSinceLevelLoad;
        }
        else
        {
            winText.text = "YOU WIN!!";
            if (user != null && !scoreSent)
            {
                scoreSent = true;
                KiiBucket bucket = Kii.Bucket(appScopeScoreBucket);
                KiiObject score  = bucket.NewKiiObject();
                score["time"]     = gameTime;
                score["username"] = user.Username;
                // score is game completion time, the lower the better
                Debug.Log("Saving score...");
                score.Save((KiiObject obj, Exception e) => {
                    if (e != null)
                    {
                        Debug.LogError(e.ToString());
                    }
                    else
                    {
                        Debug.Log("Score sent: " + gameTime.ToString("n2"));
                    }
                });
            }
        }
        string username = "";

        if (user != null)
        {
            username = user.Username + " ";
        }
        countText.text = username + count.ToString() + "/27 " + gameTime.ToString("n2");
    }
示例#11
0
        public Dictionary <string, ComputerIpInfo> EnumComputers()
        {
            try
            {
                string bIp = GetLocalMachineIp();
                if (null == bIp || 0 == bIp.Length)
                {
                    return(computerInfo);
                }
                for (int i = 0; i <= 10; i++)
                {
                    Ping myPing;
                    myPing = new Ping();
                    myPing.PingCompleted += new PingCompletedEventHandler(_myPing_PingCompleted);
                    string pingIP = bIp + i.ToString();
                    byte[] buffer = Encoding.ASCII.GetBytes("");
                    if (!computerInfo.Keys.Contains(pingIP))
                    {
                        ComputerIpInfo cip = new ComputerIpInfo();
                        string         mac = GetRemoteMac(localMachine.ip, pingIP);
                        cip.ip     = pingIP;
                        cip.status = ComputerStatus.BREAK_LIEN;
                        if (mac != "0")
                        {
                            cip.mac = mac;
                        }
                        computerInfo.Add(pingIP, cip);
                        Kii.Invoke(cip);
                    }
                    myPing.SendAsync(pingIP, 1000, buffer);
                }
            }
            catch (Exception err)
            {
            }

            return(computerInfo);
        }
示例#12
0
    void OnEnable()
    {
        if (applicationController.sessionStarted)
        {
            KiiBucket appBucket = Kii.Bucket("Games");
            KiiQuery  query     = new KiiQuery(KiiClause.Equals("_owner", KiiUser.CurrentUser.ID));

            appBucket.Query(query, (KiiQueryResult <KiiObject> result, Exception e) => {
                if (e != null)
                {
                    Debug.Log(e);
                    applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Unexpected exception occurred");
                    navigationController.GoTo("ALERT_VIEW");
                    return;
                }
                foreach (KiiObject obj in result)
                {
                    GameObject gameBoxI;
                    gameBoxI = Instantiate(gameBox);
                    gameBoxI.SetActive(true);
                    gameBoxI.transform.SetParent(container.transform);
                    gameBoxI.transform.localScale = new Vector3(1, 1, 1);
                    gameBoxI.GetComponentsInChildren <Text> () [0].text = obj.GetString("gameName");
                    gameBoxI.GetComponentInChildren <Button>().onClick.AddListener(() => editViewController.GetComponent <EditViewController>().SetUri(obj.Uri));
                    gameBoxI.GetComponentInChildren <Button>().onClick.AddListener(() => navigationController.GoTo("EDIT_VIEW"));
                    //gameBox.GetComponentInChildren<RawImage>().texture = obj["icon"];
                }
                GameObject addGameBut;
                addGameBut = Instantiate(addGameButton);
                addGameBut.SetActive(true);
                addGameBut.transform.SetParent(container.transform);
                addGameBut.transform.localScale = new Vector3(1, 1, 1);
                addGameBut.GetComponentInChildren <Button>().onClick.AddListener(() => NewGame());
            });
        }
    }
示例#13
0
    void PerformCreateGroup(string name)
    {
        message       = "Creating group...";
        ButtonEnabled = false;

        if (name == null || name.Length == 0)
        {
            message       = "Group name is null";
            ButtonEnabled = true;
            return;
        }
        KiiGroup group = Kii.Group(name);

        group.Save((KiiGroup newGroup, Exception e) =>
        {
            ButtonEnabled = true;
            if (e != null)
            {
                message = "Failed to create group " + e.ToString();
                return;
            }
            message = "Create group succeeded";
        });
    }
示例#14
0
 //显示配置属性
 public void ShowForm(Soft st, int type)
 {
     Kii.Invoke(st, type);
 }
示例#15
0
    private void register()
    {
        user       = null;
        OnCallback = true;
        KiiUser built_user = KiiUser.BuilderWithName(username).Build();

        built_user.Register(password, (KiiUser user2, Exception e) => {
            if (e == null)
            {
                                #if UNITY_IPHONE
                bool development = true;                      // choose development/production for iOS
                string USER      = username;
                string PASS      = password;
                KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS;
                plugin = GameObject.Find("KiiPush").GetComponent <KiiPushPlugin>();
                plugin.RegisterPush((string pushToken, Exception e0) => {
                    Debug.Log("Token :" + pushToken);
                    if (e0 == null)
                    {
                        KiiUser.LogIn(USER, PASS, (KiiUser kiiuser, Exception e1) => {
                            if (e1 == null)
                            {
                                KiiUser.PushInstallation(development).Install(pushToken, deviceType, (Exception e2) => {
                                    Debug.Log("Push registration completed");
                                    KiiUser user3          = KiiUser.CurrentUser;
                                    KiiBucket bucket       = Kii.Bucket("FlappyDogHighScore");
                                    KiiPushSubscription ps = user3.PushSubscription;
                                    ps.Subscribe(bucket, (KiiSubscribable target, Exception e3) => {
                                        if (e3 != null)
                                        {
                                            // check fail cause
                                            Debug.Log("Subscription Failed");
                                            Debug.Log(e3.ToString());
                                        }
                                    });
                                });
                            }
                            else
                            {
                                Debug.Log("e1 error: " + e1.ToString());
                            };
                        });
                    }
                    else
                    {
                        Debug.Log("e0 error: " + e0.ToString());
                    };
                });
                                #endif

                user = user2;
                Debug.Log("Register completed");
            }
            else
            {
                user       = null;
                OnCallback = false;
                Debug.Log("Register failed : " + e.ToString());
            }
        });
    }
示例#16
0
 void OnGUI()
 {
     this.entryNameValue = gui.TextField(
         10,
         10,
         300,
         50,
         this.entryNameValue);
     this.versionValue = gui.TextField(
         10,
         70,
         300,
         50,
         this.versionValue);
     if (gui.Button(
             10,
             130,
             300,
             60,
             "ServerCodeEntry(entryName)"))
     {
         try {
             execEntry(Kii.ServerCodeEntry(this.entryNameValue));
         } catch (Exception e) {
             this.labelText = e.ToString();
         }
     }
     if (gui.Button(
             10,
             200,
             300,
             60,
             "ServerCodeEntry(entryName, version)"))
     {
         try {
             execEntry(Kii.ServerCodeEntry(this.entryNameValue,
                                           this.versionValue));
         } catch (Exception e) {
             this.labelText = e.ToString();
         }
     }
     if (gui.Button(
             10,
             270,
             145,
             60,
             "User login"))
     {
         this.labelText = "";
         string  username = "******" + DateTime.Now.Ticks.ToString();
         KiiUser user     = KiiUser.BuilderWithName(username).Build();
         user.Register("pa$$sword", (KiiUser u, Exception e1) => {
             if (e1 == null)
             {
                 this.labelText = "SUCCESS:\nuser="******"User logout"))
     {
         KiiUser.LogOut();
         this.labelText = "User logged out";
     }
     gui.TextField(
         10,
         350,
         300,
         120,
         this.labelText);
 }
 void OnGUI()
 {
     GUI.Label(new Rect(10, 10, 800, 50), GetType().ToString());
     if (GUI.Button(new Rect(10, 60, 250, 100), "Upload & Download"))
     {
         KiiUser.LogIn(this.username, this.password, (KiiUser user, Exception e1) => {
             if (e1 == null)
             {
                 KiiObject obj = Kii.Bucket("images").NewKiiObject();
                 obj["owner"]  = this.username;
                 obj.Save((KiiObject o1, Exception e2) => {
                     if (e2 == null)
                     {
                         Debug.Log("##### Object is saved");
                         byte[] image = ReadImage();
                         Stream body  = new MemoryStream(image);
                         o1.UploadBody("image/png", body, (KiiObject o2, Exception e3) => {
                             if (e3 == null)
                             {
                                 Debug.Log("##### Object body is uploaded");
                                 Stream outputStream = new MemoryStream();
                                 o2.DownloadBody(outputStream, (KiiObject o3, Stream s, Exception e4) => {
                                     if (e4 == null)
                                     {
                                         s.Seek(0, SeekOrigin.Begin);
                                         byte[] downloadedImage = this.ReadStream(s);
                                         if (image.Length != downloadedImage.Length)
                                         {
                                             this.message = "ERROR: expected=" + image.Length + "bytes  actual=" + downloadedImage.Length + "bytes";
                                         }
                                         else if (!this.Compare(image, downloadedImage))
                                         {
                                             this.message = "ERROR: unexpected bytes";
                                         }
                                         else
                                         {
                                             this.message = "SUCCESS!!!!!";
                                         }
                                     }
                                     else
                                     {
                                         this.ShowException("Failed to download object body", e4);
                                     }
                                 }
                                                 , (KiiObject o3, float progress) => {
                                     Debug.Log("##### Downloading...");
                                     this.message = "Downloading... " + (progress * 100) + "%";
                                 });
                             }
                             else
                             {
                                 this.ShowException("Failed to upload object body", e3);
                             }
                         }
                                       , (KiiObject o2, float progress) => {
                             this.message = "Uploading... " + (progress * 100) + "%";
                         });
                     }
                     else
                     {
                         this.ShowException("Failed to save object", e2);
                     }
                 });
             }
             else
             {
                 this.ShowException("Failed to login", e1);
             }
         });
     }
     GUI.Label(new Rect(10, 175, 500, 1000), this.message);
 }
示例#18
0
    void llenarPartidas()
    {
        string[] creatorstring = new string[20];
        string[] numberofplayersstring = new string[20];
        string[] puzzlesizestring = new string[20];
        string[] powerupsstring = new string[20];
        string[] goTopicURLstring = new string[20];
        int x = 0;
        //Genera las filas de la lista de partidas disponibles
        // Las columnas estan ya diseñadas.
        KiiQuery query = new KiiQuery(
                  KiiClause.And(
                        KiiClause.Equals(key4, "false"),
                        KiiClause.NotEquals(key9, mystats.idplayer)
                      )
                  );

        // Alternatively, you can also do:
        // Kii.Bucket("myBuckets").Query(null, (...));
        Kii.Bucket("Global").Query(query, (KiiQueryResult<KiiObject> result, Exception e) =>
        {
            float exis = -(200f * 0.0016f);
            float eye = -(200f * 0.0016f) + calculaHuecos;
            GameObject worldObject = Instantiate(WorldMatches, new Vector3(exis, eye, 0f), Quaternion.identity) as GameObject;
            world[0] = worldObject;
            worldObject.transform.parent = scroll.transform;
            worldObject.SetActive(true);
            if (e != null)
            {
                // handle error
                return;
            }
            foreach (KiiObject obj in result)
            {
                numberofplayersstring[x] = (string)obj[key8];
                creatorstring[x] = (string)obj[key9];
                puzzlesizestring[x] = (string)obj[key10];
                powerupsstring[x] = (string)obj[key11];
                goTopicURLstring[x] = (string)obj[key12];
                lista[x] = obj;
                int p = x + 1;
                Debug.Log("Este es el Uri de la partida "+ p +": " + obj.Uri.ToString());
                x++;
            }
            Debug.Log("Partidas disponibles encontradas: " + x);
            listaOld = new GameObject[x];
            for (int y = 0; y < x; y++)
            {

                eye = eye - (100f * 0.0016f);
                GameObject childObject = Instantiate(match, new Vector3(exis, eye, 0f), Quaternion.identity) as GameObject;
                childObject.transform.parent = scroll.transform;
                listaOld[y] = childObject;
                if (y == x - 1)
                {
                    calculaHuecos = eye;
                }

            }
            for (int i = 0; i < x; i++)
            {
                GameObject creator = listaOld[i].transform.FindChild("Creator").gameObject;
                GameObject numberofplayers = listaOld[i].transform.FindChild("NumberOfPlayers").gameObject;
                GameObject puzzlesize = listaOld[i].transform.FindChild("PuzzleSize").gameObject;
                GameObject powerups = listaOld[i].transform.FindChild("PowerUps").gameObject;
                GameObject unirse = listaOld[i].transform.FindChild("Check").gameObject;
                GameObject nocheck = listaOld[i].transform.FindChild("SafeCheck").gameObject;
                nocheck.SetActive(false);
                GameObject idJsonPArtidas = listaOld[i].transform.FindChild("jsonID").gameObject;
                GameObject goTopicURL = listaOld[i].transform.FindChild("topicURL").gameObject;
                UILabel creatorlabel = creator.GetComponent<UILabel>();
                UILabel numberofplayerslabel = numberofplayers.GetComponent<UILabel>();
                UILabel puzzlesizelabel = puzzlesize.GetComponent<UILabel>();
                UILabel powerupslabel = powerups.GetComponent<UILabel>();
                UILabel idjonLabel = idJsonPArtidas.GetComponent<UILabel>();
                UILabel topicURLlabel = goTopicURL.GetComponent<UILabel>();
                creatorlabel.text = "" + creatorstring[i] + "";
                numberofplayerslabel.text = "" + numberofplayersstring[i] + "";
                puzzlesizelabel.text = "" + puzzlesizestring[i] + "";
                powerupslabel.text = "" + powerupsstring[i] + "";
                idjonLabel.text = "" + lista[i].Uri.ToString() + "";
                topicURLlabel.text = "" + lista[i][key12] + "";
            }
        });
        /*if (callBack.take1.Count < 2)
        {
            notfound.SetActive(true);
        }
        else
        {
            float exis = -(200f * 0.0016f);
            float eye = -(200f * 0.0016f) + calculaHuecos;
            lista = new GameObject[callBack.take1.Count];
            for (int x = 0; x < callBack.take1.Count + 1; x++)
            {
                if (x == 0)
                {
                    GameObject worldObject = Instantiate(WorldMatches, new Vector3(exis, eye, 0f), Quaternion.identity) as GameObject;
                    world[0] = worldObject;
                    worldObject.transform.parent = scroll.transform;
                    worldObject.SetActive(true);
                }
                else
                {
                    eye = eye - (100f * 0.0016f);
                    GameObject childObject = Instantiate(match, new Vector3(exis, eye, 0f), Quaternion.identity) as GameObject;
                    childObject.transform.parent = scroll.transform;
                    lista[x - 1] = childObject;
                    if (x == callBack.take1.Count - 1)
                    {
                        calculaHuecos = eye;
                    }
                }
            }
            for (int i = 0; i < callBack.take1.Count; i++)
            {
                GameObject creator = lista[i].transform.FindChild("Creator").gameObject;
                GameObject numberofplayers = lista[i].transform.FindChild("NumberOfPlayers").gameObject;
                GameObject puzzlesize = lista[i].transform.FindChild("PuzzleSize").gameObject;
                GameObject powerups = lista[i].transform.FindChild("PowerUps").gameObject;
                GameObject unirse = lista[i].transform.FindChild("Check").gameObject;
                GameObject idJsonPArtidas = lista[i].transform.FindChild("jsonID").gameObject;
                UILabel creatorlabel = creator.GetComponent<UILabel>();
                UILabel numberofplayerslabel = numberofplayers.GetComponent<UILabel>();
                UILabel puzzlesizelabel = puzzlesize.GetComponent<UILabel>();
                UILabel powerupslabel = powerups.GetComponent<UILabel>();
                UILabel idjonLabel = idJsonPArtidas.GetComponent<UILabel>();
                jsonObj = callBack.take1[i].GetJsonDoc();
                string creatorstring = getinfo.sacarinfo(key9, jsonObj);
                string numberofplayersstring = getinfo.sacarinfo(key8, jsonObj);
                string puzzlesizestring = getinfo.sacarinfo(key10, jsonObj);
                string powerupsstring = getinfo.sacarinfo(key11, jsonObj);
                string jsonId = callBack.take1[i].GetDocId();
                creatorlabel.text = "" + creatorstring + "";
                Debug.Log(creatorstring);
                numberofplayerslabel.text = "" + numberofplayersstring + "";
                puzzlesizelabel.text = "" + puzzlesizestring + "";
                powerupslabel.text = "" + powerupsstring + "";
                idjonLabel.text = "" + jsonId + "";
            }
        }
        searching.text = "";
        }*/
        searching.text = "";
    }
示例#19
0
    public void newGame()
    {
        //Crea una partida nueva
        searching.text = "Creating match...";
        /*
        value1 = round.ToString();
        value2 = turn.ToString();
        value9 = mystats.idplayer;
        json.Add(key1, value1);
        json.Add(key2, value2);
        json.Add(key3, value3);
        json.Add(key4, value4);
        json.Add(key5, value5);
        json.Add(key6, value6);
        json.Add(key7, value7);
        json.Add(key8, value8);
        json.Add(key9, value9);
        json.Add(key10, value10);
        json.Add(key11, value11);
        storageService = sp.BuildStorageService();
        storageService.InsertJSONDocument(dbName, mystats.idplayer + "'s Games", json, myDataBase);
        storageService.InsertJSONDocument(dbName, collectionName, json, callBack);
        */
        // Create an object in an user-scope bucket.
        KiiObject obj5 = Kii.Bucket("MatchInfo").NewKiiObject();
        value1 = round.ToString();
        value2 = turn.ToString();
        value9 = mystats.idplayer;
        obj5[keypieces] = valuepieces;
        obj5[keyplayersturn] = valueplayersturn;

        obj5.Save((KiiObject savedObj, Exception e) =>
        {
            if (e != null)
            {
                // Handle error
            }
            else
            {
                value12 = obj5.Uri.ToString();
                mystats.groupURL = value12;
                KiiObject obj = KiiUser.CurrentUser.Bucket(mystats.idplayer + "sGames").NewKiiObject();
                obj[key1] = value1;
                obj[key2] = value2;
                obj[key3] = value3;
                obj[key4] = value4;
                obj[key5] = value5;
                obj[key6] = value6;
                obj[key7] = value7;
                obj[key8] = value8;
                obj[key9] = value9;
                obj[key10] = value10;
                obj[key11] = value11;
                obj[key12] = value12;
                // Save the object
                obj.Save((KiiObject savedObj2, Exception e2) =>
                {
                    if (e2 != null)
                    {
                        // Handle error
                    }
                    else
                    {
                        mystats.yourIdJson = obj.Uri.ToString();
                    }
                });
                KiiObject obj2 = Kii.Bucket(collectionName).NewKiiObject();
                // Set key-value pairs
                obj2[key1] = value1;
                obj2[key2] = value2;
                obj2[key3] = value3;
                obj2[key4] = value4;
                obj2[key5] = value5;
                obj2[key6] = value6;
                obj2[key7] = value7;
                obj2[key8] = value8;
                obj2[key9] = value9;
                obj2[key10] = value10;
                obj2[key11] = value11;
                obj2[key12] = value12;
                obj2.Save((KiiObject savedObjj, Exception e3) =>
                {
                    if (e3 != null)
                    {
                        // Handle error
                    }
                    else
                    {
                        mystats.idjson = obj2.Uri.ToString();
                        upLoadScene = true;
                        contador5 = 0.0f;
                        jugador = "1";
                        oponente = "2";
                        mystats.jugador = jugador;
                        mystats.oponente = oponente;
                        Debug.Log("Creando nueva partida...");
                    }
                });
            }
        });
    }
示例#20
0
    public void buscar()
    {
        //Busca una partida vacia
        // Prepare the target bucket to be queried
        KiiBucket bucket = Kii.Bucket("Global");

        // Define query conditions
        KiiQuery query = new KiiQuery(
            KiiClause.Equals("Full","True")
        );

        // Fine-tune your query results
        query.Limit = 1;

        // Query the bucket
        bucket.Query(query, (KiiQueryResult<KiiObject> result, Exception e) =>
        {
            if (e != null)
            {
                Debug.LogError("Query Object failed: " + e.ToString());
                // handle error
                return;
            }
            foreach (KiiObject obj in result)
            {
                obj.GetUri(objectUri);
                Debug.Log("Uri del objeto: " + objectUri);
                string turno = (string)obj[key2];
                string turnoplayer = (string)obj[key3];
                string idjugador1 = (string)obj[key9];

                //Updating match information.
                KiiObject obj2 = KiiObject.CreateByUri(new Uri(objectUri));
                obj2.Refresh((KiiObject obj3, Exception e2) =>
                {
                    if (e2 != null)
                    {
                        Debug.LogError("Retreving Object failed: " + e2.ToString());
                        // handle error
                        return;
                    }
                    //Update following information
                    value1 = round.ToString();
                    value2 = turno;
                    value3 = turnoplayer;
                    value4 = full;
                    value5 = mystats.idplayer;
                    value9 = idjugador1;

                    obj3[key1] = value1;
                    obj3[key2] = value2;
                    obj3[key3] = value3;
                    obj3[key4] = value4;
                    obj3[key5] = value5;
                    obj3[key6] = value6;
                    obj3[key7] = value7;
                    obj3[key8] = value8;
                    obj3[key9] = value9;
                    obj3[key10] = value10;
                    obj3[key11] = value11;
                    obj3.SaveAllFields(false, (KiiObject updatedObj, Exception e3) =>
                    {
                        if (e3 != null)
                        {
                            Debug.LogError("Update Object failed: " + e3.ToString());
                            // handle error
                        }
                        else
                        {
                            //TENEMOS QUE SEGUIR AQUI: IMPLEMENTAR KII TOPICS
                            mystats.idplayer2 = key9;
                            Debug.Log("Match information upadted successfully.");
                        }
                    });
                });
            }
        });
        /*
        storageService = sp.BuildStorageService();
        storageService.FindDocumentByKeyValue(dbName, collectionName, key4, validador, callBack);
        nomatch = 0;
        check = true;
        */
    }
示例#21
0
 void Start()
 {
     Kii.Initialize("{APP ID}", "{APP KEY}", "http://api-jp.kii.com/api");
     KiiAnalytics.Initialize("{APP ID}", "{APP KEY}", "http://api-jp.kii.com/api", GetDeviceID());
 }
示例#22
0
    void Awake()
    {
        Debug.Log("Initialize");

        Kii.Initialize(APP_ID, APP_KEY, Kii.Site.JP);
    }
示例#23
0
    void OnEnable()
    {
        if (applicationController.sessionStarted)
        {
            for (int i = 0; i < 4; i++)
            {
                GameObject instantiatedPrefab;
                instantiatedPrefab = Instantiate(screenshotBox) as GameObject;
                instantiatedPrefab.SetActive(true);
                instantiatedPrefab.transform.SetParent(screensList.transform);
                instantiatedPrefab.transform.localScale = new Vector3(1, 1, 1);
                instantiatedPrefab.GetComponent <Button> ().onClick.AddListener(() => GetButtonIndex(instantiatedPrefab));
                instantiatedPrefab.GetComponent <Button> ().onClick.AddListener(() => OpenScreenshot());
                buttonList.Add(instantiatedPrefab);
            }
            bool      validate  = true;
            KiiBucket appBucket = Kii.Bucket("Games");
            //string gameNameTrim = gameName.GetComponent<InputField> ().text.Replace (" ", String.Empty);

            /*KiiQuery query = new KiiQuery(
             * KiiClause.And(
             * KiiClause.Equals("gameName", gameName.GetComponent<InputField>().text)
             * ,KiiClause.Equals("bucketScreenshotsId", gameNameTrim)
             * )
             * );*/
            //string bucketName = gameNameTrim+"-Screenshots-";
            string    userId = KiiUser.CurrentUser.ID;
            KiiObject obj    = Kii.Bucket("Games").NewKiiObject();
            String    id     = "";
            try {
                obj.Refresh();
                id = obj.GetString("_id");
            } catch (Exception e) {
                Debug.Log("Fallo refresh id game: " + e);
            }

            /*obj["gameName"] = gameName.GetComponent<InputField>().text;
             * obj["gameDescription"] = gameDescription.GetComponent<InputField>().text;
             * obj["gameCategories"] = gameCategories.GetComponent<InputField>().text;
             * obj["gameKeywords"] = gameKeywords.GetComponent<InputField>().text;
             * obj["gameEula"] = gameEula.GetComponent<InputField>().text;
             * obj["gamePlatform"] = gamePlatform.GetComponent<Text> ().text;
             * obj["gameLanguage"] = gameLanguage.GetComponent<Text> ().text;
             * obj["userId"] = userId;
             * obj["bucketScreenshotsId"] = gameNameTrim;*/

            //obj["GameBucket"] = userId;

            //if(ValidatedFields()){

            /*appBucket.Count(query, (KiiBucket b, KiiQuery q, int count, Exception e) => {
             * if (e != null){
             *      validate = false;
             *      applicationController.alertView.GetComponent<AlertViewController> ().SetAlert ("Unexpected exception occurred");
             *      navigationController.GoTo ("ALERT_VIEW");
             *      return;
             * }
             * if (count > 0){
             *      validate = false;
             *      applicationController.alertView.GetComponent<AlertViewController> ().SetAlert ("Game name already exist");
             *      navigationController.GoTo ("ALERT_VIEW");
             *      return;
             * }*/
            if (validate)
            {
                // Save the object
                obj.SaveAllFields(true, (KiiObject savedObj, Exception exc) => {
                    if (exc is NetworkException)
                    {
                        if (((NetworkException)exc).InnerException is TimeoutException)
                        {
                            // Network timeout occurred
                            applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Network timeout occurred");
                            navigationController.GoTo("ALERT_VIEW");
                            return;
                        }
                        else
                        {
                            // Network error occurred
                            applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Network error occurred");
                            navigationController.GoTo("ALERT_VIEW");
                            return;
                        }
                    }
                    else if (exc is ConflictException)
                    {
                        // Registration failed because the user already exists
                        applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Registration failed because the game name already exists");
                        navigationController.GoTo("ALERT_VIEW");
                        return;
                    }
                    else if (exc is CloudException)
                    {
                        // Registration failed
                        applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Registration failed");
                        navigationController.GoTo("ALERT_VIEW");
                        return;
                    }
                    else if (exc != null)
                    {
                        // Unexpected exception occurred
                        applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Unexpected exception occurred");
                        navigationController.GoTo("ALERT_VIEW");
                        return;
                    }
                    ;
                    objUri = obj.Uri;
                    Debug.Log("mi uri es:" + objUri);

                    /*Debug.Log ("SavingImages.");
                     * SaveImage(0, obj);*/
                });
            }

            //});
            //Check whether the id is valid.

            /*for (int i = 1; i < imagePaths.Length; i++){
             * SaveImages(bucketName, i);
             * }
             * Debug.Log ("ImagesSaved: GoTo Edit");*/
            //navigationController.GoTo ("EDIT_VIEW");
            //}
        }
    }
示例#24
0
    public static void RegisterDeath(GameObject deadObject)
    {
        if (Instance == null)
        {
            Debug.Log("Game score not loaded");
            return;
        }

        int
            playerLayer = LayerMask.NameToLayer(Instance.playerLayerName),
            enemyLayer  = LayerMask.NameToLayer(Instance.enemyLayerName);

        Debug.Log("Getting KiiUser");
        user = KiiUser.CurrentUser;

        if (user == null)
        {
            if (deadObject.layer == playerLayer)
            {
                Instance.deaths++;
            }
            else if (deadObject.layer == enemyLayer)
            {
                Instance.kills [deadObject.name] = Instance.kills.ContainsKey(deadObject.name) ? Instance.kills [deadObject.name] + 1 : 1;
            }
            else
            {
                Instance.kills [deadObject.name] = Instance.kills.ContainsKey(deadObject.name) ? Instance.kills [deadObject.name] + 1 : 1;
            }
            return;
        }

        Debug.Log("Creating app bucket");
        appBucket = Kii.Bucket(BUCKET_NAME);

        Debug.Log("Creating death object");
        KiiObject death = appBucket.NewKiiObject();

        death["user"]  = user.Username;
        death ["time"] = Time.time;

        if (deadObject.layer == playerLayer)
        {
            Instance.deaths++;
            death ["type"]  = "Player";
            death ["count"] = Instance.deaths;
            Debug.Log("Dead player counted");
            Debug.Log("Saving death object");
        }
        else if (deadObject.layer == enemyLayer)
        {
            Instance.kills [deadObject.name] = Instance.kills.ContainsKey(deadObject.name) ? Instance.kills [deadObject.name] + 1 : 1;
            death ["type"]  = "Enemy";
            death ["enemy"] = deadObject.name;
            death ["count"] = Instance.kills [deadObject.name];
            Debug.Log("Dead enemy counted");
            Debug.Log("Saving death object...");
        }
        else
        {
            Instance.kills [deadObject.name] = Instance.kills.ContainsKey(deadObject.name) ? Instance.kills [deadObject.name] + 1 : 1;
            death ["type"]  = "Unknown";
            death ["enemy"] = deadObject.name;
            death ["count"] = Instance.kills [deadObject.name];
            Debug.Log("Dead entity counted");
            Debug.Log("Saving death object...");
        }

        death.Save((KiiObject obj, Exception e) => {
            if (e != null)
            {
                Debug.Log("GameScore: Failed to create death object: " + e.ToString());
            }
            else
            {
                Debug.Log("GameScore: Create death object succeeded");
            }
        });
    }