playMaker

Author Topic: Solved!! get the code-> web page data to Player maker??  (Read 18640 times)

forcevfx

  • Playmaker Newbie
  • *
  • Posts: 20
Solved!! get the code-> web page data to Player maker??
« on: June 09, 2012, 10:14:56 PM »
I am building this Unity3D Web Site/App.

re.--------------------
UNImations is dedicated to providing free and inexpensive characters and motion
captured based animations.

 All assets are run through the Unity3D game engine and the web player will show you exactly what your getting. I have decided to use two common rigs(bones), one female and one male. This allows me to re-target my entire library of mocaps, much more easily!! Take a look at some of my video captures and sample web players
----------------------
HD Video: explains more: http://www.youtube.com/watch?v=ulLBsjBYK4s  
UNImations.com (free prefabs and animations)
shop.UNImations.com (paid prefabs and animations)

I am trying to get a string value into FSMvariables.
Please take a look at this, it should explain everything..

Animation Search page: http://unimations.com/anims.aspx

I have tried www. wwwFor, wwwAction (but do i create a custum string parse action?
I am Sooo Close..

I know playmaker will get the animation string, and play it. that works but, I need 3 more string variables.
I know  I can get Unity/Playmaker to play animation by name gender and action type.

Thanks

Patrick
« Last Edit: June 11, 2012, 12:15:00 PM by forcevfx »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Was hoping someone could help - web page to Player maker??
« Reply #1 on: June 09, 2012, 10:32:15 PM »
Hi,

 parsing a web page to get info within the html DOM will be a nightmare.

 I suggest you create a dedicated "web service" for this, outputing nothing but the required information in a format convenient for scripting environment ( read not for users to see or read).

for example, build a web server page called animList.aspsx ( or in php, whatever) and calling this page would return aplain text csv list like so :


Category,Gender,Action,Name
Human,Male,Pistol,Pistol_AimDown.anim
Human,Male,Pistol,Pistol_AimIdle.anim
Human,Male,Pistol,Pistol_AimLeft.anim
Human,Male,Pistol,Pistol_AimRight.anim.anim
Human,Male,Pistol,Pistol_AimStraight.anim
Human,Male,Pistol,Pistol_AimUp.anim

then it become a lost easier to access from playmaker,

I started on this kind of cases before christmas and got carried away...
http://hutonggames.com/playmakerforum/index.php?topic=891.0

I went into parsing csv content into a xml structure for then use xpath to access data, very powerful. If you need this work to be further developed so that you can finish your web site system, pm me and we'll see what we can do. Else you can always implement something manually, but you will definitly require arrayMaker, that would make things a lot easier to start with.

https://hutonggames.fogbugz.com/default.asp?W715


also aside the technical implementation, I am not sure what you are actually aimed to achieve here in terms of workflow. Could you explain a bit more in details? like hw do you plan on using them three strings if you actually could only need the name of the animation file itself.

bye,

 Jean

forcevfx

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Was hoping someone could help - web page to Player maker??
« Reply #2 on: June 09, 2012, 11:11:53 PM »
I am trying to build a web player that play animations based on Character Gender and Action Type: animation..
That would actually get me there.

scenario:

user wants to see: male pistol fire

now I want to get that in play maker and load unoad male/female.
Then depending on action type :Hand/Pistol/Sword/M16, etc..
I can hide or unhide the weapon pack prefab item.

the anim name does hold action type, so I could , 'InString that..'

but how to I place the player on a differen/new window (than the list).

I would really like an iFrame / or ajax window, so when you click on the list, the right character and animation will play..

simple...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Was hoping someone could help - web page to Player maker??
« Reply #3 on: June 10, 2012, 03:59:57 AM »
Hi,

 ok, I think you will be better off merging everything in Unity, instead of having a web page and unity web player communicating together. It would solved a lot of trouble, and you have one place to update.

 Else, it's not such a problem anyway. Do you have already the knowledge on how to communicate from the page back to Unity?

http://unity3d.com/support/documentation/Manual/Unity%20Web%20Player%20and%20browser%20communication.html

With this, you are left with three tasks:

1: To place Unity within your page. this is plain html technics, so I won't go too much in details about this, but if you simply copy paste from the web page generated as you publish unity for the web, you should have everything there to construct the page layout you need.

2: create a script that will bridge the unity.SendMessage() to actually fire an event within playmaker. Something that I can do for you if you don't have the scripting skills.

3: upon this event, react appropriatly to trigger the right animation, show hide props etc etc. that will be already the fun part :) I would go for a very simply string definition,and each keyword delimited by a comma or something, then you can use the slit custom action featured in arrayMaker to store each element in an array and access them to decide finally what to do.


 as an even more quick and dirty way, simply hard code references with integers, say 0 is for Pistol_AimDown.anim, 1 is for Pistol_AimIdle.anim etc etc then within Playmaker you simply compare the int and react appropriately. This is quick, but may become difficult to maintain tho.

 Bye,

 Jean




forcevfx

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Was hoping someone could help - web page to Player maker??
« Reply #4 on: June 10, 2012, 10:45:35 AM »
here what I tried..

1).
Code: [Select]
<%
            ConnectString = "Driver={SQL Server}; Server="
            Set Conn = Server.CreateObject("ADODB.Connection")
            'open the databse connection
            Conn.Open ConnectString

            'strProd_Category = "Human"
            'strProd_Gender = "Male"
            'strProd_subCategory = "M16"
            'strProd_Filename = "crouchM16.anim"

            strProd_Category = Request("strProd_Category")
            strProd_Gender = Request("strProd_Gender")
            strProd_subCategory = Request("strProd_subCategory")
            strProd_Filename = Request("strProd_Filename")

            SQLCmdAnimFile = " SELECT TOP(1)* FROM ProductFile WHERE Prod_Category LIKE '" & strProd_Category & "' AND " &_
            "" & " Prod_Gender LIKE '" & strProd_Gender & "' AND  Prod_subCategory LIKE '" & strProd_subCategory & "' AND Prod_Filename LIKE '" &  strProd_Filename & "'"

            SET DataRS = Conn.Execute(SQLCmdAnimFile)
            Response.Write "<br>SQLCmdAnimFile: " & SQLCmdAnimFile

   IF NOT DataRS.EOF THEN
            DO WHILE NOT DataRS.EOF

            Prod_Category   = DataRS("Prod_Category")
            Prod_Gender = DataRS("Prod_Gender")
            Prod_subCategory = DataRS("Prod_subCategory")
            Prod_Filename  = DataRS("Prod_Filename")
            strProd_Name = Replace(Prod_Filename,".anim","",1)


               strFile = Prod_Category & "^" & strProd_Gender & "^" & Prod_subCategory & "^" &  strProd_Name

   DataRS.MOVENEXT
   LOOP
   ELSE
                strFile = "crouchM16_runBackwards"
   End If

                Response.Write "<br> Data I am Pushing to Unity: <br>" & strFile

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Unimations.com WebPlayer</title>
<script type="text/javascript" src="Scripts/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", "SoldierPlayer_M16/WebPlayer/WebPlayer.unity3d", 400, 400);
       unity.SendMessage("wwwCall", "myAnimationCall", "<%=strFile%>");
   }
-->
</script>
#2). Inside Uinity wwwCall()

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

public class wwwCall : MonoBehaviour {

public PlayMakerFSM wwwCbj;

public FsmString Cat;
public FsmString Gender;
public FsmString Action;
public FsmString FileName;

private string strCat;
private string strGender;
private string strAction;
private string strFileName;

// Use this for initialization
void Start ()

{

}

// Update is called once per frame
void Update ()
{
Cat = strCat;
Gender = strGender;
Action = strAction;
FileName = strFileName;

Cat = wwwCbj.FsmVariables.GetFsmString("strCat");
Gender = wwwCbj.FsmVariables.GetFsmString("strGender");
Action = wwwCbj.FsmVariables.GetFsmString("strAction");
FileName = wwwCbj.FsmVariables.GetFsmString("strFileName");
}

void myAnimationCall(string indata)
{
string[] words = indata.Split('^');

strCat = words[0];
strGender = words[1];
strAction = words[2];
strFileName = words[3];
Debug.Log (indata);
}


}
« Last Edit: June 10, 2012, 10:47:11 AM by forcevfx »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Was hoping someone could help - web page to Player maker??
« Reply #5 on: June 10, 2012, 01:19:05 PM »
Hi,

 Are you saying it doesn't work? or do you have that part now covered and wondering what to do next?

 bye,

 Jean

forcevfx

  • Playmaker Newbie
  • *
  • Posts: 20
Re: Was hoping someone could help - web page to Player maker??
« Reply #6 on: June 10, 2012, 03:01:51 PM »
well. it seems it should work..its not...

I'll go back again..maby because I a trying to set global FSMvars by script??
Maby I am putting blocks of code in the wrong place.

It seems like that is exactly what you described..this was my last attempt before posting "help"
I was coding for ten 10 hours . .net/sql/asp/c#/unityscript..going through every search link I could find..

This is a pretty importany peice to my business model.

so , as you can see..I made a valid attempt..and should be pretty close, if not there.

anyway..look at code, see if there is any Glaring mistakes..

Thanks for your help!!


p-

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Was hoping someone could help - web page to Player maker??
« Reply #7 on: June 10, 2012, 04:27:12 PM »
Hi,

 yes there are obvious error when you are trying to set the Fsm variables, instead you actually simply need to do the following:

remove the update function all together, you don't need that

in the function myAnimationCall

wwwCbj.FsmVariables.GetFsmString("strCat").Value = word[0];

then you will really put the first word in the Fsm variable "strCat" if it does exits of course. Note the .Value appended, else it won't work. FsmString is a wrapper of a string, not the string itself.


Bye,

 Jean

forcevfx

  • Playmaker Newbie
  • *
  • Posts: 20
GOT IT...For Public Use Getting data from a web page to PlayMaker
« Reply #8 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
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!!!!!!!!!");
}
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Solved!! get the code-> web page data to Player maker??
« Reply #9 on: June 12, 2012, 04:53:18 AM »
Hi,

 Thanks for sharing!

bye,

 Jean