LitMotionUIToolkitExtensions.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. #if LITMOTION_SUPPORT_UIELEMENTS
  2. using Unity.Collections;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. #if LITMOTION_SUPPORT_ZSTRING
  6. using Cysharp.Text;
  7. #endif
  8. namespace LitMotion.Extensions
  9. {
  10. /// <summary>
  11. /// Provides binding extension methods for UIElements.
  12. /// </summary>
  13. public static class LitMotionUIToolkitExtensions
  14. {
  15. #region VisualElement
  16. /// <summary>
  17. /// Create a motion data and bind it to VisualElement.style.left
  18. /// </summary>
  19. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  20. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  21. /// <param name="builder">This builder</param>
  22. /// <param name="transform"></param>
  23. /// <returns>Handle of the created motion data.</returns>
  24. public static MotionHandle BindToStyleLeft<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  25. where TOptions : unmanaged, IMotionOptions
  26. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  27. {
  28. Error.IsNull(visualElement);
  29. return builder.BindWithState(visualElement, static (x, target) =>
  30. {
  31. target.style.left = x;
  32. });
  33. }
  34. /// <summary>
  35. /// Create a motion data and bind it to VisualElement.style.right
  36. /// </summary>
  37. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  38. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  39. /// <param name="builder">This builder</param>
  40. /// <param name="transform"></param>
  41. /// <returns>Handle of the created motion data.</returns>
  42. public static MotionHandle BindToStyleRight<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  43. where TOptions : unmanaged, IMotionOptions
  44. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  45. {
  46. Error.IsNull(visualElement);
  47. return builder.BindWithState(visualElement, static (x, target) =>
  48. {
  49. target.style.right = x;
  50. });
  51. }
  52. /// <summary>
  53. /// Create a motion data and bind it to VisualElement.style.top
  54. /// </summary>
  55. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  56. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  57. /// <param name="builder">This builder</param>
  58. /// <param name="transform"></param>
  59. /// <returns>Handle of the created motion data.</returns>
  60. public static MotionHandle BindToStyleTop<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  61. where TOptions : unmanaged, IMotionOptions
  62. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  63. {
  64. Error.IsNull(visualElement);
  65. return builder.BindWithState(visualElement, static (x, target) =>
  66. {
  67. target.style.top = x;
  68. });
  69. }
  70. /// <summary>
  71. /// Create a motion data and bind it to VisualElement.style.bottom
  72. /// </summary>
  73. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  74. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  75. /// <param name="builder">This builder</param>
  76. /// <param name="transform"></param>
  77. /// <returns>Handle of the created motion data.</returns>
  78. public static MotionHandle BindToStyleBottom<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  79. where TOptions : unmanaged, IMotionOptions
  80. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  81. {
  82. Error.IsNull(visualElement);
  83. return builder.BindWithState(visualElement, static (x, target) =>
  84. {
  85. target.style.bottom = x;
  86. });
  87. }
  88. /// <summary>
  89. /// Create a motion data and bind it to VisualElement.style.width
  90. /// </summary>
  91. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  92. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  93. /// <param name="builder">This builder</param>
  94. /// <param name="transform"></param>
  95. /// <returns>Handle of the created motion data.</returns>
  96. public static MotionHandle BindToStyleWidth<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  97. where TOptions : unmanaged, IMotionOptions
  98. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  99. {
  100. Error.IsNull(visualElement);
  101. return builder.BindWithState(visualElement, static (x, target) =>
  102. {
  103. target.style.width = x;
  104. });
  105. }
  106. /// <summary>
  107. /// Create a motion data and bind it to VisualElement.style.height
  108. /// </summary>
  109. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  110. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  111. /// <param name="builder">This builder</param>
  112. /// <param name="transform"></param>
  113. /// <returns>Handle of the created motion data.</returns>
  114. public static MotionHandle BindToStyleHeight<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  115. where TOptions : unmanaged, IMotionOptions
  116. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  117. {
  118. Error.IsNull(visualElement);
  119. return builder.BindWithState(visualElement, static (x, target) =>
  120. {
  121. target.style.height = x;
  122. });
  123. }
  124. /// <summary>
  125. /// Create a motion data and bind it to VisualElement.style.color
  126. /// </summary>
  127. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  128. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  129. /// <param name="builder">This builder</param>
  130. /// <param name="transform"></param>
  131. /// <returns>Handle of the created motion data.</returns>
  132. public static MotionHandle BindToStyleColor<TOptions, TAdapter>(this MotionBuilder<Color, TOptions, TAdapter> builder, VisualElement visualElement)
  133. where TOptions : unmanaged, IMotionOptions
  134. where TAdapter : unmanaged, IMotionAdapter<Color, TOptions>
  135. {
  136. Error.IsNull(visualElement);
  137. return builder.BindWithState(visualElement, static (x, target) =>
  138. {
  139. target.style.color = x;
  140. });
  141. }
  142. /// <summary>
  143. /// Create a motion data and bind it to VisualElement.style.color.r
  144. /// </summary>
  145. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  146. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  147. /// <param name="builder">This builder</param>
  148. /// <param name="transform"></param>
  149. /// <returns>Handle of the created motion data.</returns>
  150. public static MotionHandle BindToStyleColorR<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  151. where TOptions : unmanaged, IMotionOptions
  152. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  153. {
  154. Error.IsNull(visualElement);
  155. return builder.BindWithState(visualElement, static (x, target) =>
  156. {
  157. var c = target.style.color.value;
  158. c.r = x;
  159. target.style.color = c;
  160. });
  161. }
  162. /// <summary>
  163. /// Create a motion data and bind it to VisualElement.style.color.g
  164. /// </summary>
  165. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  166. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  167. /// <param name="builder">This builder</param>
  168. /// <param name="transform"></param>
  169. /// <returns>Handle of the created motion data.</returns>
  170. public static MotionHandle BindToStyleColorG<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  171. where TOptions : unmanaged, IMotionOptions
  172. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  173. {
  174. Error.IsNull(visualElement);
  175. return builder.BindWithState(visualElement, static (x, target) =>
  176. {
  177. var c = target.style.color.value;
  178. c.g = x;
  179. target.style.color = c;
  180. });
  181. }
  182. /// <summary>
  183. /// Create a motion data and bind it to VisualElement.style.color.b
  184. /// </summary>
  185. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  186. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  187. /// <param name="builder">This builder</param>
  188. /// <param name="transform"></param>
  189. /// <returns>Handle of the created motion data.</returns>
  190. public static MotionHandle BindToStyleColorB<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  191. where TOptions : unmanaged, IMotionOptions
  192. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  193. {
  194. Error.IsNull(visualElement);
  195. return builder.BindWithState(visualElement, static (x, target) =>
  196. {
  197. var c = target.style.color.value;
  198. c.b = x;
  199. target.style.color = c;
  200. });
  201. }
  202. /// <summary>
  203. /// Create a motion data and bind it to VisualElement.style.color.a
  204. /// </summary>
  205. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  206. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  207. /// <param name="builder">This builder</param>
  208. /// <param name="transform"></param>
  209. /// <returns>Handle of the created motion data.</returns>
  210. public static MotionHandle BindToStyleColorA<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  211. where TOptions : unmanaged, IMotionOptions
  212. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  213. {
  214. Error.IsNull(visualElement);
  215. return builder.BindWithState(visualElement, static (x, target) =>
  216. {
  217. var c = target.style.color.value;
  218. c.a = x;
  219. target.style.color = c;
  220. });
  221. }
  222. /// <summary>
  223. /// Create a motion data and bind it to VisualElement.style.backgroundColor
  224. /// </summary>
  225. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  226. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  227. /// <param name="builder">This builder</param>
  228. /// <param name="transform"></param>
  229. /// <returns>Handle of the created motion data.</returns>
  230. public static MotionHandle BindToStyleBackgroundColor<TOptions, TAdapter>(this MotionBuilder<Color, TOptions, TAdapter> builder, VisualElement visualElement)
  231. where TOptions : unmanaged, IMotionOptions
  232. where TAdapter : unmanaged, IMotionAdapter<Color, TOptions>
  233. {
  234. Error.IsNull(visualElement);
  235. return builder.BindWithState(visualElement, static (x, target) =>
  236. {
  237. target.style.backgroundColor = x;
  238. });
  239. }
  240. /// <summary>
  241. /// Create a motion data and bind it to VisualElement.style.backgroundColor.r
  242. /// </summary>
  243. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  244. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  245. /// <param name="builder">This builder</param>
  246. /// <param name="transform"></param>
  247. /// <returns>Handle of the created motion data.</returns>
  248. public static MotionHandle BindToStyleBackgroundColorR<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  249. where TOptions : unmanaged, IMotionOptions
  250. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  251. {
  252. Error.IsNull(visualElement);
  253. return builder.BindWithState(visualElement, static (x, target) =>
  254. {
  255. var c = target.style.backgroundColor.value;
  256. c.r = x;
  257. target.style.backgroundColor = c;
  258. });
  259. }
  260. /// <summary>
  261. /// Create a motion data and bind it to VisualElement.style.backgroundColor.g
  262. /// </summary>
  263. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  264. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  265. /// <param name="builder">This builder</param>
  266. /// <param name="transform"></param>
  267. /// <returns>Handle of the created motion data.</returns>
  268. public static MotionHandle BindToStyleBackgroundColorG<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  269. where TOptions : unmanaged, IMotionOptions
  270. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  271. {
  272. Error.IsNull(visualElement);
  273. return builder.BindWithState(visualElement, static (x, target) =>
  274. {
  275. var c = target.style.backgroundColor.value;
  276. c.g = x;
  277. target.style.backgroundColor = c;
  278. });
  279. }
  280. /// <summary>
  281. /// Create a motion data and bind it to VisualElement.style.backgroundColor.b
  282. /// </summary>
  283. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  284. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  285. /// <param name="builder">This builder</param>
  286. /// <param name="transform"></param>
  287. /// <returns>Handle of the created motion data.</returns>
  288. public static MotionHandle BindToStyleBackgroundColorB<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  289. where TOptions : unmanaged, IMotionOptions
  290. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  291. {
  292. Error.IsNull(visualElement);
  293. return builder.BindWithState(visualElement, static (x, target) =>
  294. {
  295. var c = target.style.backgroundColor.value;
  296. c.b = x;
  297. target.style.backgroundColor = c;
  298. });
  299. }
  300. /// <summary>
  301. /// Create a motion data and bind it to VisualElement.style.backgroundColor.a
  302. /// </summary>
  303. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  304. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  305. /// <param name="builder">This builder</param>
  306. /// <param name="transform"></param>
  307. /// <returns>Handle of the created motion data.</returns>
  308. public static MotionHandle BindToStyleBackgroundColorA<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  309. where TOptions : unmanaged, IMotionOptions
  310. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  311. {
  312. Error.IsNull(visualElement);
  313. return builder.BindWithState(visualElement, static (x, target) =>
  314. {
  315. var c = target.style.backgroundColor.value;
  316. c.a = x;
  317. target.style.backgroundColor = c;
  318. });
  319. }
  320. /// <summary>
  321. /// Create a motion data and bind it to VisualElement.style.opacity
  322. /// </summary>
  323. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  324. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  325. /// <param name="builder">This builder</param>
  326. /// <param name="transform"></param>
  327. /// <returns>Handle of the created motion data.</returns>
  328. public static MotionHandle BindToStyleOpacity<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  329. where TOptions : unmanaged, IMotionOptions
  330. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  331. {
  332. Error.IsNull(visualElement);
  333. return builder.BindWithState(visualElement, static (x, target) =>
  334. {
  335. target.style.opacity = x;
  336. });
  337. }
  338. /// <summary>
  339. /// Create a motion data and bind it to VisualElement.style.fontSize
  340. /// </summary>
  341. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  342. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  343. /// <param name="builder">This builder</param>
  344. /// <param name="transform"></param>
  345. /// <returns>Handle of the created motion data.</returns>
  346. public static MotionHandle BindToStyleFontSize<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  347. where TOptions : unmanaged, IMotionOptions
  348. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  349. {
  350. Error.IsNull(visualElement);
  351. return builder.BindWithState(visualElement, static (x, target) =>
  352. {
  353. target.style.fontSize = x;
  354. });
  355. }
  356. /// <summary>
  357. /// Create a motion data and bind it to VisualElement.style.wordSpacing
  358. /// </summary>
  359. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  360. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  361. /// <param name="builder">This builder</param>
  362. /// <param name="transform"></param>
  363. /// <returns>Handle of the created motion data.</returns>
  364. public static MotionHandle BindToStyleWordSpacing<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
  365. where TOptions : unmanaged, IMotionOptions
  366. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  367. {
  368. Error.IsNull(visualElement);
  369. return builder.BindWithState(visualElement, static (x, target) =>
  370. {
  371. target.style.wordSpacing = x;
  372. });
  373. }
  374. /// <summary>
  375. /// Create a motion data and bind it to VisualElement.style.translate
  376. /// </summary>
  377. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  378. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  379. /// <param name="builder">This builder</param>
  380. /// <param name="transform"></param>
  381. /// <returns>Handle of the created motion data.</returns>
  382. public static MotionHandle BindToStyleTranslate<TOptions, TAdapter>(this MotionBuilder<Vector3, TOptions, TAdapter> builder, VisualElement visualElement)
  383. where TOptions : unmanaged, IMotionOptions
  384. where TAdapter : unmanaged, IMotionAdapter<Vector3, TOptions>
  385. {
  386. Error.IsNull(visualElement);
  387. return builder.BindWithState(visualElement, static (x, target) =>
  388. {
  389. target.style.translate = new Translate(x.x, x.y, x.z);
  390. });
  391. }
  392. /// <summary>
  393. /// Create a motion data and bind it to VisualElement.style.translate
  394. /// </summary>
  395. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  396. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  397. /// <param name="builder">This builder</param>
  398. /// <param name="transform"></param>
  399. /// <returns>Handle of the created motion data.</returns>
  400. public static MotionHandle BindToStyleTranslate<TOptions, TAdapter>(this MotionBuilder<Vector2, TOptions, TAdapter> builder, VisualElement visualElement)
  401. where TOptions : unmanaged, IMotionOptions
  402. where TAdapter : unmanaged, IMotionAdapter<Vector2, TOptions>
  403. {
  404. Error.IsNull(visualElement);
  405. return builder.BindWithState(visualElement, static (x, target) =>
  406. {
  407. target.style.translate = new Translate(x.x, x.y);
  408. });
  409. }
  410. /// <summary>
  411. /// Create a motion data and bind it to VisualElement.style.rotate
  412. /// </summary>
  413. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  414. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  415. /// <param name="builder">This builder</param>
  416. /// <param name="transform"></param>
  417. /// <returns>Handle of the created motion data.</returns>
  418. public static MotionHandle BindToStyleRotate<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement, AngleUnit angleUnit = AngleUnit.Degree)
  419. where TOptions : unmanaged, IMotionOptions
  420. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  421. {
  422. Error.IsNull(visualElement);
  423. return builder.BindWithState(visualElement, (x, target) =>
  424. {
  425. target.style.rotate = new Rotate(new Angle(x, angleUnit));
  426. });
  427. }
  428. /// <summary>
  429. /// Create a motion data and bind it to VisualElement.style.scale
  430. /// </summary>
  431. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  432. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  433. /// <param name="builder">This builder</param>
  434. /// <param name="transform"></param>
  435. /// <returns>Handle of the created motion data.</returns>
  436. public static MotionHandle BindToStyleScale<TOptions, TAdapter>(this MotionBuilder<Vector3, TOptions, TAdapter> builder, VisualElement visualElement)
  437. where TOptions : unmanaged, IMotionOptions
  438. where TAdapter : unmanaged, IMotionAdapter<Vector3, TOptions>
  439. {
  440. Error.IsNull(visualElement);
  441. return builder.BindWithState(visualElement, static (x, target) =>
  442. {
  443. target.style.scale = new Scale(x);
  444. });
  445. }
  446. /// <summary>
  447. /// Create a motion data and bind it to VisualElement.style.transformOrigin
  448. /// </summary>
  449. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  450. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  451. /// <param name="builder">This builder</param>
  452. /// <param name="transform"></param>
  453. /// <returns>Handle of the created motion data.</returns>
  454. public static MotionHandle BindToStyleTransformOrigin<TOptions, TAdapter>(this MotionBuilder<Vector3, TOptions, TAdapter> builder, VisualElement visualElement)
  455. where TOptions : unmanaged, IMotionOptions
  456. where TAdapter : unmanaged, IMotionAdapter<Vector3, TOptions>
  457. {
  458. Error.IsNull(visualElement);
  459. return builder.BindWithState(visualElement, static (x, target) =>
  460. {
  461. target.style.transformOrigin = new TransformOrigin(x.x, x.y, x.z);
  462. });
  463. }
  464. /// <summary>
  465. /// Create a motion data and bind it to VisualElement.style.transformOrigin
  466. /// </summary>
  467. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  468. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  469. /// <param name="builder">This builder</param>
  470. /// <param name="transform"></param>
  471. /// <returns>Handle of the created motion data.</returns>
  472. public static MotionHandle BindToStyleTransformOrigin<TOptions, TAdapter>(this MotionBuilder<Vector2, TOptions, TAdapter> builder, VisualElement visualElement)
  473. where TOptions : unmanaged, IMotionOptions
  474. where TAdapter : unmanaged, IMotionAdapter<Vector2, TOptions>
  475. {
  476. Error.IsNull(visualElement);
  477. return builder.BindWithState(visualElement, static (x, target) =>
  478. {
  479. target.style.transformOrigin = new TransformOrigin(x.x, x.y);
  480. });
  481. }
  482. #endregion
  483. #region AbstractProgressBar
  484. /// <summary>
  485. /// Create a motion data and bind it to AbstractProgressBar.value
  486. /// </summary>
  487. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  488. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  489. /// <param name="builder">This builder</param>
  490. /// <param name="transform"></param>
  491. /// <returns>Handle of the created motion data.</returns>
  492. public static MotionHandle BindToProgressBar<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, AbstractProgressBar progressBar)
  493. where TOptions : unmanaged, IMotionOptions
  494. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  495. {
  496. Error.IsNull(progressBar);
  497. return builder.BindWithState(progressBar, static (x, target) =>
  498. {
  499. target.value = x;
  500. });
  501. }
  502. #endregion
  503. #region TextElement
  504. /// <summary>
  505. /// Create a motion data and bind it to TextElement.text
  506. /// </summary>
  507. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  508. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  509. /// <param name="builder">This builder</param>
  510. /// <param name="transform"></param>
  511. /// <returns>Handle of the created motion data.</returns>
  512. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<FixedString32Bytes, TOptions, TAdapter> builder, TextElement textElement)
  513. where TOptions : unmanaged, IMotionOptions
  514. where TAdapter : unmanaged, IMotionAdapter<FixedString32Bytes, TOptions>
  515. {
  516. Error.IsNull(textElement);
  517. return builder.BindWithState(textElement, static (x, target) =>
  518. {
  519. target.text = x.ConvertToString();
  520. });
  521. }
  522. /// <summary>
  523. /// Create a motion data and bind it to TextElement.text
  524. /// </summary>
  525. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  526. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  527. /// <param name="builder">This builder</param>
  528. /// <param name="transform"></param>
  529. /// <returns>Handle of the created motion data.</returns>
  530. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<FixedString64Bytes, TOptions, TAdapter> builder, TextElement textElement)
  531. where TOptions : unmanaged, IMotionOptions
  532. where TAdapter : unmanaged, IMotionAdapter<FixedString64Bytes, TOptions>
  533. {
  534. Error.IsNull(textElement);
  535. return builder.BindWithState(textElement, static (x, target) =>
  536. {
  537. target.text = x.ConvertToString();
  538. });
  539. }
  540. /// <summary>
  541. /// Create a motion data and bind it to TextElement.text
  542. /// </summary>
  543. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  544. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  545. /// <param name="builder">This builder</param>
  546. /// <param name="transform"></param>
  547. /// <returns>Handle of the created motion data.</returns>
  548. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<FixedString128Bytes, TOptions, TAdapter> builder, TextElement textElement)
  549. where TOptions : unmanaged, IMotionOptions
  550. where TAdapter : unmanaged, IMotionAdapter<FixedString128Bytes, TOptions>
  551. {
  552. Error.IsNull(textElement);
  553. return builder.BindWithState(textElement, static (x, target) =>
  554. {
  555. target.text = x.ConvertToString();
  556. });
  557. }
  558. /// <summary>
  559. /// Create a motion data and bind it to TextElement.text
  560. /// </summary>
  561. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  562. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  563. /// <param name="builder">This builder</param>
  564. /// <param name="transform"></param>
  565. /// <returns>Handle of the created motion data.</returns>
  566. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<FixedString512Bytes, TOptions, TAdapter> builder, TextElement textElement)
  567. where TOptions : unmanaged, IMotionOptions
  568. where TAdapter : unmanaged, IMotionAdapter<FixedString512Bytes, TOptions>
  569. {
  570. Error.IsNull(textElement);
  571. return builder.BindWithState(textElement, static (x, target) =>
  572. {
  573. target.text = x.ConvertToString();
  574. });
  575. }
  576. /// <summary>
  577. /// Create a motion data and bind it to TextElement.text
  578. /// </summary>
  579. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  580. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  581. /// <param name="builder">This builder</param>
  582. /// <param name="transform"></param>
  583. /// <returns>Handle of the created motion data.</returns>
  584. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<FixedString4096Bytes, TOptions, TAdapter> builder, TextElement textElement)
  585. where TOptions : unmanaged, IMotionOptions
  586. where TAdapter : unmanaged, IMotionAdapter<FixedString4096Bytes, TOptions>
  587. {
  588. Error.IsNull(textElement);
  589. return builder.BindWithState(textElement, static (x, target) =>
  590. {
  591. target.text = x.ConvertToString();
  592. });
  593. }
  594. /// <summary>
  595. /// Create a motion data and bind it to Text.text
  596. /// </summary>
  597. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  598. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  599. /// <param name="builder">This builder</param>
  600. /// <param name="transform"></param>
  601. /// <returns>Handle of the created motion data.</returns>
  602. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<int, TOptions, TAdapter> builder, TextElement textElement)
  603. where TOptions : unmanaged, IMotionOptions
  604. where TAdapter : unmanaged, IMotionAdapter<int, TOptions>
  605. {
  606. Error.IsNull(textElement);
  607. return builder.BindWithState(textElement, static (x, target) =>
  608. {
  609. target.text = x.ToString();
  610. });
  611. }
  612. /// <summary>
  613. /// Create a motion data and bind it to Text.text
  614. /// </summary>
  615. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  616. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  617. /// <param name="builder">This builder</param>
  618. /// <param name="transform"></param>
  619. /// <param name="format">Format string</param>
  620. /// <returns>Handle of the created motion data.</returns>
  621. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<int, TOptions, TAdapter> builder, TextElement textElement, string format)
  622. where TOptions : unmanaged, IMotionOptions
  623. where TAdapter : unmanaged, IMotionAdapter<int, TOptions>
  624. {
  625. Error.IsNull(textElement);
  626. return builder.BindWithState(textElement, format, static (x, target, f) =>
  627. {
  628. #if LITMOTION_SUPPORT_ZSTRING
  629. target.text = ZString.Format(f, x);
  630. #else
  631. target.text = string.Format(f, x);
  632. #endif
  633. });
  634. }
  635. /// <summary>
  636. /// Create a motion data and bind it to Text.text
  637. /// </summary>
  638. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  639. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  640. /// <param name="builder">This builder</param>
  641. /// <param name="transform"></param>
  642. /// <returns>Handle of the created motion data.</returns>
  643. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<long, TOptions, TAdapter> builder, TextElement textElement)
  644. where TOptions : unmanaged, IMotionOptions
  645. where TAdapter : unmanaged, IMotionAdapter<long, TOptions>
  646. {
  647. Error.IsNull(textElement);
  648. return builder.BindWithState(textElement, static (x, target) =>
  649. {
  650. target.text = x.ToString();
  651. });
  652. }
  653. /// <summary>
  654. /// Create a motion data and bind it to Text.text
  655. /// </summary>
  656. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  657. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  658. /// <param name="builder">This builder</param>
  659. /// <param name="transform"></param>
  660. /// <param name="format">Format string</param>
  661. /// <returns>Handle of the created motion data.</returns>
  662. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<long, TOptions, TAdapter> builder, TextElement textElement, string format)
  663. where TOptions : unmanaged, IMotionOptions
  664. where TAdapter : unmanaged, IMotionAdapter<long, TOptions>
  665. {
  666. Error.IsNull(textElement);
  667. return builder.BindWithState(textElement, format, static (x, target, format) =>
  668. {
  669. #if LITMOTION_SUPPORT_ZSTRING
  670. target.text = ZString.Format(format, x);
  671. #else
  672. target.text = string.Format(format, x);
  673. #endif
  674. });
  675. }
  676. /// <summary>
  677. /// Create a motion data and bind it to Text.text
  678. /// </summary>
  679. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  680. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  681. /// <param name="builder">This builder</param>
  682. /// <param name="transform"></param>
  683. /// <returns>Handle of the created motion data.</returns>
  684. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, TextElement textElement)
  685. where TOptions : unmanaged, IMotionOptions
  686. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  687. {
  688. Error.IsNull(textElement);
  689. return builder.BindWithState(textElement, static (x, target) =>
  690. {
  691. target.text = x.ToString();
  692. });
  693. }
  694. /// <summary>
  695. /// Create a motion data and bind it to Text.text
  696. /// </summary>
  697. /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
  698. /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
  699. /// <param name="builder">This builder</param>
  700. /// <param name="transform"></param>
  701. /// <param name="format">Format string</param>
  702. /// <returns>Handle of the created motion data.</returns>
  703. public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, TextElement textElement, string format)
  704. where TOptions : unmanaged, IMotionOptions
  705. where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
  706. {
  707. Error.IsNull(textElement);
  708. return builder.BindWithState(textElement, format, static (x, target, format) =>
  709. {
  710. #if LITMOTION_SUPPORT_ZSTRING
  711. target.text = ZString.Format(format, x);
  712. #else
  713. target.text = string.Format(format, x);
  714. #endif
  715. });
  716. }
  717. #endregion
  718. }
  719. }
  720. #endif