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.

95 lines
2.7 KiB

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