Пример #1
0
        private void LoadPlugins()
        {
            m_plugineffects = new Dictionary <string, ITerrainEffect>();
            string plugineffectsPath = "Terrain";

            // Load the files in the Terrain/ dir
            if (!Directory.Exists(plugineffectsPath))
            {
                return;
            }

            string[] files = Directory.GetFiles(plugineffectsPath);
            foreach (string file in files)
            {
                m_log.Info("Loading effects in " + file);
                try
                {
                    Assembly library = Assembly.LoadFrom(file);
                    foreach (Type pluginType in library.GetTypes())
                    {
                        try
                        {
                            if (pluginType.IsAbstract || pluginType.IsNotPublic)
                            {
                                continue;
                            }

                            string typeName = pluginType.Name;

                            if (pluginType.GetInterface("ITerrainEffect", false) != null)
                            {
                                ITerrainEffect terEffect = (ITerrainEffect)Activator.CreateInstance(library.GetType(pluginType.ToString()));

                                InstallPlugin(typeName, terEffect);
                            }
                            else if (pluginType.GetInterface("ITerrainLoader", false) != null)
                            {
                                ITerrainLoader terLoader = (ITerrainLoader)Activator.CreateInstance(library.GetType(pluginType.ToString()));
                                m_loaders[terLoader.FileExtension] = terLoader;
                                m_log.Info("L ... " + typeName);
                            }
                        }
                        catch (AmbiguousMatchException)
                        {
                        }
                    }
                }
                catch (BadImageFormatException)
                {
                }
            }
        }
Пример #2
0
 public void InstallPlugin(string pluginName, ITerrainEffect effect)
 {
     lock (m_plugineffects)
     {
         if (!m_plugineffects.ContainsKey(pluginName))
         {
             m_plugineffects.Add(pluginName, effect);
             m_log.Info("E ... " + pluginName);
         }
         else
         {
             m_plugineffects[pluginName] = effect;
             m_log.Warn("E ... " + pluginName + " (Replaced)");
         }
     }
 }
Пример #3
0
 public void InstallPlugin(string pluginName, ITerrainEffect effect)
 {
     lock (m_plugineffects)
     {
         if (!m_plugineffects.ContainsKey(pluginName))
         {
             m_plugineffects.Add(pluginName, effect);
             //m_log.Info("E ... " + pluginName);
         }
         else
         {
             m_plugineffects[pluginName] = effect;
             //m_log.Warn("E ... " + pluginName + " (Replaced)");
         }
     }
 }