コード例 #1
0
        // Create additional model generators from plugins using reflection.
        public void CreateAdditionalModelGenerators(MyCubeSize gridSizeEnum)
        {
            Assembly[] assemblies = new Assembly[] {
                Assembly.GetExecutingAssembly(),
                       MyPlugins.GameAssembly,
                       MyPlugins.UserAssembly,
            };

            foreach (var assembly in assemblies)
            {
                if (assembly == null)
                {
                    continue;
                }

                // Lookup
                Type lookupType = typeof(IMyBlockAdditionalModelGenerator);
                IEnumerable <Type> lookupTypes = assembly.GetTypes().Where(
                    t => lookupType.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract);

                // Create instances
                foreach (var type in lookupTypes)
                {
                    IMyBlockAdditionalModelGenerator generator = Activator.CreateInstance(type) as IMyBlockAdditionalModelGenerator;
                    if (generator.Initialize(m_grid, gridSizeEnum))
                    {
                        AdditionalModelGenerators.Add(generator);
                    }
                    else
                    {
                        generator.Close();
                    }
                }
            }
        }
コード例 #2
0
 public void CreateAdditionalModelGenerators(MyCubeSize gridSizeEnum)
 {
     Assembly[] first = new Assembly[] { Assembly.GetExecutingAssembly(), MyPlugins.GameAssembly, MyPlugins.SandboxAssembly };
     if (MyPlugins.UserAssemblies != null)
     {
         first = first.Union <Assembly>(MyPlugins.UserAssemblies).ToArray <Assembly>();
     }
     foreach (Assembly assembly in first)
     {
         if (assembly != null)
         {
             Type lookupType = typeof(IMyBlockAdditionalModelGenerator);
             using (IEnumerator <Type> enumerator = (from t in assembly.GetTypes()
                                                     where lookupType.IsAssignableFrom(t) && (t.IsClass && !t.IsAbstract)
                                                     select t).GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     IMyBlockAdditionalModelGenerator item = Activator.CreateInstance(enumerator.Current) as IMyBlockAdditionalModelGenerator;
                     if (item.Initialize(this.m_grid, gridSizeEnum))
                     {
                         this.AdditionalModelGenerators.Add(item);
                         continue;
                     }
                     item.Close();
                 }
             }
         }
     }
 }