playMaker

Author Topic: Zenject integration  (Read 1060 times)

jojoblaze

  • Playmaker Newbie
  • *
  • Posts: 5
Zenject integration
« on: January 14, 2021, 06:50:29 AM »
I am using Zenject for a project and I would like to integrate with PlayMaker.
Zenject is a IoC framework. Basically I need to, inject or resolve, dependencies when CustomAction is activated.
There are some guidelines or best practices?
Maybe someone already dealt with this?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Zenject integration
« Reply #1 on: January 14, 2021, 07:37:20 AM »
Hi.
Not sure how to integrate this, but here you can find the playmaker API :
https://hutonggames.fogbugz.com/default.asp?W127

jojoblaze

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Zenject integration
« Reply #2 on: January 15, 2021, 04:24:08 AM »
I think you guys should take a look at dependency injection. Inversion of Control is a really useful and famous pattern. A great tool like PlayMaker should support and promote this pattern.

jojoblaze

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Zenject integration
« Reply #3 on: January 16, 2021, 02:27:34 PM »
For the sake of the argument I'm going to explain the situation I'm facing, maybe it could be useful for someone.
My Unity project use Zenject for dependency injection (if you don't know what is it, take a look here: https://blogs.unity3d.com/2014/05/07/dependency-injection-and-abstractions/ for a quick introduction).
I have a UIManager class that handle in-game user interface like menus, dialogues windows, notifications and so on (I'm a developer, so it's easier manage these things directly with code).
The UIManager object is instantiated by Zenject and is available for all other objects which may need it (this is the great convenience of DI).
Then I created some custom actions to handle ui at high level with PlayMaker. In this way I can show dialogues and prompt user for input, if he need to make a choice or give an answer and manage the conduct of the conversation jumping from one state to another based on responses.
In the action inspector I only need set options and text for dialogues, then the action will invoke UIManager methods passing parameters.
It's sooo flexible and now I love PlayMaker!  8)

So, what is the problem? It's about code design.
DI help to write clean and testable code (is very important!).

I managed to get it work, but I had to resort to singleton.
Despite being widely used especially in game development, has several drawbacks (look here https://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons for more info).

Zenject has different ways to inject dependencies, but basically it need to manage or oversee objects instantiation in some way. It seems that FsmStateAction are instantiated through the Activator and I found no way to hook FsmStateAction instantiation.

If I'll found a way to make it work properly with injection, I'll report here, but I'd really like to know if there is some support to injection or if it's planned in some future release.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Zenject integration
« Reply #4 on: January 16, 2021, 03:52:38 PM »
Hi.
To be honest, i don't think that there are plans to integrate this, as it looks like then it would be dependent on this.

Also even for none playmaker users there is not much demand for this yet.

But you could make other people happy by sharing your actions :) or set a open source git of what you have achieved :)