A fork of Eusth's IPA
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

108 wiersze
2.4KB

  1. using System;
  2. using System.Collections.Generic;
  3. using IllusionPlugin;
  4. namespace IllusionInjector
  5. {
  6. public class CompositePlugin : IPlugin
  7. {
  8. private readonly IEnumerable<IPlugin> plugins;
  9. private delegate void CompositeCall(IPlugin plugin);
  10. public CompositePlugin(IEnumerable<IPlugin> plugins)
  11. {
  12. this.plugins = plugins;
  13. }
  14. public void OnApplicationStart()
  15. {
  16. Invoke(plugin => plugin.OnApplicationStart());
  17. }
  18. public void OnApplicationQuit()
  19. {
  20. Invoke(plugin => plugin.OnApplicationQuit());
  21. }
  22. public void OnLevelWasLoaded(int level)
  23. {
  24. foreach (var plugin in plugins)
  25. {
  26. try
  27. {
  28. plugin.OnLevelWasLoaded(level);
  29. }
  30. catch (Exception ex)
  31. {
  32. Console.WriteLine("{0}: {1}", plugin.Name, ex);
  33. }
  34. }
  35. }
  36. private void Invoke(CompositeCall callback)
  37. {
  38. foreach (var plugin in plugins)
  39. {
  40. try
  41. {
  42. callback(plugin);
  43. }
  44. catch (Exception ex)
  45. {
  46. Console.WriteLine("{0}: {1}", plugin.Name, ex);
  47. }
  48. }
  49. }
  50. public void OnLevelWasInitialized(int level)
  51. {
  52. foreach (var plugin in plugins)
  53. {
  54. try
  55. {
  56. plugin.OnLevelWasInitialized(level);
  57. }
  58. catch (Exception ex)
  59. {
  60. Console.WriteLine("{0}: {1}", plugin.Name, ex);
  61. }
  62. }
  63. }
  64. public void OnUpdate()
  65. {
  66. Invoke(plugin => plugin.OnUpdate());
  67. }
  68. public void OnFixedUpdate()
  69. {
  70. Invoke(plugin => plugin.OnFixedUpdate());
  71. }
  72. public string Name
  73. {
  74. get { throw new NotImplementedException(); }
  75. }
  76. public string Version
  77. {
  78. get { throw new NotImplementedException(); }
  79. }
  80. public void OnLateUpdate()
  81. {
  82. Invoke(plugin =>
  83. {
  84. if (plugin is IEnhancedPlugin)
  85. ((IEnhancedPlugin)plugin).OnLateUpdate();
  86. });
  87. }
  88. }
  89. }