apkd/Medicine

Work at editor time?

Opened this issue · 4 comments

I find myself wanting injection to happen to some extent during edit mode, for setting things up correctly in OnValidate(), or just for use in editor scripts.

[Inject] public BoxCollider Box { get; }

void OnValidate()
{
	Box.isTrigger = true;
}

I do understand why this doesn't currently work, and I can't think of any super elegant solution off the top of my head.
I thought I'd mention it as something that'd be desirable on the off-chance there's a great way to support this that doesn't create loads of edge cases.

Possibly something that makes regular injection behave lazily at editor time?
Would have to be optional and enabled by the user somehow.

In terms of MonoBehaviour dependencies, that would make SerializeField completely obsolete in my projects. An additional LazyInEditor property would be great.

apkd commented

Hey there, thanks for getting in touch. This would be a great feature to add. There's several ways it could be implemented. I think the most likely route would be to have the code compile slightly differently depending on whether the game is compiling in editor or making a build. This would let us keep optimal performance in player builds, by eliminating unnecessary Application.isPlaying checks. I'd rather avoid adding new attributes because I kinda think we already have too many 😅

I'd love to add this feature but I'm loaded with work at the moment, so I can't give you an ETA. Obviously, pull requests are welcome.

I think the most likely route would be to have the code compile slightly differently depending on whether the game is compiling in editor or making a build. This would let us keep optimal performance in player builds, by eliminating unnecessary Application.isPlaying checks. I'd rather avoid adding new attributes because I kinda think we already have too many 😅

This does sound good, my only fear is encountering different behaviour in editor vs in builds, could be hard to debug if someone isn't aware of this feature.

I might investigate it myself at some point, but the main project is demanding most of my attention at the moment.
Let me know if some indie sized sponsorship would help! Really appreciate your work.