CustomRoleUtility.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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.localScale);
  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 ShowFile()
  231. {
  232. FileStream fs = File.Open("E:/key.key", FileMode.Open);
  233. FileStream fsout = File.Open("E:/keyout9.key", FileMode.Create);
  234. BinaryReader br = new BinaryReader(fs);
  235. BinaryWriter bw = new BinaryWriter(fsout);
  236. Byte[] byData = br.ReadBytes((int)fs.Length);
  237. var t = "NKnFb79Sxk+4Xw284MQleA==";
  238. var pid = "1639047545434X1016017";
  239. fs.Close();
  240. //var iv = new byte[16];
  241. //var key = new byte[16];
  242. //for (int i = 0; i < byData.Length; i++)
  243. //{
  244. // if(i <= 15)
  245. // {
  246. // iv[i] = byData[i];
  247. // var ivx = byData[i].ToString("x");
  248. // Debug.Log(iv[i] + " : " + ivx);
  249. // }
  250. // else
  251. // {
  252. // key[i - 16] = byData[i];
  253. // var keyx = byData[i].ToString("x");
  254. // Debug.Log(key[i - 16] + " : " + keyx);
  255. // }
  256. //}
  257. //var str = DecryptStringFromBytes_Aes(byData, iv, key);
  258. //Debug.Log("result" + str);
  259. Debug.Log(byData.Length);
  260. IList<byte> bData = new List<byte>();
  261. string[] strHexs = new string[16];
  262. int[] intData = {
  263. 245,
  264. 217,
  265. 174,
  266. 210,
  267. 90,
  268. 41,
  269. 167,
  270. 178,
  271. 110,
  272. 47,
  273. 158,
  274. 193,
  275. 35,
  276. 162,
  277. 230,
  278. 97
  279. };
  280. for (int i = 0; i < 16; i++)
  281. {
  282. int a = intData[i];
  283. strHexs[i] = a.ToString("x");
  284. //strHexs[i] = a.ToString();
  285. Debug.Log(a + " : " + a.ToString("x"));
  286. }
  287. foreach (var item in strHexs)
  288. {
  289. Debug.Log(Convert.ToByte(item, 16));
  290. bData.Add(Convert.ToByte(item, 16));
  291. }
  292. bw.Write(bData.ToArray());
  293. fsout.Close();
  294. }
  295. }