Beispiel #1
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 #2
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);
        }