BepInComponent.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6. namespace BepInEx
  7. {
  8. //Adapted from https://github.com/Eusth/IPA/blob/0df8b1ecb87fdfc9e169365cb4a8fd5a909a2ad6/IllusionInjector/PluginComponent.cs
  9. public class BepInComponent : MonoBehaviour
  10. {
  11. private bool quitting = false;
  12. public static BepInComponent Create()
  13. {
  14. return new GameObject("BepInEx_Manager").AddComponent<BepInComponent>();
  15. }
  16. void Awake()
  17. {
  18. DontDestroyOnLoad(gameObject);
  19. }
  20. void Start()
  21. {
  22. Console.WriteLine("Component ready");
  23. }
  24. void Update()
  25. {
  26. //Console.WriteLine("Update");
  27. }
  28. void LateUpdate()
  29. {
  30. }
  31. void FixedUpdate()
  32. {
  33. }
  34. void OnDestroy()
  35. {
  36. if (!quitting)
  37. {
  38. Create();
  39. }
  40. }
  41. void OnApplicationQuit()
  42. {
  43. quitting = true;
  44. }
  45. }
  46. }