Skip to content

Conversation

CristianRos
Copy link
Contributor

This PR addresses part of #95. Reflex isn't integrated into UniState yet. This PR wants to add that feature.

  • Gives state machines the container context so they can resolve states with Reflex.
  • Adds Reflex.ContainerBuilder extensions allowing to use:
    • builder.AddStateMachine<TInterface, TStateMachine>();
    • builder.AddState<TInterface, TState>();
    • builder.AddState<TInterface>(Type stateType);
    • builder.AddState(Type stateType);
    • AddSingletonState and AddSingletonStateMachine variants are also available for singleton registrations.
  • Ports the Dice Game tutorial into new Reflex scene: ReflexDiceGameScene.unity

This is the API:

  builder.AddStateMachine<IStateMachine, StateMachine>();
  
  builder.AddState<IState<EmptyPayload>, LostState>();
  builder.AddState<IState<EmptyPayload>>(typeof(LostState));
  builder.AddState(typeof(LostState));
  
  builder.AddState<IOtherState, LostState>();         // Errors at compile time
  // Should be builder.AddState<IOtherState, OtherStateImplementation>();
  
  builder.AddState<IOtherState>(typeof(LostState));   // Errors at runtime
  // Should be builder.AddState<IOtherState>(typeof(OtherStateImplementation));
  
  builder.AddState<IMyState, MyState>();

Additional notes:

Reflex needs to add an Assets/Resources folder to properly work where ReflexSettings ScriptableObject lives, I also made a ProjectScope prefab that includes the ProjectScope script and added it to the settings.

This is because Reflex uses the ReflexSettings to load all global state through every ProjectScope passed to it, allowing a cleaner separation of concerns if needed.

I also added Reflex to the UniStateTests.Common assembly definition references as I had some errors that required that but I'm not sure why.

Copy link
Owner

@bazyleu bazyleu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for PR 👍

  • I left some comments they should be resolved before merging.
  • Please note that the existing code use spaces as separators. You use tabs. Please use spaces like other code in this repo.
  • Since we don't have any tests for Reflex integration yet, before merging I'd like to make sure that the experimental integration basically works on il2cpp. Could you check on real build (Android with il2cpp or iOS or Windows il2cpp) that ReflexDiceGameSene is working on build (checking can be done simply by reviewing logs)

@CristianRos
Copy link
Contributor Author

I didn't realize my editor made a mess off of the formatting haha, it should be solved now 😅

@CristianRos
Copy link
Contributor Author

I tested ReflexDiceGameScene on an Android IL2CPP build with Android Studio. I've reviewed logcat output and the logs show Reflex initializing correctly and the game functionality is working as expected. 👍

I also tried to make a Windows IL2CPP build and it gave me some errors, I believe they are related to some missconfiguration on my end with Visual Studio. I'll look into it separately but I'm possitive the Android IL2CPP test confirms the core integration.

@bazyleu bazyleu self-requested a review July 25, 2025 19:22
@bazyleu bazyleu merged commit 475b4d5 into bazyleu:main Jul 25, 2025
@bazyleu bazyleu mentioned this pull request Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants