BaseUnityPlugin.cs 920 B

12345678910111213141516171819202122232425262728293031323334
  1. using BepInEx.Bootstrap;
  2. using BepInEx.Configuration;
  3. using BepInEx.Contract;
  4. using BepInEx.Logging;
  5. using UnityEngine;
  6. namespace BepInEx
  7. {
  8. /// <summary>
  9. /// The base plugin type that is used by the BepInEx plugin loader.
  10. /// </summary>
  11. public abstract class BaseUnityPlugin : MonoBehaviour
  12. {
  13. protected ManualLogSource Logger { get; }
  14. protected ConfigFile Config { get; }
  15. protected PluginInfo Info { get; }
  16. protected BaseUnityPlugin()
  17. {
  18. var metadata = MetadataHelper.GetMetadata(this);
  19. if (Chainloader.PluginInfos.TryGetValue(metadata.GUID, out var info))
  20. Info = info;
  21. else
  22. Logging.Logger.LogDebug($"Plugin [{metadata.GUID}] wasn't registered through chainloader! PluginInfo property will not be initialized.");
  23. Logger = Logging.Logger.CreateLogSource(metadata.Name);
  24. Config = new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, metadata.GUID + ".cfg"), false);
  25. }
  26. }
  27. }