A fork of Eusth's IPA
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.

75 lines
1.5KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using UnityEngine;
  5. namespace IllusionInjector
  6. {
  7. public class PluginComponent : MonoBehaviour
  8. {
  9. private CompositePlugin plugins;
  10. private bool freshlyLoaded = false;
  11. private bool quitting = false;
  12. public static PluginComponent Create()
  13. {
  14. return new GameObject("IPA_PluginManager").AddComponent<PluginComponent>();
  15. }
  16. void Awake()
  17. {
  18. DontDestroyOnLoad(gameObject);
  19. plugins = new CompositePlugin(PluginManager.Plugins);
  20. plugins.OnApplicationStart();
  21. }
  22. void Start()
  23. {
  24. OnLevelWasLoaded(Application.loadedLevel);
  25. }
  26. void Update()
  27. {
  28. if (freshlyLoaded)
  29. {
  30. freshlyLoaded = false;
  31. plugins.OnLevelWasInitialized(Application.loadedLevel);
  32. }
  33. plugins.OnUpdate();
  34. }
  35. void LateUpdate()
  36. {
  37. plugins.OnLateUpdate();
  38. }
  39. void FixedUpdate()
  40. {
  41. plugins.OnFixedUpdate();
  42. }
  43. void OnDestroy()
  44. {
  45. if (!quitting)
  46. {
  47. Create();
  48. }
  49. }
  50. void OnApplicationQuit()
  51. {
  52. plugins.OnApplicationQuit();
  53. quitting = true;
  54. }
  55. void OnLevelWasLoaded(int level)
  56. {
  57. plugins.OnLevelWasLoaded(level);
  58. freshlyLoaded = true;
  59. }
  60. }
  61. }