Beispiel #1
0
 private bool DescriptorIsLoaded(IUserPluginDescriptor descriptor)
 {
     foreach (IUserPlugin plugin in Plugins)
     {
         if (plugin.Descriptor == descriptor)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #2
0
        public bool LoadPlugin(IUserPluginDescriptor descriptor, FSGameLoop game)
        {
            if (DescriptorIsLoaded(descriptor))
            {
                return(false);
            }

            if (!File.Exists(descriptor.EntryFilePath(PluginExtension)))
            {
                return(false);
            }

            if (descriptor.Dependencies != null && descriptor.Dependencies.Length > 0)
            {
                LogSystem.PrintColor(descriptor.Name + " has " + descriptor.Dependencies.Length + " dependencies", UnityEngine.Color.cyan);
                foreach (string s in descriptor.Dependencies)
                {
                    LogSystem.PrintColor("> " + s, UnityEngine.Color.cyan);
                    var dependency = FindDescriptor(s);
                    if (dependency == null || !LoadPlugin(dependency, game))
                    {
                        var couldntFind = string.Format("Couldn't load plugin: {0}, missing dependency: {1}",
                                                        descriptor.Name,
                                                        s);
                        LogSystem.PrintWarning(couldntFind);
                        return(false);
                    }
                }
            }

            var plugin = _LoadPlugin(descriptor, game);

            if (plugin != null)
            {
                Plugins.Add(plugin);

                var successMessage = '[' + descriptor.Space.ToString() + ']'
                                     + "Plugin loaded: "
                                     + descriptor.Name
                                     + " ("
                                     + descriptor.Version
                                     + ") by "
                                     + descriptor.Author
                                     + " ["
                                     + PluginExtension
                                     + ']';

                LogSystem.PrintColor(successMessage, UnityEngine.Color.green);

                return(true);
            }

            return(false);
        }
Beispiel #3
0
        protected override IUserPlugin _LoadPlugin(IUserPluginDescriptor descriptor, FSGameLoop game)
        {
            try
            {
                var plugin = new LuaPlugin(descriptor);
                plugin.Game      = game;
                plugin.LogSystem = LogSystem;
                plugin.Load();
                return(plugin);
            }
            catch (System.Exception e)
            {
                LogSystem?.PrintWarning(e.ToString());
            }

            return(null);
        }
Beispiel #4
0
 protected abstract IUserPlugin _LoadPlugin(IUserPluginDescriptor descriptor, FSGameLoop game);
Beispiel #5
0
 public LuaPlugin(IUserPluginDescriptor descriptor)
     : base(descriptor)
 {
 }
Beispiel #6
0
        // METHODS

        public BaseUserPlugin(IUserPluginDescriptor descriptor)
        {
            Descriptor = descriptor;
            Config     = new ConfigManager(this);
        }