playMaker

Author Topic: Web browser interaction  (Read 1882 times)

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Web browser interaction
« on: February 12, 2014, 01:00:29 PM »
This is something that is becoming quite key to our project and with the project built with playmaker, we need to get a little more clued up on how to send information to the FMS's. Sending Strings has gone fine as we are getting there with that and now we need to try and replicate this for things like

SendEvent - Broadcast All and Specific FSM
Float - This should be similar to Strings?

For Send Event we are trying this, in our Unity Script

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;
using System.Collections;

public class wwwCall : MonoBehaviour
{
public PlayMakerFSM Decal;
void AddDecal()
{
Application.ExternalCall("AddDecal", "");
//Lets Try to Get and Parse that browser data!!
try
{
//Now send the new logo event to Playmaker FSM
Decal.Fsm.Event("CreateNewLogo");
}
catch
{
//Debug.Log("NO DATA!!!!!!!!!");
}
}
}

And in our web Javascript we are doing

Code: [Select]
<script type="text/javascript">
function AddDecal()
{
u.getUnity().SendMessage("getModel", "AddDecal");
}
</script>

and HTML
Code: [Select]
<td>
<input type="image" src="/images/Cameras_01.gif" width="100" height="127" alt="" onClick="AddDecal()"/></td>

So far this isn't working (unsurprisingly) and I am guessing it is mainly due to the Decal.Fsm.Event("CreateNewLogo"); part of our code? Where is the best place to get the references to pick up what and how we should be referencing the playmaker actions/fsm's etc?

Any support on this would be great!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15501
  • Official Playmaker Support
Re: Web browser interaction
« Reply #1 on: February 12, 2014, 02:03:13 PM »
Hi,

 It looks to me you are bitting your own tail.

1: name your methods distinctively, you have both AddDecal in web Javascript and in Unity c#: very confusing: AddDecal is either an action to perform in the web or in unity.

2: in c# AddDecal, you call the web method AddDecal, and in that you send a message back to unity "AddDecal", so it's looping isn' it.

3: you need to cut down your problem:

 A: communicate back and forth between unity and the web page
 B: communicating from c# to PlayMaker.

 A: I think you have this working, only you need to clean that up to see the process more clearly.
 
 B: try with a simple script, not linked to anything fancy, just a simple mousedown method that would fire a PlayMaker event. once you have that working you can use this inside a method called by the web page itself.


Also, use debug statement to log activity on each of your methods so you know who gets called and at what point it fails to process further.

Please find below a script that effectivly send events to a playmaker fsm OR broadcast to all if no playmaker is referenced.

Code: [Select]
using UnityEngine;
using System.Collections;

using HutongGames.PlayMaker;

public class PlaymakerMessageBroker : MonoBehaviour {

public PlayMakerFSM target;
public string eventName;

private PlayMakerFSM fsmProxy;

public void Start()
{
fsmProxy = this.GetComponent<PlayMakerFSM>();

if (fsmProxy==null)
{
Debug.LogError("A Fsm is required to be attached to a gamObject using this script");
}

}

public void messageBroker()
{
FireEvent();
}

public void messageBroker(string stringVar)
{
FsmEventData eventData = new FsmEventData();
eventData.StringData = stringVar;

Fsm.EventData = eventData;
FireEvent();
}


private void FireEvent()
{
if (target==null)
{
PlayMakerFSM.BroadcastEvent(eventName);
}else if (fsmProxy!=null){

// set the target to be this gameObject.
FsmOwnerDefault goTarget = new FsmOwnerDefault();
goTarget.GameObject = new FsmGameObject();
goTarget.GameObject.Value = target.gameObject;
goTarget.OwnerOption = OwnerDefaultOption.SpecifyGameObject;

       // send the event to this gameObject and all its children
FsmEventTarget eventTarget = new FsmEventTarget();
eventTarget.excludeSelf = false;
eventTarget.target = FsmEventTarget.EventTarget.GameObject;
eventTarget.gameObject = goTarget;
eventTarget.sendToChildren = false;

// create the event.
FsmEvent fsmEvent = new FsmEvent(eventName);

// send the event
fsmProxy.Fsm.Event(eventTarget,fsmEvent.Name); // TOFIX: doesn't work if using simply fsmEvent
}
}




}




If you are still stuck, let me know :)

bye,

 Jean

adgrist

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Web browser interaction
« Reply #2 on: February 12, 2014, 02:13:43 PM »
Fantastic thanks Jean, will give this a go tomorrow. Much appreciated