Ya. newtonSoft has a great JSON library.
But UniWeb comes with its JSON Decode and Econde native support, so I will just take that instead.
UniWeb has great features like
- HTTPS
- JSON,
- cookies,
- texture downloading,
- websocket,
- steam,
- keepAlive,
- HTTP cache,
- GZIP,
- send binary data(eg: after you take a picture in iphone and you can send it to server to save it)
...etc .. just like all the stuff you would expected for networking.
Playmaker cant really do serious network game with only get request and socket.
Sure. I wrote my own script just now. It works for basic REST server calls.
Altho I am not sure if i am doing it right without yield.
Hopefully someone can add more functions.
--------------------------------------
using UnityEngine;
using HutongGames.PlayMaker;
[ActionCategory(ActionCategory.Network)]
[Tooltip("UniWebWWW")]
public class UniWebWWW : FsmStateAction
{
public FsmString type;
public FsmString url;
private HTTP.Request r;
[ActionSection("Results")]
[UIHint(UIHint.Variable)]
[Tooltip("Gets text from the url.")]
public FsmString storeText;
[UIHint(UIHint.Variable)]
[Tooltip("Gets a Texture from the url.")]
public FsmTexture storeTexture;
[UIHint(UIHint.Variable)]
[Tooltip("Error message if there was an error during the download.")]
public FsmString errorString;
[UIHint(UIHint.Variable)]
[Tooltip("How far the download progressed (0-1).")]
public FsmFloat progress;
[ActionSection("Events")]
[Tooltip("Event to send when the data has finished loading (progress = 1).")]
public FsmEvent isDone;
[Tooltip("Event to send if there was an error.")]
public FsmEvent isError;
// Code that runs on entering the state.
public override void OnEnter()
{
r = new HTTP.Request (type.Value, url.Value);
r.Send();
}
// Code that runs every frame.
public override void OnUpdate()
{
if (r == null)
return;
if(r.exception != null) { //some error occured.
Debug.Log(r.exception.ToString());
errorString.Value = r.exception.ToString();
Finish();
Fsm.Event(isError);
return;
}
progress.Value = r.Progress;
if(r.state != HTTP.RequestState.Waiting) { //there might be some chunks available
}
if (r.isDone) {
storeText.Value = r.response.Text;
/*
var tex = new Texture2D (512, 512);
storeTexture.LoadImage (r.response.Bytes);
renderer.material.SetTexture ("_MainTex", tex);
storeTexture.Value = tex;
*/
Fsm.Event(string.IsNullOrEmpty(errorString.Value) ? isDone : isError);
Finish ();
}
}
}