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.

112 lines
4.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. using System;
  2. namespace IPA
  3. {
  4. internal enum EdgeLifecycleType
  5. {
  6. Enable, Disable
  7. }
  8. internal interface IEdgeLifecycleAttribute
  9. {
  10. EdgeLifecycleType Type { get; }
  11. }
  12. // TODO: is there a better way to manage this mess?
  13. /// <summary>
  14. /// Indicates that the target method should be called when the plugin is enabled.
  15. /// </summary>
  16. /// <remarks>
  17. /// <para>
  18. /// This attribute is interchangable with <see cref="OnStartAttribute"/>, and is treated identically.
  19. /// They are seperate to allow plugin code to more clearly describe the intent of the methods.
  20. /// </para>
  21. /// <para>
  22. /// Typically, this will be used when the <see cref="RuntimeOptions"/> parameter of the plugins's
  23. /// <see cref="PluginAttribute"/> is <see cref="RuntimeOptions.DynamicInit"/>.
  24. /// </para>
  25. /// <para>
  26. /// The method marked by this attribute will always be called from the Unity main thread.
  27. /// </para>
  28. /// </remarks>
  29. /// <seealso cref="PluginAttribute"/>
  30. /// <seealso cref="OnStartAttribute"/>
  31. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
  32. public sealed class OnEnableAttribute : Attribute, IEdgeLifecycleAttribute
  33. {
  34. EdgeLifecycleType IEdgeLifecycleAttribute.Type => EdgeLifecycleType.Enable;
  35. }
  36. /// <summary>
  37. /// Indicates that the target method should be called when the game starts.
  38. /// </summary>
  39. /// <remarks>
  40. /// <para>
  41. /// This attribute is interchangable with <see cref="OnEnableAttribute"/>, and is treated identically.
  42. /// They are seperate to allow plugin code to more clearly describe the intent of the methods.
  43. /// </para>
  44. /// <para>
  45. /// Typically, this will be used when the <see cref="RuntimeOptions"/> parameter of the plugins's
  46. /// <see cref="PluginAttribute"/> is <see cref="RuntimeOptions.SingleStartInit"/>.
  47. /// </para>
  48. /// <para>
  49. /// The method marked by this attribute will always be called from the Unity main thread.
  50. /// </para>
  51. /// </remarks>
  52. /// <seealso cref="PluginAttribute"/>
  53. /// <seealso cref="OnEnableAttribute"/>
  54. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
  55. public sealed class OnStartAttribute : Attribute, IEdgeLifecycleAttribute
  56. {
  57. EdgeLifecycleType IEdgeLifecycleAttribute.Type => EdgeLifecycleType.Enable;
  58. }
  59. /// <summary>
  60. /// Indicates that the target method should be called when the plugin is disabled.
  61. /// </summary>
  62. /// <remarks>
  63. /// <para>
  64. /// This attribute is interchangable with <see cref="OnExitAttribute"/>, and is treated identically.
  65. /// They are seperate to allow plugin code to more clearly describe the intent of the methods.
  66. /// </para>
  67. /// <para>
  68. /// Typically, this will be used when the <see cref="RuntimeOptions"/> parameter of the plugins's
  69. /// <see cref="PluginAttribute"/> is <see cref="RuntimeOptions.DynamicInit"/>.
  70. /// </para>
  71. /// <para>
  72. /// The method marked by this attribute will always be called from the Unity main thread.
  73. /// </para>
  74. /// </remarks>
  75. /// <seealso cref="PluginAttribute"/>
  76. /// <seealso cref="OnExitAttribute"/>
  77. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
  78. public sealed class OnDisableAttribute : Attribute, IEdgeLifecycleAttribute
  79. {
  80. EdgeLifecycleType IEdgeLifecycleAttribute.Type => EdgeLifecycleType.Disable;
  81. }
  82. /// <summary>
  83. /// Indicates that the target method should be called when the game exits.
  84. /// </summary>
  85. /// <remarks>
  86. /// <para>
  87. /// This attribute is interchangable with <see cref="OnDisableAttribute"/>, and is treated identically.
  88. /// They are seperate to allow plugin code to more clearly describe the intent of the methods.
  89. /// </para>
  90. /// <para>
  91. /// Typically, this will be used when the <see cref="RuntimeOptions"/> parameter of the plugins's
  92. /// <see cref="PluginAttribute"/> is <see cref="RuntimeOptions.SingleStartInit"/>.
  93. /// </para>
  94. /// <para>
  95. /// The method marked by this attribute will always be called from the Unity main thread.
  96. /// </para>
  97. /// </remarks>
  98. /// <seealso cref="PluginAttribute"/>
  99. /// <seealso cref="OnDisableAttribute"/>
  100. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
  101. public sealed class OnExitAttribute : Attribute, IEdgeLifecycleAttribute
  102. {
  103. EdgeLifecycleType IEdgeLifecycleAttribute.Type => EdgeLifecycleType.Disable;
  104. }
  105. }