Add Lifecycle generator; Singleton/Dependency stop owning Awake/Start#9
Merged
Conversation
Events were silently dropped by the formatter and by the auto-include candidate check, so a public event on a [Singleton] class never appeared on its generated interface. Format IEventSymbol as `event Type Name;`, accept events in auto-mode, widen [SingletonInclude] / [SingletonIgnore] to AttributeTargets.Event, and add a demo CountChanged event with a test that subscribes through the interface.
The tests exercise [Dependency] resolution and the singleton lifecycle, which only run in PlayMode. Drop the EditMode-only test runner reference and Editor platform restriction so the [UnityTest] coroutines that yield a frame for Start() can run.
… owning Awake/Start New [Awake]/[Start]/[OnEnable]/[OnDisable]/[Update]/[FixedUpdate]/[LateUpdate]/[OnDestroy] attributes mark MonoBehaviour methods to be invoked from a single generated dispatcher per lifecycle phase, ordered by an optional int Order arg (source order on tie). [Singleton] and [Dependency] now contribute private SingletonAwake()/DependencyStart() helpers instead of owning Awake/Start themselves, so multiple features can cooperate on the same MonoBehaviour without colliding. The Singleton helper returns false on a duplicate (after Destroy) so the dispatcher short-circuits before any user [Awake] or OnAwake runs on the doomed instance. Backwards-compatible: the Awake/Start dispatchers still call (and declare) the OnAwake()/OnStart() partial hooks. ERG0003/ERG0103 retired in favor of the unified ERG0203, which suggests adding a [Awake]/[Start]/etc. method.
# Conflicts: # src/generators-unity/Packages/games.engine-room.generators/Runtime/Plugins/EngineRoom.Generators.dll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[Awake]/[Start]/[OnEnable]/[OnDisable]/[Update]/[FixedUpdate]/[LateUpdate]/[OnDestroy]attributes mark MonoBehaviour methods that the newLifecycleGeneratorinvokes from a single dispatcher per phase. Optionalint orderargument sorts methods (source order on tie); the analyzer warns on duplicate explicit orders.[Singleton]and[Dependency]no longer emitAwake()/Start()directly. They emitprivate bool SingletonAwake()andprivate void DependencyStart()helpers that the lifecycle dispatcher calls first. The Singleton helper returnsfalseon a duplicate (afterDestroy(gameObject)) so the dispatcher short-circuits before any user[Awake]/OnAwakeruns on the doomed instance.AwakeandStartdispatchers still call and declare theOnAwake()/OnStart()partial hooks, so existing code keeps working unchanged.Test plan
dotnet build src/generators-src/EngineRoom.Generators.sln -c Release— cleanEngineRoom.Demo.Lifecycle.Tests(7 cases covering one-shot callbacks, Update/LateUpdate/FixedUpdate cadence, explicit ordering, Singleton+Awake interaction, duplicate-singleton short-circuit) + existingEngineRoom.Demo.Singletons.Tests— all greentests/generators-tests-2022-3-62/in Unity 2022.3.62 and confirm package still loadsvoid Awake() {}to a[Singleton]class — it should suggest marking a method with[Awake]