CustomRoleUtility.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using UnityEngine;
  7. /// <summary>
  8. /// 可编辑脸部部位
  9. /// </summary>
  10. public enum EditableFacePart
  11. {
  12. eyebrow,
  13. eye,
  14. mousewidth
  15. }
  16. /// <summary>
  17. /// 可编辑身体部位
  18. /// </summary>
  19. public enum EditableBodyPart
  20. {
  21. UpperArm = 0,
  22. LowerArm = 1,
  23. Hand = 2,
  24. UpperLeg = 3,
  25. LowerLeg = 4,
  26. Foot = 5,
  27. All = 6,
  28. Neck = 7,
  29. Clavicle = 8,
  30. Shoulder = 9,
  31. Chest = 10,//胸
  32. Pleural = 11,//胸腔下部
  33. Belly = 12,//肚子
  34. UpperArmUp = 13,
  35. UpperArmDown = 14,
  36. UpperLegUp = 15,
  37. UpperLegDown = 16,
  38. LowerLegUp = 17,
  39. LowerLegDown = 18,
  40. Head = 19,
  41. Acromion = 20,//肩峰
  42. Waist = 21,//腰
  43. Wrist = 22,//手腕
  44. Crotch = 23,//胯部
  45. Hips = 24,//臀部
  46. Knee = 25,//膝盖
  47. Ankle = 26,//脚腕
  48. None = 27,
  49. }
  50. /// <summary>
  51. /// 编辑类型
  52. /// </summary>
  53. public enum ModifyType
  54. {
  55. Length = 0,//长
  56. Width = 1,//宽
  57. Thick = 2,//厚度
  58. LengthWidthThick = 3,//长宽厚
  59. Angle = 4,//角度
  60. UpDown = 5,//上下
  61. LeftRight = 6,//左右
  62. ForwardBehind = 7,//前后
  63. }
  64. public static class CustomRoleUtility
  65. {
  66. public static void UpdateBoneScale(Animator ani,EditableBodyPart part, Vector3 scale,bool keepChildWorldScale, float value)
  67. {
  68. Transform[] transList = GetRelativeTransform(ani,part);
  69. Vector3 beforeScale = Vector3.one;
  70. if(transList == null)
  71. {
  72. return;
  73. }
  74. for (int i = 0; i < transList.Length; i++)
  75. {
  76. var trans = transList[i];
  77. if(trans == null)
  78. {
  79. continue;
  80. }
  81. beforeScale = trans.localScale;
  82. var world_l = trans.lossyScale;
  83. if (scale.x == 1) trans.SetLocalScaleX(trans.localScale.x * value / world_l.x);
  84. if (scale.y == 1) trans.SetLocalScaleY(trans.localScale.y * value / world_l.y);
  85. if (scale.z == 1) trans.SetLocalScaleZ(trans.localScale.z * value / world_l.z);
  86. //修改子物体的缩放
  87. if (!keepChildWorldScale)
  88. {
  89. continue;
  90. }
  91. var lcount = trans.childCount;
  92. for (int j = 0; j < lcount; j++)
  93. {
  94. var childTrans = trans.GetChild(j);
  95. var oldScale = childTrans.localScale;
  96. if (scale.x == 1) childTrans.SetLocalScaleX(oldScale.x * beforeScale.x / value);
  97. if (scale.y == 1) childTrans.SetLocalScaleY(oldScale.y * beforeScale.y / value);
  98. if (scale.z == 1) childTrans.SetLocalScaleZ(oldScale.z * beforeScale.z / value);
  99. }
  100. }
  101. }
  102. public static Transform[] GetRelativeTransform(Animator ani,EditableBodyPart part)
  103. {
  104. Transform[] result = null;
  105. switch (part)
  106. {
  107. case EditableBodyPart.UpperArm:
  108. result = new Transform[2];
  109. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftUpperArm);
  110. result[1] = ani.GetBoneTransform(HumanBodyBones.RightUpperArm);
  111. break;
  112. case EditableBodyPart.LowerArm:
  113. result = new Transform[2];
  114. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftLowerArm);
  115. result[1] = ani.GetBoneTransform(HumanBodyBones.RightLowerArm);
  116. break;
  117. case EditableBodyPart.Hand:
  118. result = new Transform[2];
  119. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftHand);
  120. result[1] = ani.GetBoneTransform(HumanBodyBones.RightHand);
  121. break;
  122. case EditableBodyPart.UpperLeg:
  123. result = new Transform[2];
  124. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
  125. result[1] = ani.GetBoneTransform(HumanBodyBones.RightUpperLeg);
  126. break;
  127. case EditableBodyPart.LowerLeg:
  128. result = new Transform[2];
  129. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
  130. result[1] = ani.GetBoneTransform(HumanBodyBones.RightLowerLeg);
  131. break;
  132. case EditableBodyPart.Foot:
  133. result = new Transform[2];
  134. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftFoot);
  135. result[1] = ani.GetBoneTransform(HumanBodyBones.RightFoot);
  136. break;
  137. case EditableBodyPart.All:
  138. result = new Transform[1];
  139. result[0] = ani.GetBoneTransform(HumanBodyBones.Spine);
  140. break;
  141. case EditableBodyPart.Neck:
  142. result = new Transform[1];
  143. result[0] = ani.GetBoneTransform(HumanBodyBones.Neck);
  144. break;
  145. case EditableBodyPart.Clavicle:
  146. result = new Transform[1];
  147. //result[0] = ani.GetBoneTransform(HumanBodyBones.cl);
  148. break;
  149. case EditableBodyPart.Shoulder:
  150. result = new Transform[2];
  151. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftShoulder);
  152. result[1] = ani.GetBoneTransform(HumanBodyBones.RightShoulder);
  153. break;
  154. case EditableBodyPart.Chest:
  155. result = new Transform[2];
  156. var p = ani.GetBoneTransform(HumanBodyBones.Chest);
  157. result[0] = GetChild(p, "Chest_L");
  158. result[1] = GetChild(p, "Chest_R");
  159. break;
  160. case EditableBodyPart.Pleural:
  161. break;
  162. case EditableBodyPart.Belly:
  163. break;
  164. case EditableBodyPart.UpperArmUp:
  165. break;
  166. case EditableBodyPart.UpperArmDown:
  167. break;
  168. case EditableBodyPart.UpperLegUp:
  169. break;
  170. case EditableBodyPart.UpperLegDown:
  171. break;
  172. case EditableBodyPart.LowerLegUp:
  173. break;
  174. case EditableBodyPart.LowerLegDown:
  175. break;
  176. case EditableBodyPart.Head:
  177. result = new Transform[1];
  178. result[0] = ani.GetBoneTransform(HumanBodyBones.Head);
  179. break;
  180. case EditableBodyPart.Acromion:
  181. break;
  182. case EditableBodyPart.Waist:
  183. break;
  184. case EditableBodyPart.Wrist:
  185. break;
  186. case EditableBodyPart.Crotch:
  187. break;
  188. case EditableBodyPart.Hips:
  189. break;
  190. case EditableBodyPart.Knee:
  191. break;
  192. case EditableBodyPart.Ankle:
  193. break;
  194. case EditableBodyPart.None:
  195. break;
  196. default:
  197. break;
  198. }
  199. return result;
  200. }
  201. public static void GetNormalAniBonesScale(Animator ani,ref Dictionary<string, Vector3> boneDic)
  202. {
  203. for (int i = 0; i < Enum.GetValues(typeof(HumanBodyBones)).Length - 1; i++)
  204. {
  205. var trans = ani.GetBoneTransform((HumanBodyBones)i);
  206. if(trans)
  207. {
  208. boneDic.Add(trans.name, trans.lossyScale);
  209. }
  210. }
  211. }
  212. public static Transform GetChild(Transform trans,string name)
  213. {
  214. for (int i = 0; i < trans.childCount; i++)
  215. {
  216. if(trans.GetChild(i).name == name)
  217. {
  218. return trans.GetChild(i);
  219. }else
  220. {
  221. var childTrans = GetChild(trans.GetChild(i),name);
  222. if(childTrans != null)
  223. {
  224. return childTrans;
  225. }
  226. }
  227. }
  228. return null;
  229. }
  230. public static void ChangeCloth(SkinnedMeshRenderer before,SkinnedMeshRenderer now,Transform[] transforms)
  231. {
  232. if (before == null && now == null)
  233. {
  234. return;
  235. }
  236. if(now == null)
  237. {
  238. if(before)
  239. {
  240. before.gameObject.SetActive(false);
  241. }
  242. return;
  243. }
  244. //Transform[] transforms = skeleton.GetComponentsInChildren<Transform>(false);
  245. List<Transform> boneList = new List<Transform>();
  246. SkinnedMeshRenderer smr = null;
  247. if(before)
  248. {
  249. smr = before;
  250. before.gameObject.SetActive(true);
  251. }else
  252. {
  253. smr = now;
  254. }
  255. foreach (Transform bone in smr.bones)
  256. {
  257. foreach (Transform item in transforms)
  258. {
  259. if (item.name != bone.name)
  260. continue;
  261. boneList.Add(item);
  262. break;
  263. }
  264. }
  265. smr.sharedMesh = now.sharedMesh;
  266. smr.bones = boneList.ToArray();
  267. smr.materials = now.sharedMaterials;
  268. smr.rootBone = smr.rootBone;
  269. }
  270. public static void ShowFile()
  271. {
  272. FileStream fs = File.Open("E:/key.key", FileMode.Open);
  273. FileStream fsout = File.Open("E:/keyout4.key", FileMode.Create);
  274. BinaryReader br = new BinaryReader(fs);
  275. BinaryWriter bw = new BinaryWriter(fsout);
  276. Byte[] byData = br.ReadBytes((int)fs.Length);
  277. var t = "NKnFb79Sxk+4Xw284MQleA==";
  278. var pid = "1639047545434X1016017";
  279. fs.Close();
  280. //var iv = new byte[16];
  281. //var key = new byte[16];
  282. //for (int i = 0; i < byData.Length; i++)
  283. //{
  284. // if(i <= 15)
  285. // {
  286. // iv[i] = byData[i];
  287. // var ivx = byData[i].ToString("x");
  288. // Debug.Log(iv[i] + " : " + ivx);
  289. // }
  290. // else
  291. // {
  292. // key[i - 16] = byData[i];
  293. // var keyx = byData[i].ToString("x");
  294. // Debug.Log(key[i - 16] + " : " + keyx);
  295. // }
  296. //}
  297. //var str = DecryptStringFromBytes_Aes(byData, iv, key);
  298. //Debug.Log("result" + str);
  299. Debug.Log(byData.Length);
  300. IList<byte> bData = new List<byte>();
  301. string[] strHexs = new string[16];
  302. int[] intData = {
  303. 52,
  304. 202,
  305. 48,
  306. 138,
  307. 68,
  308. 75,
  309. 239,
  310. 159,
  311. 27,
  312. 50,
  313. 70,
  314. 255,
  315. 10,
  316. 248,
  317. 131,
  318. 73
  319. };
  320. for (int i = 0; i < 16; i++)
  321. {
  322. int a = intData[i];
  323. strHexs[i] = a.ToString("x");
  324. //strHexs[i] = a.ToString();
  325. Debug.Log(a + " : " + a.ToString("x"));
  326. }
  327. foreach (var item in strHexs)
  328. {
  329. Debug.Log(Convert.ToByte(item, 16));
  330. bData.Add(Convert.ToByte(item, 16));
  331. }
  332. bw.Write(bData.ToArray());
  333. fsout.Close();
  334. }
  335. }