Beispiel #1
0
        public static void LoadAssemble(string assemblyName)
        {
            var load = Assembly.Load(assemblyName).GetTypes().Where(x =>
                                                                    x.IsClass && x.IsSubclassOf(typeof(GameSceneBase))).ToArray();

            foreach (var type in load)
            {
                var constructors    = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
                var voidConstructor = constructors.FirstOrDefault(x => x.GetParameters().Length == 0);
                if (voidConstructor != null)
                {
                    GameScenes.Add(type, (GameSceneBase)Activator.CreateInstance(type));
                }
                else
                {
                    var firstConstructor = constructors.FirstOrDefault();
                    if (firstConstructor != null)
                    {
                        var parameters = firstConstructor.GetParameters();
                        var resolve    = AutoFacFactory.TypesResolve(parameters.Select(x => x.ParameterType).ToArray());
                        GameScenes.Add(type, (GameSceneBase)firstConstructor.Invoke(resolve));
                    }
                }
            }
        }
Beispiel #2
0
 public static void LoadContent(ContentManager contentManager)
 {
     AutoFacFactory.Build();
     _contentManager = contentManager;
     LoadAssemble(Assembly.GetExecutingAssembly().FullName);
     _currentScene = GameScenes[typeof(MainMenu)];
     _scene        = typeof(MainMenu);
     _currentScene.LoadContent(contentManager);
 }