playMaker

Author Topic: UniWeb Actions  (Read 6072 times)

tester

  • Playmaker Newbie
  • *
  • Posts: 31
UniWeb Actions
« on: November 24, 2012, 03:00:19 PM »
The playmaker's WWWobject is pretty limited.
EG: doesnt work for REST, setting header, JSON decode.
Hopefully UniWeb can be used for improvement.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15537
  • Official Playmaker Support
Re: UniWeb Actions
« Reply #1 on: November 24, 2012, 03:41:21 PM »
hi,

 Yes, UniWeb is the only viable solution for proper webService Access for any serious projects. wwwObject will get the job done for simple things and proof of concepts tho.

Json should be handled by newtonSoft great library.

Like Data management, web services and online access in general is such a vast topic that it is difficult to find the right balance, maybe you could list some usage you would like to benefit like obviously texture downloading, but you might other needs.

It would be indeed very good to develop a series of custom actions to support UniWeb conveniently within PlayMaker. maybe you could participate if you have some scripting knowledge? This would be welcome indeed.


bye,

 Jean

tester

  • Playmaker Newbie
  • *
  • Posts: 31
Re: UniWeb Actions
« Reply #2 on: November 24, 2012, 04:13:41 PM »
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 ();
      }

      
   }


}
« Last Edit: November 24, 2012, 04:22:02 PM by tester »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15537
  • Official Playmaker Support
Re: UniWeb Actions
« Reply #3 on: November 26, 2012, 12:32:36 AM »
Hi,

 Good! thanks for that.

--  I noticed that your "storeTexture" will not work because the related code is commented out. So maybe you should comment also the public variable, else users will think it's a bug.


Also, don't hesitate to share the actual file in the "Share new action" section of the forum, it will be easier for people to find your work.
http://hutonggames.com/playmakerforum/index.php?board=19.0

bye,

 Jean