/// <summary>
        /// List of all screen instances.
        /// </summary>
        #region Events
        //public static event Action OnScreenLoading;
        //public static event Action OnAllScreensLoaded;
        //public static event Action OnUpdate;
        //public static event Action<SpriteBatch> OnDraw;
        //public static event Action OnResolutionChanged;
        #endregion

        /// <summary>
        /// Saves the given screen and takes a care about his updating, drawing, and changing resolution. Screens must be loaded in the right draw order (they are drawed in order in which they were added).
        /// </summary>
        internal static void LoadScreens()
        {
            // Get assemblies with MenuScreens
            var assembliesWithScreens = AppDomain.GetAssemblies().Where(a => a.GetCustomAttribute(typeof(GameLogicAssembly)) != null);

            // Get all types of subclasses of MenuScreen
            var types = assembliesWithScreens.SelectMany(a => a.DefinedTypes).Where(t => t.IsSubclassOf(typeof(MenuScreen))).ToList();

            Camera          = new Camera();
            _screens        = new Dictionary <Type, MenuScreen>();
            _orderedScreens = new List <MenuScreen>();

            MenuScreen mainScreen = null;

            // Create instances of all MenuScreens
            types.ForEach(t =>
            {
                MenuScreen screen = (MenuScreen)t.DeclaredConstructors.First().Invoke(new object[] { Camera });

                if (screen.GetType().GetTypeInfo().GetCustomAttribute(typeof(MainScreenAttribute)) != null)
                {
                    mainScreen = screen;
                }

                AddScreen(screen);
            });

            if (mainScreen == null)
            {
                throw new MissingMemberException("No MenuScreen has attribute MainScreenAttribute. Mark the MenuScreen, which should be showed as the first after start up, with the MainScreenAttribute attribute.");
            }
            mainScreen.Show();
            _screens.Values.ForEach(p => p.AllScreensLoaded());
        }
Exemple #2
0
 public void SetScreen(MenuScreen pScreen, bool pReset)
 {
     print("Setting screen to: " + pScreen.GetType().Name);
     _currentScreen = pScreen;
     if (pReset)
     {
         pScreen.ResetCall();
     }
 }
Exemple #3
0
 public Type GetActiveScreen()
 {
     for (int i = 0; i < this.m_Screens.Count; i++)
     {
         MenuScreen menuScreen = this.m_Screens[i];
         if (menuScreen != null && menuScreen.gameObject.activeSelf)
         {
             return(menuScreen.GetType());
         }
     }
     return(null);
 }
Exemple #4
0
 public bool IsChangingScreens()
 {
     if (this.m_ScreenToShow == null)
     {
         return(false);
     }
     for (int i = 0; i < this.m_Screens.Count; i++)
     {
         MenuScreen menuScreen = this.m_Screens[i];
         if (this.m_ScreenToShow == menuScreen.GetType())
         {
             return(menuScreen.gameObject.activeSelf);
         }
     }
     return(false);
 }
    private void Init()
    {
        GameObject gameObject = GameObject.Find("InGameMenu");

        DebugUtils.Assert(gameObject, true);
        for (int i = 0; i < gameObject.transform.childCount; i++)
        {
            GameObject gameObject2 = gameObject.transform.GetChild(i).gameObject;
            MenuScreen component   = gameObject2.GetComponent <MenuScreen>();
            if (component)
            {
                component.m_MenuInGameManager = this;
                component.Hide();
                this.m_Screens[component.GetType()] = component;
            }
        }
        this.m_OutlineCamera = GameObject.Find("OutlineCamera").GetComponent <Camera>();
        this.m_Initialized   = true;
    }
Exemple #6
0
 private void Awake()
 {
     _currentScreen = _startScreen;
     print("Currently in " + _currentScreen.GetType().Name);
 }
 private static void AddScreen(MenuScreen screen)
 {
     _screens.Add(screen.GetType(), screen);
     _orderedScreens.Add(screen);
     _orderedScreens.Sort((screen1, screen2) => screen1.DrawPriorities.CompareTo(screen2.DrawPriorities));
 }