Easily Manage the State of Your UI With This Pattern to Save Yourself Headaches




Published: 23 Nov 2021

On your UI do you have references from random scripts to other scripts to manage which one should be showing? Are you setting up the state of the next page in code where your UI scripts are tightly coupled?


In this video I'll show you the pattern I've been using for the last 6 years to remove that mess and separate the concerns of UI Sounds and Animations into a "Page" Monobehaviour that is controlled by the MenuController. With these two simple, but powerful scripts you can easily manage your UI page state in a simple, predictable, and powerful way.


At the end of this video you'll have:

A structured, proven paradigm to approach to managing pages on your UI

An easy way to decouple your animation and sound playing from your UI logic.

A tool to intelligently control what needs to be set up, when it needs to be set up, instead of having that hard coded in your scripts.


๐Ÿ‘จโ€๐Ÿ’ป As always, all code from this video is available on GitHub: https://github.com/llamacademy/menu-controller


๐Ÿท๏ธSave 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: https://www.jetbrains.com/store/?section=personal&billing=yearly


๐Ÿงก Believe in LlamAcademy's mission and have received value from the videos? Here's how you can show your support:

๐ŸŒŸ Patreon: https://www.patreon.com/llamacademy

๐ŸŒŸ YouTube Member: https://www.youtube.com/channel/UCnWm6pMD38R1E2vCAByGb6w/join or click the Join button on any video

๐Ÿ“š Take my Unity ShaderGraph Course:

https://www.gamedev.tv/p/unity-shader-graph?affcode=45216_kuvg0bp7

๐Ÿ‘• Get yourself some LlamAcademy merch: https://llamacademy.myspreadshop.com/

๐Ÿ’ธ Use my Affiliate Link for Humble Bundles https://humblebundleinc.sjv.io/9g4ak4

๐Ÿ’ธ Publisher Sale! 50% OFF an entire publisher's Assets! Publisher changes weekly! https://assetstore.unity.com/publisher-sale?aid=1101l9QvC (affiliate)

๐Ÿ’ธ Save up to 50% on NEW Assets: https://assetstore.unity.com/?new_sale=true&orderBy=1&aid=1101l9QvC (affiliate)


Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.


Chapters

00:00 Introduction - What to Expect

03:24 Scene Overview

03:44 Page.cs - Initial Setup, Entry and Exits

06:50 AnimationHelper.cs - Page Animations

07:43 Page.cs - Audio Management

09:22 Page.cs - Hooking up the rest of the animations

10:40 Page.cs - Fixing copy/paste issues

11:02 MenuController.cs - Pushing and Popping Pages

14:10 Hooking it all up

16:50 PlayerInput - Escape to go back

17:46 Demo

18:58 Page.cs - Adding Events Before/After Animations

19:21 Explanation of Event Order

19:45 Page.cs - Calling Events

20:21 Setting up Events in the Editor

20:57 Demo - Events and Exit On Page Push

Connect on Social Media

Some links may be affiliate links, which at no additional cost to you, gives LlamAcademy a small portion of the purchase.