I'm using the Mapbox SDK and RoadArchitect and trying to build some game initialization code that uses Mapbox to generate a list of vectors, then take that list of vectors and call functions in Road Architect to generate road GameObjects. In order to do this, I need to wait until Mapbox has finished it's work before I can run the code to generate roads. I extended the Mapbox MergedModifierStack as ObservedModifierStack and added a StackComplete event.
My current scene setup has 2 relevant GameObjects:
AbstractMap
)
Map.VectorTileFactory.Factories[m].Visualizer.ObservedModifierStack .Modifiers[n].MyModifier
GSDRoadSystem
Most of the objects in the Map hierarchy are ScriptableObject
and all are added/configured through inspectors in the editor UI.
public class MyModifier {
public MyModifier (MyDataObject myDataObject) { ... }
}
public class MyObjectCreator {
public MyObjectCreator(MyDataObject myDataObject, ModifierStack modifierStack) {
...
modifierStack.StackComplete += OnStackComplete();
}
}
In My OnStackComplete
event handler I am attempting to execute functions against GSDRoadSystem
. I say "attempt" because I haven't been able to figure out how to wire everything up to be injected, short of rewriting large portions of the Mapbox code simply to decorate everything with [Inject]
, something I'm reluctant to do given the SDK is still in heavy development.
The main issue seems to be that MyModifier
isn't having MyDataObject
injected, I'm guessing because Mapbox/Unity is controlling the lifecycle (due to configuration through inspectors/editor), but I don't know how to get around or work with that through Zenject.
My other option is to mess around with the Unity messaging system, and passing the vector list in the message to MyObjectCreator
which would locate the appropriate GSDRoadSystem
through the Unity provided service locators. Not ideal, but given this is a one-time setup and the RoadArchitect processing is going to dwarf any extra time or memory that might take I'm okay with it, even if it is a bit inelegant, although I'd rather learn how to get Zenject to wire things up, if that is at all possible (maybe it isn't because of how Mapbox built things).
I do have a fairly extensive background working with DI (Autofac, Ninject, poor-man's, etc.) but this is my first foray into Unity3d. It's possible I'm allowing Unity to cloud things and the solution is obvious, but I'm not seeing it right now.
For objects that are not created by Zenject and are not in the initial scene, you need to manually inject them yourself. You can do this by first injecting DiContainer into one of your classes and then calling DiContainer.Inject
or DiContainer.InjectGameObject
on the object that was created by third party code.