How can I Instantiate a Gameobject at runtime like zenject's sub container #473
-
like title, I have CharacterView (MonoBehaviour)、CharacterMoveHandler (plain C#) and the handler need the view. I only thought a way that I create CharacterPresenter (plain C#) and CharacterRepository (plain C#), when instantiate a character I will put view and handler in repository, and then presenter get all character from repository and run all handlers' tick Is there have more easy way to do this? |
Beta Was this translation helpful? Give feedback.
Answered by
SimonNordon4
Apr 8, 2023
Replies: 1 comment 1 reply
-
[SerializedField]
private CharacterView characterPrefab;
builder.RegisterFactory<CharacterMoveHandler >(container =>
{
return () =>
{
var CharacterView = container.Instantiate(characterPrefab);
var moveHandler = new MoveHandler(CharacterView);
};
}, Lifetime.Scoped); Something like this should work. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cowbear6598
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like this should work.