You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using UnityEngine.SceneManagement;
  5. using Logger = IPA.Logging.Logger;
  6. namespace IPA.Loader.Composite
  7. {
  8. internal class CompositeBSPlugin
  9. {
  10. private readonly IEnumerable<PluginExecutor> plugins;
  11. private delegate void CompositeCall(PluginExecutor plugin);
  12. public CompositeBSPlugin(IEnumerable<PluginExecutor> plugins)
  13. {
  14. this.plugins = plugins;
  15. }
  16. private void Invoke(CompositeCall callback, [CallerMemberName] string method = "")
  17. {
  18. foreach (var plugin in plugins)
  19. {
  20. try
  21. {
  22. if (plugin != null)
  23. callback(plugin);
  24. }
  25. catch (Exception ex)
  26. {
  27. Logger.log.Error($"{plugin.Metadata.Name} {method}: {ex}");
  28. }
  29. }
  30. }
  31. public void OnEnable()
  32. => Invoke(plugin => plugin.Enable());
  33. public void OnApplicationQuit() // do something useful with the Task that Disable gives us
  34. => Invoke(plugin => plugin.Disable());
  35. public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
  36. { }//=> Invoke(plugin => plugin.Plugin.OnSceneLoaded(scene, sceneMode));
  37. public void OnSceneUnloaded(Scene scene)
  38. { }//=> Invoke(plugin => plugin.Plugin.OnSceneUnloaded(scene));
  39. public void OnActiveSceneChanged(Scene prevScene, Scene nextScene)
  40. { }//=> Invoke(plugin => plugin.Plugin.OnActiveSceneChanged(prevScene, nextScene));
  41. public void OnUpdate()
  42. { }/*=> Invoke(plugin =>
  43. {
  44. if (plugin.Plugin is IEnhancedPlugin saberPlugin)
  45. saberPlugin.OnUpdate();
  46. });*/
  47. public void OnFixedUpdate()
  48. { }/*=> Invoke(plugin => {
  49. if (plugin.Plugin is IEnhancedPlugin saberPlugin)
  50. saberPlugin.OnFixedUpdate();
  51. });*/
  52. public void OnLateUpdate()
  53. { }/*=> Invoke(plugin => {
  54. if (plugin.Plugin is IEnhancedPlugin saberPlugin)
  55. saberPlugin.OnLateUpdate();
  56. });*/
  57. }
  58. }