playMaker

Author Topic: How can I load a FsmTemplate from the template file at runtime  (Read 1214 times)

pippocao

  • Playmaker Newbie
  • *
  • Posts: 2
    • View Profile
How can I load a FsmTemplate from the template file at runtime
« on: February 02, 2014, 01:58:45 AM »
Hi, everyone, I've encounterd a problem and cannot find the solution in this forum, so I post this thread to request some helps.
I am developing a network game, and I need to load different template files to specify my character behaviours. the key point is that the choosing of  the right template which is decided by server side. For example, the server told client that it need to place a enemy on the scene, and the enyme will attack player automatically, so I will attach a PlayMakerFSM component to the character gameObject and invoke SetTemplate(FsmTemplate template) method of the PlayMakerFSM component. The FsmTemplate is loaded from a prepared playmaker template file names "AutoAttack.asset" . Below is my code:

Code: [Select]
string templateFileName = getBehaviourFromServer();  //the template file name is got from server at runtime.
PlayMakerFSM fsmComponent = gameObject.addComponent<PlayMakerFSM>();
FsmTemplate template = LoadTemplateFromFile(templateFileName);
fsmComponent.SetTemplate(template);

So my question is that how can I implement LoadTemplateFromFile method, is there any API I can use?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3631
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: How can I load a FsmTemplate from the template file at runtime
« Reply #1 on: February 02, 2014, 08:37:25 AM »
Are the templates on the server or in your build?

If you want them on the server you should use AssetBundles:
http://docs.unity3d.com/Documentation/Manual/AssetBundlesIntro.html

If they're in the build, put them is a Resources folder and use Resources.Load:
http://docs.unity3d.com/Documentation/ScriptReference/Resources.Load.html

Either way you should be able to load the resource by name, cast it to an FsmTemplate, then use SetTemplate.

pippocao

  • Playmaker Newbie
  • *
  • Posts: 2
    • View Profile
Re: How can I load a FsmTemplate from the template file at runtime
« Reply #2 on: February 02, 2014, 09:20:30 AM »
Thanks very much! this will help me