IKScriptHelper.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using kt.Utility;
  5. using UnityEngine;
  6. namespace kt.ik
  7. {
  8. public static class IKScriptHelper
  9. {
  10. public static IKAttachParam GetIKAttachParam(KagTagSupport tagData, Maid src_chara, Maid target_chara = null)
  11. {
  12. IKAttachParam ikattachParam = new IKAttachParam(src_chara, target_chara);
  13. IKScriptHelper.SetIKAttachParam(ikattachParam, tagData);
  14. return ikattachParam;
  15. }
  16. public static void SetIKAttachParam(IKAttachParam param, KagTagSupport tagData)
  17. {
  18. param.offset = Vector3.zero;
  19. if (tagData.IsValid("offsetx"))
  20. {
  21. param.offset.x = tagData.GetTagProperty("offsetx").AsReal();
  22. }
  23. if (tagData.IsValid("offsety"))
  24. {
  25. param.offset.y = tagData.GetTagProperty("offsety").AsReal();
  26. }
  27. if (tagData.IsValid("offsetz"))
  28. {
  29. param.offset.z = tagData.GetTagProperty("offsetz").AsReal();
  30. }
  31. param.attachType = ((!param.srcChara.body0.IsCrcBody) ? AIKCtrl.IKAttachType.Point : AIKCtrl.IKAttachType.NewPoint);
  32. if (tagData.IsValid("attach_type"))
  33. {
  34. string value = tagData.GetTagProperty("attach_type").AsString();
  35. param.attachType = (AIKCtrl.IKAttachType)Enum.Parse(typeof(AIKCtrl.IKAttachType), value);
  36. if (param.srcChara.body0.IsCrcBody && param.attachType == AIKCtrl.IKAttachType.Point)
  37. {
  38. param.attachType = AIKCtrl.IKAttachType.NewPoint;
  39. }
  40. }
  41. if (param.attachType == AIKCtrl.IKAttachType.NewPoint)
  42. {
  43. param.posOffsetType = AIKCtrl.PosOffsetType.OffsetTarget;
  44. if (tagData.IsValid("offset_world"))
  45. {
  46. param.posOffsetType = AIKCtrl.PosOffsetType.OffsetWorld;
  47. }
  48. else if (tagData.IsValid("offset_bone"))
  49. {
  50. param.posOffsetType = AIKCtrl.PosOffsetType.OffsetBone;
  51. }
  52. }
  53. if (tagData.IsValid("blend"))
  54. {
  55. param.blendTime = MathUtility.MillisecondToSecond(tagData.GetTagProperty("blend").AsInteger());
  56. }
  57. else if (tagData.IsValid("blendtime"))
  58. {
  59. param.blendTime = MathUtility.MillisecondToSecond(tagData.GetTagProperty("blendtime").AsInteger());
  60. }
  61. else
  62. {
  63. param.blendTime = param.srcChara.fullBodyIK.blendTime;
  64. }
  65. if (tagData.IsValid("disable"))
  66. {
  67. string[] array = tagData.GetTagProperty("disable").AsString().Split(new char[]
  68. {
  69. ','
  70. });
  71. int i = 0;
  72. while (i < array.Length)
  73. {
  74. string text = array[i];
  75. string text2 = text.ToLower();
  76. if (text2 != null)
  77. {
  78. if (!(text2 == "x"))
  79. {
  80. if (!(text2 == "y"))
  81. {
  82. if (text2 == "z")
  83. {
  84. param.offsetEnable.enableZ = false;
  85. }
  86. }
  87. else
  88. {
  89. param.offsetEnable.enableY = false;
  90. }
  91. }
  92. else
  93. {
  94. param.offsetEnable.enableX = false;
  95. }
  96. }
  97. IL_288:
  98. i++;
  99. continue;
  100. goto IL_288;
  101. }
  102. }
  103. param.doAnimation = false;
  104. if (tagData.IsValid("do_animation"))
  105. {
  106. param.doAnimation = true;
  107. }
  108. param.bodyPull = (param.attachType == AIKCtrl.IKAttachType.NewPoint);
  109. if (param.attachType == AIKCtrl.IKAttachType.NewPoint)
  110. {
  111. param.bodyPull = !tagData.IsValid("pull_off");
  112. }
  113. }
  114. public static InsertIKParam GetInsertIKParam(KagTagSupport tagData, Maid src_chara = null, Maid target_chara = null)
  115. {
  116. InsertIKParam insertIKParam = new InsertIKParam(src_chara, target_chara);
  117. IKScriptHelper.SetInsertIKParam(insertIKParam, tagData);
  118. return insertIKParam;
  119. }
  120. public static void SetInsertIKParam(InsertIKParam param, KagTagSupport tagData)
  121. {
  122. IKScriptHelper.SetIKAttachParam(param, tagData);
  123. param.insertBefore = MathUtility.Vec3Parse(tagData.GetTagProperty("insert_before").AsString(), ',').normalized;
  124. param.insertAfter = MathUtility.Vec3Parse(tagData.GetTagProperty("insert_after").AsString(), ',').normalized;
  125. if (param.attachTarget && AutoKupaCtrl.InsertBoneMorphDic.ContainsKey(param.attachTarget.name))
  126. {
  127. AutoKupaCtrl.MorphType morph_type = AutoKupaCtrl.InsertBoneMorphDic[param.attachTarget.name];
  128. param.kupaCtrl = param.targetChara.body0.GetKupaCtrl(morph_type);
  129. if (param.kupaCtrl != null)
  130. {
  131. param.kupaCtrl.SetInsertParamFromScript(tagData);
  132. }
  133. }
  134. }
  135. public static PenisIKParam GetPenisIKParam(KagTagSupport tagData, Maid src_chara, Maid target_chara)
  136. {
  137. PenisIKParam penisIKParam = new PenisIKParam(src_chara, target_chara);
  138. IKScriptHelper.SetPenisIKPatam(penisIKParam, tagData);
  139. return penisIKParam;
  140. }
  141. public static void SetPenisIKPatam(PenisIKParam param, KagTagSupport tagData)
  142. {
  143. IKScriptHelper.SetInsertIKParam(param, tagData);
  144. param.sensorLength = 0f;
  145. if (tagData.IsValid("sensorlength"))
  146. {
  147. param.sensorLength = tagData.GetTagProperty("sensorlength").AsReal();
  148. }
  149. param.isNotEscape = tagData.IsValid("notescape");
  150. param.isForciblyBend = tagData.IsValid("forcebend");
  151. param.alwaysLookTarget = tagData.IsValid("alwayslook");
  152. if (tagData.IsValid("scaling"))
  153. {
  154. string[] array = tagData.GetTagProperty("scaling").AsString().Split(new char[]
  155. {
  156. ' '
  157. });
  158. foreach (string text in array)
  159. {
  160. string[] array3 = text.Split(new char[]
  161. {
  162. ':'
  163. });
  164. string key = array3[0];
  165. float value = MathUtility.PercentageToRatio(int.Parse(array3[1]), false);
  166. param.boneNameScaleValPair.Add(new KeyValuePair<string, float>(key, value));
  167. }
  168. }
  169. if (tagData.IsValid("motionctrlbone"))
  170. {
  171. param.motionCtrlBoneName = tagData.GetTagProperty("motionctrlbone").AsString();
  172. if (tagData.IsValid("motionctrlweight"))
  173. {
  174. param.motionCtrlWeight = MathUtility.PercentageToRatio(tagData.GetTagProperty("motionctrlweight").AsInteger(), false);
  175. }
  176. }
  177. }
  178. public static BodyOffsetIKParam GetBodyIKParam(KagTagSupport tagData, Maid src_chara, Maid target_chara = null)
  179. {
  180. BodyOffsetIKParam bodyOffsetIKParam = new BodyOffsetIKParam(src_chara, target_chara);
  181. IKScriptHelper.SetBodyIKPatam(bodyOffsetIKParam, tagData);
  182. return bodyOffsetIKParam;
  183. }
  184. public static void SetBodyIKPatam(BodyOffsetIKParam param, KagTagSupport tagData)
  185. {
  186. IKScriptHelper.SetIKAttachParam(param, tagData);
  187. param.attachType = AIKCtrl.IKAttachType.NewPoint;
  188. param.posOffsetType = AIKCtrl.PosOffsetType.OffsetTarget;
  189. if (tagData.IsValid("heighttype"))
  190. {
  191. param.heightFitType = (IKBodyOffsetCtrl.HeightFitType)Enum.Parse(typeof(IKBodyOffsetCtrl.HeightFitType), tagData.GetTagProperty("heighttype").AsString());
  192. }
  193. param.posBaseBoneName = tagData.GetTagProperty("srcbone").AsString();
  194. if (tagData.IsValid("addoffset"))
  195. {
  196. param.addOffset = MathUtility.Vec3Parse(tagData.GetTagProperty("addoffset").AsString(), ',');
  197. }
  198. }
  199. public static string ConvertColliderNameToIKName(string name)
  200. {
  201. string text = Regex.Replace(name, "左|右", string.Empty);
  202. if (text != null)
  203. {
  204. if (!(text == "上腕"))
  205. {
  206. if (!(text == "前腕"))
  207. {
  208. if (!(text == "腿"))
  209. {
  210. if (text == "脛")
  211. {
  212. name = name.Replace("脛", "足");
  213. }
  214. }
  215. else
  216. {
  217. name = name.Replace("腿", "膝");
  218. }
  219. }
  220. else
  221. {
  222. name = name.Replace("前腕", "手");
  223. }
  224. }
  225. else
  226. {
  227. name = name.Replace("上腕", "肘");
  228. }
  229. }
  230. return name;
  231. }
  232. }
  233. }