Consciousness Videos

Unity Tips – Observer pattern for Updating UI



DSU Software Community

Game Programming, Unity Tips – Observer pattern for Updating UI.
https://github.com/GP101/UnderstandingUnity/tree/master/UnityUiMvcPattern/New%20Unity%202018%20Project%20-%20UI%20observer%20pattern02%20with%20polling

When we update the UI widgets, they generally access the UI component directly when it required anywhere. But do not access UI widget from any other non-UI components. Instead, UI components can access other components. But to do that, there must a way to know when do UI components need to update.
For that purpose, we can apply the observer pattern. We can maintain the simple data stamp for UI data, then each frame, just check the data time stamp, then when it was modified, we can update the UI widgets.

In Unity official ‘roll a ball’ tutorial, they didn’t apply the observer pattern.
In this demo, we show how to modify existing UI to apply the observer pattern.

Source

Similar Posts

WP2Social Auto Publish Powered By : XYZScripts.com