CustomRoleUtility.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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,float value)
  67. {
  68. Transform transL = null;
  69. Transform transR = null;
  70. Vector3 beforeScale = Vector3.one;
  71. List<Transform> childList = new List<Transform>();
  72. bool keepChildWorldScale = false;
  73. switch (part)
  74. {
  75. case EditableBodyPart.UpperArm:
  76. transL = ani.GetBoneTransform(HumanBodyBones.LeftUpperArm);
  77. transR = ani.GetBoneTransform(HumanBodyBones.RightUpperArm);
  78. break;
  79. case EditableBodyPart.LowerArm:
  80. transL = ani.GetBoneTransform(HumanBodyBones.LeftLowerArm);
  81. transR = ani.GetBoneTransform(HumanBodyBones.RightLowerArm);
  82. break;
  83. case EditableBodyPart.Hand:
  84. transL = ani.GetBoneTransform(HumanBodyBones.LeftHand);
  85. transR = ani.GetBoneTransform(HumanBodyBones.RightHand);
  86. break;
  87. case EditableBodyPart.UpperLeg:
  88. transL = ani.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
  89. transR = ani.GetBoneTransform(HumanBodyBones.RightUpperLeg);
  90. keepChildWorldScale = true;
  91. break;
  92. case EditableBodyPart.LowerLeg:
  93. transL = ani.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
  94. transR = ani.GetBoneTransform(HumanBodyBones.RightLowerLeg);
  95. break;
  96. case EditableBodyPart.Foot:
  97. transL = ani.GetBoneTransform(HumanBodyBones.LeftFoot);
  98. transR = ani.GetBoneTransform(HumanBodyBones.RightFoot);
  99. break;
  100. case EditableBodyPart.None:
  101. break;
  102. default:
  103. break;
  104. }
  105. if(transL != null)
  106. {
  107. beforeScale = transL.localScale;
  108. var world_l = transL.lossyScale;
  109. transL.SetLocalScaleX(transL.localScale.x * value / world_l.x);
  110. transL.SetLocalScaleY(transL.localScale.y * value / world_l.y);
  111. transL.SetLocalScaleZ(transL.localScale.z * value / world_l.z);
  112. var lcount = transL.childCount;
  113. for (int i = 0; i < lcount; i++)
  114. {
  115. childList.Add(transL.GetChild(i));
  116. }
  117. }
  118. if(transR != null)
  119. {
  120. beforeScale = transR.localScale;
  121. var world_r = transR.lossyScale;
  122. transR.SetLocalScaleX(transR.localScale.x * value / world_r.x);
  123. transR.SetLocalScaleY(transR.localScale.y * value / world_r.y);
  124. transR.SetLocalScaleZ(transR.localScale.z * value / world_r.z);
  125. var rcount = transR.childCount;
  126. for (int i = 0; i < rcount; i++)
  127. {
  128. childList.Add(transR.GetChild(i));
  129. }
  130. }
  131. if(!keepChildWorldScale)
  132. {
  133. return;
  134. }
  135. for (int i = 0; i < childList.Count; i++)
  136. {
  137. var childTrans = childList[i];
  138. var oldScale = childTrans.localScale;
  139. childTrans.SetLocalScaleX(oldScale.x * beforeScale.x / value);
  140. childTrans.SetLocalScaleY(oldScale.y * beforeScale.y / value);
  141. childTrans.SetLocalScaleZ(oldScale.z * beforeScale.z / value);
  142. }
  143. }
  144. public static Transform[] GetRelativeTransform(Animator ani,EditableBodyPart part)
  145. {
  146. Transform[] result = null;
  147. switch (part)
  148. {
  149. case EditableBodyPart.UpperArm:
  150. result = new Transform[2];
  151. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftUpperArm);
  152. result[1] = ani.GetBoneTransform(HumanBodyBones.RightUpperArm);
  153. break;
  154. case EditableBodyPart.LowerArm:
  155. result = new Transform[2];
  156. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftLowerArm);
  157. result[1] = ani.GetBoneTransform(HumanBodyBones.RightLowerArm);
  158. break;
  159. case EditableBodyPart.Hand:
  160. result = new Transform[2];
  161. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftHand);
  162. result[1] = ani.GetBoneTransform(HumanBodyBones.RightHand);
  163. break;
  164. case EditableBodyPart.UpperLeg:
  165. result = new Transform[2];
  166. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
  167. result[1] = ani.GetBoneTransform(HumanBodyBones.RightUpperLeg);
  168. break;
  169. case EditableBodyPart.LowerLeg:
  170. result = new Transform[2];
  171. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
  172. result[1] = ani.GetBoneTransform(HumanBodyBones.RightLowerLeg);
  173. break;
  174. case EditableBodyPart.Foot:
  175. result = new Transform[2];
  176. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftFoot);
  177. result[1] = ani.GetBoneTransform(HumanBodyBones.RightFoot);
  178. break;
  179. case EditableBodyPart.All:
  180. result = new Transform[1];
  181. result[0] = ani.GetBoneTransform(HumanBodyBones.Spine);
  182. break;
  183. case EditableBodyPart.Neck:
  184. result = new Transform[1];
  185. result[0] = ani.GetBoneTransform(HumanBodyBones.Neck);
  186. break;
  187. case EditableBodyPart.Clavicle:
  188. result = new Transform[1];
  189. //result[0] = ani.GetBoneTransform(HumanBodyBones.cl);
  190. break;
  191. case EditableBodyPart.Shoulder:
  192. result = new Transform[2];
  193. result[0] = ani.GetBoneTransform(HumanBodyBones.LeftShoulder);
  194. result[1] = ani.GetBoneTransform(HumanBodyBones.RightShoulder);
  195. break;
  196. case EditableBodyPart.Chest:
  197. result = new Transform[2];
  198. var p = ani.GetBoneTransform(HumanBodyBones.Chest);
  199. result[0] = GetChild(p, "Chest_L");
  200. result[1] = GetChild(p, "Chest_R");
  201. break;
  202. case EditableBodyPart.Pleural:
  203. break;
  204. case EditableBodyPart.Belly:
  205. break;
  206. case EditableBodyPart.UpperArmUp:
  207. break;
  208. case EditableBodyPart.UpperArmDown:
  209. break;
  210. case EditableBodyPart.UpperLegUp:
  211. break;
  212. case EditableBodyPart.UpperLegDown:
  213. break;
  214. case EditableBodyPart.LowerLegUp:
  215. break;
  216. case EditableBodyPart.LowerLegDown:
  217. break;
  218. case EditableBodyPart.Head:
  219. result = new Transform[1];
  220. result[0] = ani.GetBoneTransform(HumanBodyBones.Head);
  221. break;
  222. case EditableBodyPart.Acromion:
  223. break;
  224. case EditableBodyPart.Waist:
  225. break;
  226. case EditableBodyPart.Wrist:
  227. break;
  228. case EditableBodyPart.Crotch:
  229. break;
  230. case EditableBodyPart.Hips:
  231. break;
  232. case EditableBodyPart.Knee:
  233. break;
  234. case EditableBodyPart.Ankle:
  235. break;
  236. case EditableBodyPart.None:
  237. break;
  238. default:
  239. break;
  240. }
  241. return result;
  242. }
  243. public static void GetNormalAniBonesScale(Animator ani,ref Dictionary<string, Vector3> boneDic)
  244. {
  245. for (int i = 0; i < Enum.GetValues(typeof(HumanBodyBones)).Length - 1; i++)
  246. {
  247. var trans = ani.GetBoneTransform((HumanBodyBones)i);
  248. if(trans)
  249. {
  250. boneDic.Add(trans.name, trans.localScale);
  251. }
  252. }
  253. }
  254. public static Transform GetChild(Transform trans,string name)
  255. {
  256. for (int i = 0; i < trans.childCount; i++)
  257. {
  258. if(trans.GetChild(i).name == name)
  259. {
  260. return trans.GetChild(i);
  261. }else
  262. {
  263. var childTrans = GetChild(trans.GetChild(i),name);
  264. if(childTrans != null)
  265. {
  266. return childTrans;
  267. }
  268. }
  269. }
  270. return null;
  271. }
  272. public static void ShowFile()
  273. {
  274. FileStream fs = File.Open("E:/key.key", FileMode.Open);
  275. FileStream fsout = File.Open("E:/keyout9.key", FileMode.Create);
  276. BinaryReader br = new BinaryReader(fs);
  277. BinaryWriter bw = new BinaryWriter(fsout);
  278. Byte[] byData = br.ReadBytes((int)fs.Length);
  279. var t = "NKnFb79Sxk+4Xw284MQleA==";
  280. var pid = "1639047545434X1016017";
  281. fs.Close();
  282. //var iv = new byte[16];
  283. //var key = new byte[16];
  284. //for (int i = 0; i < byData.Length; i++)
  285. //{
  286. // if(i <= 15)
  287. // {
  288. // iv[i] = byData[i];
  289. // var ivx = byData[i].ToString("x");
  290. // Debug.Log(iv[i] + " : " + ivx);
  291. // }
  292. // else
  293. // {
  294. // key[i - 16] = byData[i];
  295. // var keyx = byData[i].ToString("x");
  296. // Debug.Log(key[i - 16] + " : " + keyx);
  297. // }
  298. //}
  299. //var str = DecryptStringFromBytes_Aes(byData, iv, key);
  300. //Debug.Log("result" + str);
  301. Debug.Log(byData.Length);
  302. IList<byte> bData = new List<byte>();
  303. string[] strHexs = new string[16];
  304. int[] intData = {
  305. 245,
  306. 217,
  307. 174,
  308. 210,
  309. 90,
  310. 41,
  311. 167,
  312. 178,
  313. 110,
  314. 47,
  315. 158,
  316. 193,
  317. 35,
  318. 162,
  319. 230,
  320. 97
  321. };
  322. for (int i = 0; i < 16; i++)
  323. {
  324. int a = intData[i];
  325. strHexs[i] = a.ToString("x");
  326. //strHexs[i] = a.ToString();
  327. Debug.Log(a + " : " + a.ToString("x"));
  328. }
  329. foreach (var item in strHexs)
  330. {
  331. Debug.Log(Convert.ToByte(item, 16));
  332. bData.Add(Convert.ToByte(item, 16));
  333. }
  334. bw.Write(bData.ToArray());
  335. fsout.Close();
  336. }
  337. }