예제 #1
0
        /// <summary>
        /// Load a menu into memory by instantiating an instance of it's view
        /// and populating it with the data from the model passed in.
        /// </summary>
        /// <typeparam name="T">The type of menu to load.</typeparam>
        /// <param name="menu">The menu's model.</param>
        public void LoadMenu <T>(T menu) where T : class, IMenu
        {
            if (menuPresenter != null)
            {
                menuPresenter.Unload();
            }

            MenuPresenterAttribute presenterAttribute = typeof(T).GetCustomAttribute <MenuPresenterAttribute>();

            //Easy. We know what kind of presenter to use.
            if (presenterAttribute != null)
            {
                //Is the current one what we need?
                if ((menuPresenter?.GetType() ?? null) != presenterAttribute.Type)
                {
                    menuPresenter = Activator.CreateInstance(presenterAttribute.Type, this, commandConsole, configContainer) as IMenuPresenter;
                }
            }
            else
            {
                throw new Exception(string.Format("No menu presenter attribute found on menu of type: {0}", typeof(T)));
            }

            menuPresenter.Load(menuContainer, menu);
        }
예제 #2
0
 /// <summary>
 /// Destroy any existing menus right before switching scenes.
 /// This will handle calling their release of resources.
 /// </summary>
 /// <param name="scene"></param>
 public override void OnSceneDestroyed(Scene scene)
 {
     menuPresenter?.Unload();
 }