playMaker

Author Topic: Connect PlayMaker to a "Model" class  (Read 2237 times)

vikti

  • Playmaker Newbie
  • *
  • Posts: 2
Connect PlayMaker to a "Model" class
« on: September 22, 2014, 04:12:33 PM »
Hello,

I am working on a RPG game where item could have several representations in different views. (Map, Inventory, Arena...)
So I separate data in a Model class (ex: WeaponModel) and put the view and action logic on a base prefab (weapon.prefab)

A factory build my items (weapons, grunts, stuff...) and add FSM on runtime (non implemented yet).

My question is how can I connect a FSM which, for example, change the item owner (the player ID) in the Model class ?

Regards,


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Connect PlayMaker to a "Model" class
« Reply #1 on: September 23, 2014, 12:46:40 AM »
Hi,

 I worked on this with DfGUI ( sadly went into the bin as it's not supported anymore), but basically, you'll have several possibilities:

1: your models are expressed as components or gameobjects: This is the "best" in your case as it becomes accessible like anything else. I like this a lot, but pur coders may pull their hairs and scream :)

2: If your models are regular classes, then you'll need to write custom actions.

 Are you desigining and writing this system or ae you using a framework for this model representation?

 Bye,

 Jean

vikti

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Connect PlayMaker to a "Model" class
« Reply #2 on: September 23, 2014, 03:46:13 AM »
Hello,
Thx for your answer. Indeed i am designing and writing the model layer and I use specific class called WeaponModel, StuffModel,etc... All those models extends a base class called Item with all basic properties (ownerId, geocoord, name...)

I can't use gameobject at this level for serialization and decoupling reasons.

My architecture takes the MVVM pattern :
- xxxModel is the model
- xxxFSM is the ViewModel part
- gameobject and its behaviors the View

So I have also read some stuff on custom action and I think I will do that.

After dinamically put a FSM on my gameobject, my goal for this  action is to :

Look in a component a property which refers to a custom class instance (xxxModel) and doublebind all properties (already listed in the fsm template) on the xxxModel.

Any usefull tips on this ?

(I am not @home but if you need some code I can paste it here)
« Last Edit: September 23, 2014, 03:50:03 AM by vikti »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Connect PlayMaker to a "Model" class
« Reply #3 on: September 23, 2014, 04:10:57 AM »
Hi,

 You can always use components for your models, as wrappers, think of it as a "Unity" representation. But that's fair enough maybe an overkill in most cases.

be VERY careful with dynamic creation, make sure you use a pooling system, cause creating component is costly in Unity.

Tips:

-- Don't rely too much on reflection, it can cause issues on mobile platforms, instead create true custom actions, one for each of your models specifically.

-- separate getters and setters, make one action to get values and one action to set values. Possibly even make one action for each value within a model, if you only need to do granular work within PlayMaker.

-- You can create some editor tools to generate these custom actions. if you are building a framework, I suggest you do that, it will save you time in the long run to ensure that your actions are always true to your models, when refactoring or incrementing features.

You can also have your PlayMaker template as a composition of your model, features each properies, and then you can do the job the other way around, have your framework synchroinizing modesl to their PlayMaker templates equivalent, but that's of course if you do have a one to one bases between all your models and fsm templates ( which I think you don't).

 Bye,

 Jean


 Bye,

 Jean