LitMotionVisualEffectExtensions.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #if LITMOTION_SUPPORT_VFX_GRAPH
  2. using UnityEngine;
  3. using UnityEngine.VFX;
  4. namespace LitMotion.Extensions
  5. {
  6. /// <summary>
  7. /// Provides binding extension methods for VisualEffect.
  8. /// </summary>
  9. public static class LitMotionVisualEffectExtensions
  10. {
  11. /// <summary>
  12. /// Create a motion data and bind it to VisualEffect parameter.
  13. /// </summary>
  14. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  15. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  16. /// <param name="builder">This builder</param>
  17. /// <param name="transform"></param>
  18. /// <returns>Handle of the created motion data.</returns>
  19. public static MotionHandle BindToVisualEffectFloat<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualEffect visualEffect, string name)
  20. where TOptions : unmanaged, IMotionOptions
  21. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  22. {
  23. Error.IsNull(visualEffect);
  24. return builder.BindWithState(visualEffect, name, static (x, target, n) =>
  25. {
  26. target.SetFloat(n, x);
  27. });
  28. }
  29. /// <summary>
  30. /// Create a motion data and bind it to VisualEffect parameter.
  31. /// </summary>
  32. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  33. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  34. /// <param name="builder">This builder</param>
  35. /// <param name="transform"></param>
  36. /// <returns>Handle of the created motion data.</returns>
  37. public static MotionHandle BindToVisualEffectFloat<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualEffect visualEffect, int nameID)
  38. where TOptions : unmanaged, IMotionOptions
  39. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  40. {
  41. Error.IsNull(visualEffect);
  42. return builder.BindWithState(visualEffect, (x, target) =>
  43. {
  44. target.SetFloat(nameID, x);
  45. });
  46. }
  47. /// <summary>
  48. /// Create a motion data and bind it to VisualEffect parameter.
  49. /// </summary>
  50. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  51. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  52. /// <param name="builder">This builder</param>
  53. /// <param name="transform"></param>
  54. /// <returns>Handle of the created motion data.</returns>
  55. public static MotionHandle BindToVisualEffectInt<TOptions, TAdapter>(this MotionBuilder<int, TOptions, TAdapter> builder, VisualEffect visualEffect, string name)
  56. where TOptions : unmanaged, IMotionOptions
  57. where TAdapter : unmanaged, IMotionAdapter<int, TOptions>
  58. {
  59. Error.IsNull(visualEffect);
  60. return builder.BindWithState(visualEffect, name, static (x, target, n) =>
  61. {
  62. target.SetInt(n, x);
  63. });
  64. }
  65. /// <summary>
  66. /// Create a motion data and bind it to VisualEffect parameter.
  67. /// </summary>
  68. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  69. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  70. /// <param name="builder">This builder</param>
  71. /// <param name="transform"></param>
  72. /// <returns>Handle of the created motion data.</returns>
  73. public static MotionHandle BindToVisualEffectInt<TOptions, TAdapter>(this MotionBuilder<int, TOptions, TAdapter> builder, VisualEffect visualEffect, int nameID)
  74. where TOptions : unmanaged, IMotionOptions
  75. where TAdapter : unmanaged, IMotionAdapter<int, TOptions>
  76. {
  77. Error.IsNull(visualEffect);
  78. return builder.BindWithState(visualEffect, (x, target) =>
  79. {
  80. target.SetFloat(nameID, x);
  81. });
  82. }
  83. /// <summary>
  84. /// Create a motion data and bind it to VisualEffect parameter.
  85. /// </summary>
  86. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  87. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  88. /// <param name="builder">This builder</param>
  89. /// <param name="transform"></param>
  90. /// <returns>Handle of the created motion data.</returns>
  91. public static MotionHandle BindToVisualEffectVector2<TOptions, TAdapter>(this MotionBuilder<Vector2, TOptions, TAdapter> builder, VisualEffect visualEffect, string name)
  92. where TOptions : unmanaged, IMotionOptions
  93. where TAdapter : unmanaged, IMotionAdapter<Vector2, TOptions>
  94. {
  95. Error.IsNull(visualEffect);
  96. return builder.BindWithState(visualEffect, name, static (x, target, n) =>
  97. {
  98. target.SetVector2(n, x);
  99. });
  100. }
  101. /// <summary>
  102. /// Create a motion data and bind it to VisualEffect parameter.
  103. /// </summary>
  104. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  105. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  106. /// <param name="builder">This builder</param>
  107. /// <param name="transform"></param>
  108. /// <returns>Handle of the created motion data.</returns>
  109. public static MotionHandle BindToVisualEffectVector2<TOptions, TAdapter>(this MotionBuilder<Vector2, TOptions, TAdapter> builder, VisualEffect visualEffect, int nameID)
  110. where TOptions : unmanaged, IMotionOptions
  111. where TAdapter : unmanaged, IMotionAdapter<Vector2, TOptions>
  112. {
  113. Error.IsNull(visualEffect);
  114. return builder.BindWithState(visualEffect, (x, target) =>
  115. {
  116. target.SetVector2(nameID, x);
  117. });
  118. }
  119. /// <summary>
  120. /// Create a motion data and bind it to VisualEffect parameter.
  121. /// </summary>
  122. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  123. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  124. /// <param name="builder">This builder</param>
  125. /// <param name="transform"></param>
  126. /// <returns>Handle of the created motion data.</returns>
  127. public static MotionHandle BindToVisualEffectVector3<TOptions, TAdapter>(this MotionBuilder<Vector3, TOptions, TAdapter> builder, VisualEffect visualEffect, string name)
  128. where TOptions : unmanaged, IMotionOptions
  129. where TAdapter : unmanaged, IMotionAdapter<Vector3, TOptions>
  130. {
  131. Error.IsNull(visualEffect);
  132. return builder.BindWithState(visualEffect, name, static (x, target, n) =>
  133. {
  134. target.SetVector3(n, x);
  135. });
  136. }
  137. /// <summary>
  138. /// Create a motion data and bind it to VisualEffect parameter.
  139. /// </summary>
  140. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  141. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  142. /// <param name="builder">This builder</param>
  143. /// <param name="transform"></param>
  144. /// <returns>Handle of the created motion data.</returns>
  145. public static MotionHandle BindToVisualEffectVector3<TOptions, TAdapter>(this MotionBuilder<Vector3, TOptions, TAdapter> builder, VisualEffect visualEffect, int nameID)
  146. where TOptions : unmanaged, IMotionOptions
  147. where TAdapter : unmanaged, IMotionAdapter<Vector3, TOptions>
  148. {
  149. Error.IsNull(visualEffect);
  150. return builder.BindWithState(visualEffect, (x, target) =>
  151. {
  152. target.SetVector3(nameID, x);
  153. });
  154. }
  155. /// <summary>
  156. /// Create a motion data and bind it to VisualEffect parameter.
  157. /// </summary>
  158. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  159. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  160. /// <param name="builder">This builder</param>
  161. /// <param name="transform"></param>
  162. /// <returns>Handle of the created motion data.</returns>
  163. public static MotionHandle BindToVisualEffectVector4<TOptions, TAdapter>(this MotionBuilder<Vector4, TOptions, TAdapter> builder, VisualEffect visualEffect, string name)
  164. where TOptions : unmanaged, IMotionOptions
  165. where TAdapter : unmanaged, IMotionAdapter<Vector4, TOptions>
  166. {
  167. Error.IsNull(visualEffect);
  168. return builder.BindWithState(visualEffect, name, static (x, target, n) =>
  169. {
  170. target.SetVector4(n, x);
  171. });
  172. }
  173. /// <summary>
  174. /// Create a motion data and bind it to VisualEffect parameter.
  175. /// </summary>
  176. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  177. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  178. /// <param name="builder">This builder</param>
  179. /// <param name="transform"></param>
  180. /// <returns>Handle of the created motion data.</returns>
  181. public static MotionHandle BindToVisualEffectVector4<TOptions, TAdapter>(this MotionBuilder<Vector4, TOptions, TAdapter> builder, VisualEffect visualEffect, int nameID)
  182. where TOptions : unmanaged, IMotionOptions
  183. where TAdapter : unmanaged, IMotionAdapter<Vector4, TOptions>
  184. {
  185. Error.IsNull(visualEffect);
  186. return builder.BindWithState(visualEffect, (x, target) =>
  187. {
  188. target.SetVector4(nameID, x);
  189. });
  190. }
  191. }
  192. }
  193. #endif