Skip to main content
3 of 3
Improve answer. Clarify explanation.
Candid Moon _Max_
  • 2.9k
  • 1
  • 22
  • 39

General

There are many solutions for this approach. Mainly it would be just learning how to make every system reusable and modular. There are already a lot of solutions/patterns on the internet like: Micro-Services, Module Pattern...

After a bit of time and experience you would understand how to make everything modular and come up with your own solutions that work for your needs the best.


Specific

I am going to describe the main system that I am using for UI.

I have a system that makes use of MVC pattern. I call it OMCVO - Object Model Controller View Output.

In Objects[aka Components] I have data objects [Models] that are sent to a Controller which decides to what view to assign the data. Some views that I have are Singletons, I usually don't use them through Controller.

[Some of the method naming isn't the actual names of methods in system, they are just to show an example].

Basically, I've split the Data, Output and Behaviour. The workflow is very simple:

  • I create some DataType which I load with information and send this data to controller [Controller.Take(data)].
  • Some View that accepts this DataType through Controller does calculations and displays them to Output.
  • Some Data is linked to views for real-time changes.
  • Views have standard API like Open, Close, Show, Hide, animations, relations to one another and other similar stuff.

Technical implementation is very tedious and complicated, so I won't go into it.


Part of old asnwer that some people might find useful

But for this purpose I would have different Views that are Models and Controllers of itself.

For example, Confirmation Window - it has a method public void ApplyConfirmation(UnityAction buttonConfirmationAction, string text); - and when you click on exit button wich has some method applied to if from MenuManager or whatever which has a call to Confirmation Window.

ConfirmationWindow.Instance.ApplyConfirmation(delegate { this.ExitGame(this.SaveDataBeforeExit) }, "Do you really want to exit?");

Now confirmation window pops up. ApplyConfirmation in my case has an "Yes" button which is asigned any method to be called when it's pressed and a text that changes the text on pop up window.

If you are sure that you are going to have only 1 UI element of that behavior and you can reuse it - you can go ahead and make it a Singleton to be able to call it easily from any class like UIElementClassName.Instance.PublicMethodToCall();

Hope you got the idea from it.


For a simpler and better described solution look at my other answer.

Candid Moon _Max_
  • 2.9k
  • 1
  • 22
  • 39