31
NGUI 3 Support / Re: Best practices for Managers
« on: March 12, 2014, 04:03:43 AM »My approach is:
1. Create a class that extends from Monobehaviour and make it a Singleton.
2. Create public references for all my interface "windows", etc... So I can drag them.
3. Create wrappers from them so it's easier to use them.
I like this approach because it's really easy to use and because for the main logic I like to mix it with PlayMaker SendMessage actions (it's easier to mantain when you take a project that it's not yours or you haven't look at it for several months). Example:
Intro --> MainMenu --> OptionMenu --> Return to MainMenu --> Play... (An so on...)
With a PlayMaker FSM it's really visual and easy to add later for example, an intermediate window.
Quick example (I'm writing here so it can have compilation errors):
public class InterfaceManager : MonoBehaviour { private static InterfaceManager instance; public static InterfaceManager Instance { get { if (instance == null) { Debug.LogError("You must attach this script to a Monobehaviour. Also, don't call it from Awake"); } return instance; } } public MyWindow window; void Awake() { instance = this; } public void ShowMyWindow() { window.Show(); } public void HideMyWindow() { window.Hide(); } }
Hey, can you be more specific on how to use this approach? I'm having trouble understanding it. For example should I create a public variable for every window(game object) and attach a script to each window?
- public FirstWindow window1;
- public SecondWindow window2;
- ....
And where should the Hide() and Show() functions be? Thank you!