1
PlayMaker Help / GOT IT...For Public Use Getting data from a web page to PlayMaker
« on: June 11, 2012, 12:13:51 PM »
Please feel free to try this code if you need to get data/values from webPlayer to PlayMaker.
Use: Pull Data from a database and use those to invoke PlayMaker actions.
WebPlayer
wwwCall.cs
Use: Pull Data from a database and use those to invoke PlayMaker actions.
WebPlayer
Code: [Select]
<script type="text/javascript" src="UnityObject.js"></script>
<script type="text/javascript">
<!--
function GetUnity() {
if (typeof unityObject != "undefined") {
return unityObject.getObjectById("unityPlayer");
}
return null;
}
if (typeof unityObject != "undefined") {
unityObject.embedUnity("unityPlayer", "WebPlayer.unity3d", 400, 400);
}
-->
</script>
<script type="text/javascript">
<!--
function getAnimClip(Void)
{
// [unityGameObject],[FuntionName],[Vals(Array) to be passed to Unity]
GetUnity().SendMessage( "wwwCom", "myAnimationCall", "Human^Male^M16^crouchM16" );
}
-->
</script>
[/b]wwwCall.cs
Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;
using System.Collections;
public class wwwCall : MonoBehaviour
{
//set a Spot in the Editor for PlayMaker Object
public PlayMakerFSM wwwPlayer;
// Use this for initialization
void Start ()
{
//we know the web player has now loaded: lets get that data string!!
Application.ExternalCall("getAnimClip", 0);
}
void myAnimationCall(string indata)
{
//Lets Try to Get and Parse that browser data!!
try
{
//Heres the data from the web page, lets Split it on my [^] Char.
string[] words = indata.Split('^');
//Now That I have the Data Split into the Values I need, let's go ahead and send to PlayMaker!!
wwwPlayer.FsmVariables.GetFsmString("strCat").Value = words[0];
wwwPlayer.FsmVariables.GetFsmString("strGender").Value = words[1];
wwwPlayer.FsmVariables.GetFsmString("strAction").Value = words[2];
wwwPlayer.FsmVariables.GetFsmString("strFileName").Value = words[3];
//Debug.Log (indata);
}
catch
{
//Debug.Log("NO DATA!!!!!!!!!");
}
}
}