CustomRoleUtility.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. None = 20,
  42. }
  43. /// <summary>
  44. /// 编辑类型
  45. /// </summary>
  46. public enum ModifyType
  47. {
  48. Length = 0,//长
  49. Width = 1,//宽
  50. Thick = 2,//厚度
  51. LengthWidthThick = 3,//长宽厚
  52. Angle = 4,//角度
  53. UpDown = 5,//上下
  54. LeftRight = 6,//左右
  55. ForwardBehind = 7,//前后
  56. }
  57. public static class CustomRoleUtility
  58. {
  59. public static void UpdateBoneScale(Animator ani,EditableBodyPart part,float value)
  60. {
  61. Transform transL = null;
  62. Transform transR = null;
  63. Vector3 beforeScale = Vector3.one;
  64. List<Transform> childList = new List<Transform>();
  65. bool keepChildWorldScale = false;
  66. switch (part)
  67. {
  68. case EditableBodyPart.UpperArm:
  69. transL = ani.GetBoneTransform(HumanBodyBones.LeftUpperArm);
  70. transR = ani.GetBoneTransform(HumanBodyBones.RightUpperArm);
  71. keepChildWorldScale = true;
  72. break;
  73. case EditableBodyPart.LowerArm:
  74. transL = ani.GetBoneTransform(HumanBodyBones.LeftLowerArm);
  75. transR = ani.GetBoneTransform(HumanBodyBones.RightLowerArm);
  76. break;
  77. case EditableBodyPart.Hand:
  78. transL = ani.GetBoneTransform(HumanBodyBones.LeftHand);
  79. transR = ani.GetBoneTransform(HumanBodyBones.RightHand);
  80. break;
  81. case EditableBodyPart.UpperLeg:
  82. transL = ani.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
  83. transR = ani.GetBoneTransform(HumanBodyBones.RightUpperLeg);
  84. keepChildWorldScale = true;
  85. break;
  86. case EditableBodyPart.LowerLeg:
  87. transL = ani.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
  88. transR = ani.GetBoneTransform(HumanBodyBones.RightLowerLeg);
  89. break;
  90. case EditableBodyPart.Foot:
  91. transL = ani.GetBoneTransform(HumanBodyBones.LeftFoot);
  92. transR = ani.GetBoneTransform(HumanBodyBones.RightFoot);
  93. break;
  94. case EditableBodyPart.None:
  95. break;
  96. default:
  97. break;
  98. }
  99. if(transL != null)
  100. {
  101. beforeScale = transL.localScale;
  102. var world_l = transL.lossyScale;
  103. transL.SetLocalScaleX(transL.localScale.x * value / world_l.x);
  104. transL.SetLocalScaleY(transL.localScale.y * value / world_l.y);
  105. transL.SetLocalScaleZ(transL.localScale.z * value / world_l.z);
  106. var lcount = transL.childCount;
  107. for (int i = 0; i < lcount; i++)
  108. {
  109. childList.Add(transL.GetChild(i));
  110. }
  111. }
  112. if(transR != null)
  113. {
  114. beforeScale = transR.localScale;
  115. var world_r = transR.lossyScale;
  116. transR.SetLocalScaleX(transR.localScale.x * value / world_r.x);
  117. transR.SetLocalScaleY(transR.localScale.y * value / world_r.y);
  118. transR.SetLocalScaleZ(transR.localScale.z * value / world_r.z);
  119. var rcount = transR.childCount;
  120. for (int i = 0; i < rcount; i++)
  121. {
  122. childList.Add(transR.GetChild(i));
  123. }
  124. }
  125. if(!keepChildWorldScale)
  126. {
  127. return;
  128. }
  129. for (int i = 0; i < childList.Count; i++)
  130. {
  131. var childTrans = childList[i];
  132. var oldScale = childTrans.localScale;
  133. childTrans.SetLocalScaleX(oldScale.x * beforeScale.x / value);
  134. childTrans.SetLocalScaleY(oldScale.y * beforeScale.y / value);
  135. childTrans.SetLocalScaleZ(oldScale.z * beforeScale.z / value);
  136. }
  137. }
  138. public static void GetNormalAniBonesScale(Animator ani,ref Dictionary<string, Vector3> boneDic)
  139. {
  140. for (int i = 0; i < Enum.GetValues(typeof(HumanBodyBones)).Length - 1; i++)
  141. {
  142. var trans = ani.GetBoneTransform((HumanBodyBones)i);
  143. if(trans)
  144. {
  145. boneDic.Add(trans.name, trans.localScale);
  146. }
  147. }
  148. }
  149. public static Transform GetChild(Transform trans,string name)
  150. {
  151. for (int i = 0; i < trans.childCount; i++)
  152. {
  153. if(trans.GetChild(i).name == name)
  154. {
  155. return trans.GetChild(i);
  156. }else
  157. {
  158. var childTrans = GetChild(trans.GetChild(i),name);
  159. if(childTrans != null)
  160. {
  161. return childTrans;
  162. }
  163. }
  164. }
  165. return null;
  166. }
  167. public static void ShowFile()
  168. {
  169. FileStream fs = File.Open("E:/key.key", FileMode.Open);
  170. FileStream fsout = File.Open("E:/keyout9.key", FileMode.Create);
  171. BinaryReader br = new BinaryReader(fs);
  172. BinaryWriter bw = new BinaryWriter(fsout);
  173. Byte[] byData = br.ReadBytes((int)fs.Length);
  174. var t = "NKnFb79Sxk+4Xw284MQleA==";
  175. var pid = "1639047545434X1016017";
  176. fs.Close();
  177. //var iv = new byte[16];
  178. //var key = new byte[16];
  179. //for (int i = 0; i < byData.Length; i++)
  180. //{
  181. // if(i <= 15)
  182. // {
  183. // iv[i] = byData[i];
  184. // var ivx = byData[i].ToString("x");
  185. // Debug.Log(iv[i] + " : " + ivx);
  186. // }
  187. // else
  188. // {
  189. // key[i - 16] = byData[i];
  190. // var keyx = byData[i].ToString("x");
  191. // Debug.Log(key[i - 16] + " : " + keyx);
  192. // }
  193. //}
  194. //var str = DecryptStringFromBytes_Aes(byData, iv, key);
  195. //Debug.Log("result" + str);
  196. Debug.Log(byData.Length);
  197. IList<byte> bData = new List<byte>();
  198. string[] strHexs = new string[16];
  199. int[] intData = {
  200. 245,
  201. 217,
  202. 174,
  203. 210,
  204. 90,
  205. 41,
  206. 167,
  207. 178,
  208. 110,
  209. 47,
  210. 158,
  211. 193,
  212. 35,
  213. 162,
  214. 230,
  215. 97
  216. };
  217. for (int i = 0; i < 16; i++)
  218. {
  219. int a = intData[i];
  220. strHexs[i] = a.ToString("x");
  221. //strHexs[i] = a.ToString();
  222. Debug.Log(a + " : " + a.ToString("x"));
  223. }
  224. foreach (var item in strHexs)
  225. {
  226. Debug.Log(Convert.ToByte(item, 16));
  227. bData.Add(Convert.ToByte(item, 16));
  228. }
  229. bw.Write(bData.ToArray());
  230. fsout.Close();
  231. }
  232. }