Make most or all gameObjects in the scene should be prefabs, separated into logical features. This allows the team to work in parallel without merge conflicts on the scene file.
Static vs Singleton vs IService?
- If you are writing pure functions with no data, use a static class with static methods.
- If you have data, and your component is part of the an app, use a
MonoBehaviourthat implementsIService, and useServiceLocator.Get<MyService>to retrieve it. - If you have data, and your component is more generic (e.g. a reusable package), use a singleton. Note, singleton
MonoBehavioursare quite difficult to implement correctly and efficiently.
UXML Bindings
UI binding is the act of taking a data source and applying it a user interface.
Key principles:
- Bindings should be simple and automatic.
- You should be able to view and edit all data in the editor for easy debugging.
To implement UI bindings, we use three classes:
Property<T>- Some data + a changed event. These can be viewed and edited in the Unity editor.Derived<T, W>- Transforms an IProperty into an IProperty.Bindings- a helper class which makes it easy to take data from an IProperty and apply it to a UXML element, or vice versa.>
Follow utility-first patterns. Essentially, keep USS classes very small and single-purpose.
Most styles you need will are in Tailwind.uss (inspired by tailwindcss classes) or HyperStyle.uss. If you need a one-off style, create a USS file with the same name as your UXML.
The recommended workflow when building UI is to edit UXML/USS files directly and view the results in the game view. Using UI bindings, you should be able to inject data into your UI templates and see the results immediately.