BaseUnityPlugin.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. {
  23. Info = new PluginInfo
  24. {
  25. Metadata = metadata,
  26. Instance = this,
  27. Dependencies = MetadataHelper.GetDependencies(GetType()),
  28. Processes = MetadataHelper.GetAttributes<BepInProcess>(GetType()),
  29. Location = GetType().Assembly.Location
  30. };
  31. }
  32. Logger = Logging.Logger.CreateLogSource(metadata.Name);
  33. Config = new ConfigFile(Utility.CombinePaths(Paths.ConfigPath, metadata.GUID + ".cfg"), false);
  34. }
  35. }
  36. }