예제 #1
0
 public void UpdatePlayerItem(UpdatePlayerItem updatePlayerItem, IInventoryApi caller)
 {
     StartCoroutine(UpdatePlayerItemRoutine(updatePlayerItem, caller));
 }
예제 #2
0
            public IEnumerator UpdatePlayerItemRoutine(UpdatePlayerItem updatePlayerItem, IInventoryApi caller)
            {
                string uri = NetworkSettings.instance.BaseUri() + "/api/game/inventory/update_player_item";
                var form = new WWWForm();
                form.AddField("playerId", NetworkSettings.instance.username);
                form.AddField("authtoken", NetworkSettings.instance.authtoken);

                MemoryStream stream = new MemoryStream();
                Serializer.Serialize(stream, updatePlayerItem);
                string content = System.Convert.ToBase64String(stream.ToArray());
                form.AddField("content", content);

                WWW www = new WWW(uri, form.data, form.headers);
                yield return www;

                if (www.error != null) {
                    caller.OnUpdatePlayerItemError(www.error);
                } else {
                    stream = new MemoryStream(www.bytes);
                    updatePlayerItem = Serializer.Deserialize<UpdatePlayerItem>(stream);
                    caller.OnUpdatePlayerItem(updatePlayerItem);
                }
            }