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.
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