Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [ExecuteInEditMode]
  6. public class SkinnedQuad : MonoBehaviour
  7. {
  8.  
  9. public Transform[] bones;
  10. SkinnedMeshRenderer smr;
  11.  
  12.  
  13. private void Awake()
  14. {
  15. Mesh m = new Mesh(); // mesh 생성
  16.  
  17.  
  18. m.vertices = new Vector3[]
  19. {
  20.  
  21.  
  22. new Vector2(-1,-3),
  23. new Vector2(0,-1),
  24. new Vector2(1,-3),
  25.  
  26. new Vector2(0,0),
  27. new Vector2(-1,1),
  28. new Vector2(1,1),
  29.  
  30. new Vector2(0,-1),
  31. new Vector2(-1,0),
  32. new Vector2(1,0),
  33.  
  34.  
  35.  
  36. //leftshoulder
  37. new Vector2(-1.5f, -2.5f),
  38. new Vector2(-1.5f, -1.5f),
  39. new Vector2(-0.5f ,-2),
  40.  
  41. //left arm
  42. new Vector2(-2, -2),
  43. new Vector2(-1.5f, -1.75f),
  44. new Vector2(-1.5f, -2.25f),
  45.  
  46.  
  47. //rightsoulder
  48. new Vector2(0.5f, -2),
  49. new Vector2(1.5f, -1.5f),
  50. new Vector2(1.5f ,-2.5f),
  51.  
  52.  
  53. //right arm
  54. new Vector2(1.5f ,-2.25f),
  55. new Vector2(1.5f, -1.75f),
  56. new Vector2(2, -2),
  57.  
  58.  
  59.  
  60. //left knee
  61. new Vector2(-1, -4),
  62. new Vector2(-0.5f, -3),
  63. new Vector2(0 ,-4),
  64.  
  65. //left leg
  66. new Vector2(-0.5f, -4.5f),
  67. new Vector2(-0.75f, -4),
  68. new Vector2(-0.25f ,-4),
  69.  
  70. //right knee
  71. new Vector2(0, -4),
  72. new Vector2(0.5f, -3),
  73. new Vector2(1 ,-4),
  74.  
  75. //right leg
  76. new Vector2(0.5f, -4.5f),
  77. new Vector2(0.25f, -4),
  78. new Vector2(0.75f ,-4),
  79. };
  80.  
  81. m.triangles = new int[]
  82. {
  83. 0, 1, 2,
  84. 3, 4, 5,
  85. 6, 7, 8,
  86. 9, 10, 11,
  87. 12, 13, 14,
  88. 15, 16, 17,
  89. 18, 19, 20,
  90. 21, 22, 23,
  91. 24, 25, 26,
  92. 27, 28, 29,
  93. 30, 31, 32
  94.  
  95. };
  96.  
  97. m.uv = new Vector2[]
  98. {
  99. new Vector2(0.3125f, 0.5f),
  100. new Vector2(0.3125f, 0.6875f),
  101. new Vector2(0.4375f, 0.6875f),
  102.  
  103. new Vector2(0.125f, 0.75f),
  104. new Vector2(0.125f, 0.875f),
  105. new Vector2(0.25f, 0.875f),
  106.  
  107. new Vector2(0.25f, 0.75f),
  108. new Vector2(0.25f, 0.875f),
  109. new Vector2(0.375f, 0.875f),
  110.  
  111.  
  112. new Vector2(0.5625f, 0.0f),
  113. new Vector2(0.5625f, 0.1875f),
  114. new Vector2(0.625f, 0.1875f),
  115.  
  116. new Vector2(0.625f, 0.0f),
  117. new Vector2(0.625f, 0.1875f),
  118. new Vector2(0.6875f, 0.1875f),
  119.  
  120. new Vector2(0.6875f, 0.5f),
  121. new Vector2(0.6875f, 0.6875f),
  122. new Vector2(0.75f, 0.6875f),
  123.  
  124. new Vector2(0.75f, 0.5f),
  125. new Vector2(0.75f, 0.6875f),
  126. new Vector2(0.8125f, 0.6875f),
  127.  
  128. new Vector2(0.3125f, 0.0f),
  129. new Vector2(0.3125f, 0.1875f),
  130. new Vector2(0.3125f, 0.1875f),
  131.  
  132. new Vector2(0.375f, 0.0f),
  133. new Vector2(0.375f, 0.1875f),
  134. new Vector2(0.4375f, 0.1875f),
  135.  
  136. new Vector2(0.0625f, 0.5f),
  137. new Vector2(0.0625f, 0.6875f),
  138. new Vector2(0.125f, 0.6875f),
  139.  
  140. new Vector2(0.125f, 0.5f),
  141. new Vector2(0.125f, 0.6875f),
  142. new Vector2(0.1875f, 0.6875f),
  143. };
  144.  
  145. m.bindposes = new Matrix4x4[]
  146. {
  147. bones[0].worldToLocalMatrix * transform.localToWorldMatrix,
  148. bones[1].worldToLocalMatrix * transform.localToWorldMatrix,
  149. bones[2].worldToLocalMatrix * transform.localToWorldMatrix,
  150. bones[3].worldToLocalMatrix * transform.localToWorldMatrix,
  151. bones[4].worldToLocalMatrix * transform.localToWorldMatrix,
  152. bones[5].worldToLocalMatrix * transform.localToWorldMatrix,
  153. bones[6].worldToLocalMatrix * transform.localToWorldMatrix,
  154. bones[7].worldToLocalMatrix * transform.localToWorldMatrix,
  155. bones[8].worldToLocalMatrix * transform.localToWorldMatrix,
  156. bones[9].worldToLocalMatrix * transform.localToWorldMatrix,
  157. bones[10].worldToLocalMatrix * transform.localToWorldMatrix
  158. };
  159. m.boneWeights = new BoneWeight[]
  160. {
  161. new BoneWeight() { boneIndex0 = 0, weight0 = 1},
  162. new BoneWeight() { boneIndex0 = 0, weight0 = 1},
  163. new BoneWeight() { boneIndex0 = 0, weight0 = 1},
  164.  
  165. new BoneWeight() { boneIndex0 = 1, weight0 = 1},
  166. new BoneWeight() { boneIndex0 = 1, weight0 = 1},
  167. new BoneWeight() { boneIndex0 = 1, weight0 = 1},
  168.  
  169. new BoneWeight() { boneIndex0 = 2, weight0 = 1},
  170. new BoneWeight() { boneIndex0 = 2, weight0 = 1},
  171. new BoneWeight() { boneIndex0 = 2, weight0 = 1},
  172.  
  173. new BoneWeight() { boneIndex0 = 3, weight0 = 1},
  174. new BoneWeight() { boneIndex0 = 3, weight0 = 0.7f},
  175. new BoneWeight() { boneIndex0 = 3, weight0 = 1},
  176.  
  177. new BoneWeight() { boneIndex0 = 4, weight0 = 0.5f},
  178. new BoneWeight() { boneIndex0 = 4, weight0 = 1f},
  179. new BoneWeight() { boneIndex0 = 4, weight0 = 1f},
  180.  
  181. new BoneWeight() { boneIndex0 = 5, weight0 = 1},
  182. new BoneWeight() { boneIndex0 = 5, weight0 = 0.7f},
  183. new BoneWeight() { boneIndex0 = 5, weight0 = 1},
  184.  
  185. new BoneWeight() { boneIndex0 = 6, weight0 = 0.5f},
  186. new BoneWeight() { boneIndex0 = 6, weight0 = 1},
  187. new BoneWeight() { boneIndex0 = 6, weight0 = 1},
  188.  
  189. new BoneWeight() { boneIndex0 = 7, weight0 = 1},
  190. new BoneWeight() { boneIndex0 = 7, weight0 = 1},
  191. new BoneWeight() { boneIndex0 = 7, weight0 = 1},
  192.  
  193. new BoneWeight() { boneIndex0 = 8, weight0 = 0.5f}, //발가락
  194. new BoneWeight() { boneIndex0 = 8, weight0 = 1},
  195. new BoneWeight() { boneIndex0 = 8, weight0 = 1},
  196.  
  197. new BoneWeight() { boneIndex0 = 9, weight0 = 1},
  198. new BoneWeight() { boneIndex0 = 9, weight0 = 1},
  199. new BoneWeight() { boneIndex0 = 9, weight0 = 1},
  200.  
  201. new BoneWeight() { boneIndex0 = 10, weight0 = 0.5f}, // 발가락
  202. new BoneWeight() { boneIndex0 = 10, weight0 = 1},
  203. new BoneWeight() { boneIndex0 = 10, weight0 = 1},
  204. };
  205.  
  206. smr = GetComponent<SkinnedMeshRenderer>();
  207. smr.bones = bones;
  208. smr.sharedMesh = m;
  209. smr.quality = SkinQuality.Bone2;
  210. }
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement