RegionAttachment.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. using System;
  2. namespace Spine
  3. {
  4. public class RegionAttachment : Attachment
  5. {
  6. public RegionAttachment(string name) : base(name)
  7. {
  8. }
  9. public float X
  10. {
  11. get
  12. {
  13. return this.x;
  14. }
  15. set
  16. {
  17. this.x = value;
  18. }
  19. }
  20. public float Y
  21. {
  22. get
  23. {
  24. return this.y;
  25. }
  26. set
  27. {
  28. this.y = value;
  29. }
  30. }
  31. public float Rotation
  32. {
  33. get
  34. {
  35. return this.rotation;
  36. }
  37. set
  38. {
  39. this.rotation = value;
  40. }
  41. }
  42. public float ScaleX
  43. {
  44. get
  45. {
  46. return this.scaleX;
  47. }
  48. set
  49. {
  50. this.scaleX = value;
  51. }
  52. }
  53. public float ScaleY
  54. {
  55. get
  56. {
  57. return this.scaleY;
  58. }
  59. set
  60. {
  61. this.scaleY = value;
  62. }
  63. }
  64. public float Width
  65. {
  66. get
  67. {
  68. return this.width;
  69. }
  70. set
  71. {
  72. this.width = value;
  73. }
  74. }
  75. public float Height
  76. {
  77. get
  78. {
  79. return this.height;
  80. }
  81. set
  82. {
  83. this.height = value;
  84. }
  85. }
  86. public float R
  87. {
  88. get
  89. {
  90. return this.r;
  91. }
  92. set
  93. {
  94. this.r = value;
  95. }
  96. }
  97. public float G
  98. {
  99. get
  100. {
  101. return this.g;
  102. }
  103. set
  104. {
  105. this.g = value;
  106. }
  107. }
  108. public float B
  109. {
  110. get
  111. {
  112. return this.b;
  113. }
  114. set
  115. {
  116. this.b = value;
  117. }
  118. }
  119. public float A
  120. {
  121. get
  122. {
  123. return this.a;
  124. }
  125. set
  126. {
  127. this.a = value;
  128. }
  129. }
  130. public string Path { get; set; }
  131. public object RendererObject { get; set; }
  132. public float RegionOffsetX
  133. {
  134. get
  135. {
  136. return this.regionOffsetX;
  137. }
  138. set
  139. {
  140. this.regionOffsetX = value;
  141. }
  142. }
  143. public float RegionOffsetY
  144. {
  145. get
  146. {
  147. return this.regionOffsetY;
  148. }
  149. set
  150. {
  151. this.regionOffsetY = value;
  152. }
  153. }
  154. public float RegionWidth
  155. {
  156. get
  157. {
  158. return this.regionWidth;
  159. }
  160. set
  161. {
  162. this.regionWidth = value;
  163. }
  164. }
  165. public float RegionHeight
  166. {
  167. get
  168. {
  169. return this.regionHeight;
  170. }
  171. set
  172. {
  173. this.regionHeight = value;
  174. }
  175. }
  176. public float RegionOriginalWidth
  177. {
  178. get
  179. {
  180. return this.regionOriginalWidth;
  181. }
  182. set
  183. {
  184. this.regionOriginalWidth = value;
  185. }
  186. }
  187. public float RegionOriginalHeight
  188. {
  189. get
  190. {
  191. return this.regionOriginalHeight;
  192. }
  193. set
  194. {
  195. this.regionOriginalHeight = value;
  196. }
  197. }
  198. public float[] Offset
  199. {
  200. get
  201. {
  202. return this.offset;
  203. }
  204. }
  205. public float[] UVs
  206. {
  207. get
  208. {
  209. return this.uvs;
  210. }
  211. }
  212. public void SetUVs(float u, float v, float u2, float v2, bool rotate)
  213. {
  214. float[] array = this.uvs;
  215. if (rotate)
  216. {
  217. array[2] = u;
  218. array[3] = v2;
  219. array[4] = u;
  220. array[5] = v;
  221. array[6] = u2;
  222. array[7] = v;
  223. array[0] = u2;
  224. array[1] = v2;
  225. }
  226. else
  227. {
  228. array[0] = u;
  229. array[1] = v2;
  230. array[2] = u;
  231. array[3] = v;
  232. array[4] = u2;
  233. array[5] = v;
  234. array[6] = u2;
  235. array[7] = v2;
  236. }
  237. }
  238. public void UpdateOffset()
  239. {
  240. float num = this.width;
  241. float num2 = this.height;
  242. float num3 = this.scaleX;
  243. float num4 = this.scaleY;
  244. float num5 = num / this.regionOriginalWidth * num3;
  245. float num6 = num2 / this.regionOriginalHeight * num4;
  246. float num7 = -num / 2f * num3 + this.regionOffsetX * num5;
  247. float num8 = -num2 / 2f * num4 + this.regionOffsetY * num6;
  248. float num9 = num7 + this.regionWidth * num5;
  249. float num10 = num8 + this.regionHeight * num6;
  250. float num11 = this.rotation * 3.14159274f / 180f;
  251. float num12 = (float)Math.Cos((double)num11);
  252. float num13 = (float)Math.Sin((double)num11);
  253. float num14 = this.x;
  254. float num15 = this.y;
  255. float num16 = num7 * num12 + num14;
  256. float num17 = num7 * num13;
  257. float num18 = num8 * num12 + num15;
  258. float num19 = num8 * num13;
  259. float num20 = num9 * num12 + num14;
  260. float num21 = num9 * num13;
  261. float num22 = num10 * num12 + num15;
  262. float num23 = num10 * num13;
  263. float[] array = this.offset;
  264. array[0] = num16 - num19;
  265. array[1] = num18 + num17;
  266. array[2] = num16 - num23;
  267. array[3] = num22 + num17;
  268. array[4] = num20 - num23;
  269. array[5] = num22 + num21;
  270. array[6] = num20 - num19;
  271. array[7] = num18 + num21;
  272. }
  273. public void ComputeWorldVertices(Bone bone, float[] worldVertices)
  274. {
  275. float num = bone.skeleton.x + bone.worldX;
  276. float num2 = bone.skeleton.y + bone.worldY;
  277. float m = bone.m00;
  278. float m2 = bone.m01;
  279. float m3 = bone.m10;
  280. float m4 = bone.m11;
  281. float[] array = this.offset;
  282. worldVertices[0] = array[0] * m + array[1] * m2 + num;
  283. worldVertices[1] = array[0] * m3 + array[1] * m4 + num2;
  284. worldVertices[2] = array[2] * m + array[3] * m2 + num;
  285. worldVertices[3] = array[2] * m3 + array[3] * m4 + num2;
  286. worldVertices[4] = array[4] * m + array[5] * m2 + num;
  287. worldVertices[5] = array[4] * m3 + array[5] * m4 + num2;
  288. worldVertices[6] = array[6] * m + array[7] * m2 + num;
  289. worldVertices[7] = array[6] * m3 + array[7] * m4 + num2;
  290. }
  291. public const int X1 = 0;
  292. public const int Y1 = 1;
  293. public const int X2 = 2;
  294. public const int Y2 = 3;
  295. public const int X3 = 4;
  296. public const int Y3 = 5;
  297. public const int X4 = 6;
  298. public const int Y4 = 7;
  299. internal float x;
  300. internal float y;
  301. internal float rotation;
  302. internal float scaleX = 1f;
  303. internal float scaleY = 1f;
  304. internal float width;
  305. internal float height;
  306. internal float regionOffsetX;
  307. internal float regionOffsetY;
  308. internal float regionWidth;
  309. internal float regionHeight;
  310. internal float regionOriginalWidth;
  311. internal float regionOriginalHeight;
  312. internal float[] offset = new float[8];
  313. internal float[] uvs = new float[8];
  314. internal float r = 1f;
  315. internal float g = 1f;
  316. internal float b = 1f;
  317. internal float a = 1f;
  318. }
  319. }