IKCtrlData.cs 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. using System;
  2. using UnityEngine;
  3. public abstract class IKCtrlData
  4. {
  5. public IKCtrlData(FullBodyIKCtrl ik_ctrl, Transform tgt_bone, bool use_old = false, bool attach_ik = false)
  6. {
  7. this.MyIKCtrl = ik_ctrl;
  8. this.UseOldIK = use_old;
  9. this.m_TargetBone = tgt_bone;
  10. this.m_AttachPointIK = attach_ik;
  11. string text = (!this.MyIKCtrl.TgtChara.boMAN) ? "Bip01" : "ManBip";
  12. string name = this.m_TargetBone.name;
  13. Transform transform = this.MyIKCtrl.IKTgtRoot.Find(name);
  14. if (!transform)
  15. {
  16. transform = new GameObject(name).transform;
  17. transform.transform.SetParent(this.MyIKCtrl.IKTgtRoot, false);
  18. GameObject gameObject = new GameObject("IKTarget");
  19. gameObject.transform.SetParent(transform.transform, false);
  20. this.m_IKTarget = gameObject.transform;
  21. }
  22. else
  23. {
  24. this.m_IKTarget = transform.Find("IKTarget");
  25. }
  26. this.m_BoneTgtPair = new IKCtrlData.BoneTgtPair(this.TargetBone, this.m_IKTarget);
  27. this.IkCmoInit();
  28. this.m_PointIKData.IKCtrl = ik_ctrl;
  29. this.m_RotateIKData.IKCtrl = ik_ctrl;
  30. }
  31. public IKCtrlData.IKSettingData PointIK
  32. {
  33. get
  34. {
  35. return this.m_PointIKData;
  36. }
  37. }
  38. public IKCtrlData.IKSettingData RotateIK
  39. {
  40. get
  41. {
  42. return this.m_RotateIKData;
  43. }
  44. }
  45. public TBody.IKCMO IKCmo
  46. {
  47. get
  48. {
  49. return this.m_IKCmo;
  50. }
  51. }
  52. public bool ForceIK
  53. {
  54. get
  55. {
  56. return this.m_ForceIK;
  57. }
  58. set
  59. {
  60. this.m_ForceIK = (this.m_ForceIKEnable && value);
  61. }
  62. }
  63. public IKCtrlData.PosRotPair BlendPosRot
  64. {
  65. get
  66. {
  67. return this.m_BlendPosRot;
  68. }
  69. }
  70. public bool IsIKExec
  71. {
  72. get
  73. {
  74. return this.m_PointIKData.IsIKExec || this.m_RotateIKData.IsIKExec || this.ForceIK;
  75. }
  76. }
  77. public bool IsIKExecTruth
  78. {
  79. get
  80. {
  81. return this.GetIKExecTruth(IKCtrlData.IKAttachType.NewPoint) || this.GetIKExecTruth(IKCtrlData.IKAttachType.Rotate);
  82. }
  83. }
  84. public bool IsWeightOver0
  85. {
  86. get
  87. {
  88. return this.PositionWeight * this.m_PosWeightBase > 0f || this.RotationWeight * this.m_RotWeightBase > 0f;
  89. }
  90. }
  91. public bool OldIkExec
  92. {
  93. get
  94. {
  95. return this.m_PointIKData.IsIKExec && this.m_PointIKData.IsOldIK;
  96. }
  97. }
  98. public bool AttachPointIK
  99. {
  100. get
  101. {
  102. return this.m_AttachPointIK;
  103. }
  104. }
  105. public Transform IKTarget
  106. {
  107. get
  108. {
  109. return this.m_IKTarget;
  110. }
  111. }
  112. public IKCtrlData.Vec3Enable OffsetEnable
  113. {
  114. get
  115. {
  116. return this.m_OffsetEnable;
  117. }
  118. }
  119. public virtual Transform TargetBone
  120. {
  121. get
  122. {
  123. return this.m_TargetBone;
  124. }
  125. }
  126. public bool IsSelfIKAttach { get; protected set; }
  127. public Transform[] ChainBones
  128. {
  129. get
  130. {
  131. return this.m_ChainBones;
  132. }
  133. }
  134. public float PositionWeight
  135. {
  136. get
  137. {
  138. return this.PointIK.Weight;
  139. }
  140. set
  141. {
  142. this.PointIK.Weight = value;
  143. this.OnPostSetPositionWeight(value);
  144. }
  145. }
  146. public float RotationWeight
  147. {
  148. get
  149. {
  150. return this.RotateIK.Weight;
  151. }
  152. set
  153. {
  154. this.RotateIK.Weight = value;
  155. this.OnPostSetRotationWeight(value);
  156. }
  157. }
  158. public virtual bool NeedFullbodySolverUpdate
  159. {
  160. get
  161. {
  162. return false;
  163. }
  164. }
  165. public static bool operator true(IKCtrlData data)
  166. {
  167. return data != null;
  168. }
  169. public static bool operator false(IKCtrlData data)
  170. {
  171. return data == null;
  172. }
  173. public static bool operator !(IKCtrlData data)
  174. {
  175. return data == null;
  176. }
  177. private void IkCmoInit()
  178. {
  179. if (!this.UseOldIK)
  180. {
  181. return;
  182. }
  183. this.IKCmo.Init(this.TargetBone.parent.parent, this.TargetBone.parent, this.TargetBone, this.MyIKCtrl.TgtBody);
  184. }
  185. public void SetFlagTarget(IKCtrlData.IKAttachType attach_type, string name)
  186. {
  187. if (this.MyIKCtrl.TgtChara.boMAN)
  188. {
  189. this.GetFlagData(attach_type).Target = this.MyIKCtrl.TgtBody.GetBone(name);
  190. }
  191. else
  192. {
  193. this.GetFlagData(attach_type).Target = this.MyIKCtrl.GetSTFlagObj(name);
  194. }
  195. }
  196. public void SetIKSetting(IKCtrlData.IKAttachType attachType, IKCtrlData.IKExecTiming timing, Maid tgt_maid, int slot_no, string attach_name, Transform axis_bone, Vector3 f_vecOffset, bool do_animation = false)
  197. {
  198. this.SetIKSetting(attachType, timing, tgt_maid, slot_no, attach_name, axis_bone, null, f_vecOffset, do_animation);
  199. }
  200. public void SetIKSetting(IKCtrlData.IKAttachType attachType, IKCtrlData.IKExecTiming timing, Maid tgt_maid, Transform target, Vector3 f_vecOffset, bool do_animation = false)
  201. {
  202. this.SetIKSetting(attachType, timing, tgt_maid, -1, string.Empty, null, target, f_vecOffset, do_animation);
  203. }
  204. public void SetIKSetting(IKCtrlData.IKAttachType attachType, IKCtrlData.IKExecTiming timing, Transform target, Vector3 f_vecOffset, bool do_animation = false)
  205. {
  206. this.SetIKSetting(attachType, timing, null, -1, string.Empty, null, target, f_vecOffset, do_animation);
  207. }
  208. public void SetIKSetting(IKCtrlData.IKAttachType attachType, IKCtrlData.IKExecTiming timing, Maid tgt_maid, string bone_name, Transform target, Vector3 f_vecOffset, bool do_animation = false)
  209. {
  210. this.SetIKSetting(attachType, timing, tgt_maid, -1, bone_name, null, target, f_vecOffset, do_animation);
  211. }
  212. public virtual void SetIKSetting(IKCtrlData.IKAttachType attachType, IKCtrlData.IKExecTiming timing, Maid tgt_maid, int slot_no, string attach_name, Transform axis_bone, Transform target, Vector3 f_vecOffset, bool do_animation = false)
  213. {
  214. this.GetIKSettingData(attachType).ChangeIKType(attachType);
  215. if (this.GetIKSettingData(attachType).MyType != attachType)
  216. {
  217. return;
  218. }
  219. this.MyIKCtrl.IKActive = true;
  220. this.BlendPosRot.Copy(this.m_lastIKPosRot);
  221. this.m_AnimPosRotOffset.Reset();
  222. this.m_FirstPosRotOffset.Reset();
  223. this.m_FirstTgtPosRot.Reset();
  224. if (!target && !string.IsNullOrEmpty(attach_name))
  225. {
  226. this.IsSelfIKAttach |= (tgt_maid == this.MyIKCtrl.TgtChara);
  227. }
  228. this.GetIKSettingData(attachType).SetIKSetting(timing, tgt_maid, slot_no, attach_name, axis_bone, target, f_vecOffset, do_animation);
  229. this.GetFlagData(attachType).IsFlagChange();
  230. }
  231. public virtual void SetPullState(bool pull_on)
  232. {
  233. }
  234. protected virtual void OnPostSetPositionWeight(float val)
  235. {
  236. }
  237. protected virtual void OnPostSetRotationWeight(float val)
  238. {
  239. }
  240. public virtual void TagetTransCpy()
  241. {
  242. this.m_BoneTgtPair.Copy();
  243. float num = 0f;
  244. this.RotationWeight = num;
  245. this.PositionWeight = num;
  246. }
  247. public virtual void ApplyIKSetting()
  248. {
  249. if (this.ForceIK)
  250. {
  251. this.GetIKSettingData(IKCtrlData.IKAttachType.NewPoint).ChangeIKType(IKCtrlData.IKAttachType.NewPoint);
  252. }
  253. if (!this.MyIKCtrl.IsUpdateEnd)
  254. {
  255. this.m_EachOtherIK = false;
  256. this.ForceIK |= this.MyIKCtrl.AllForceIK;
  257. }
  258. this.ApplyIKSetting(this.GetIKSettingData(IKCtrlData.IKAttachType.NewPoint));
  259. this.ApplyIKSetting(this.GetIKSettingData(IKCtrlData.IKAttachType.Rotate));
  260. }
  261. private void ApplyIKSetting(IKCtrlData.IKSettingData data)
  262. {
  263. if (this.MyIKCtrl.IsUpdateLate)
  264. {
  265. return;
  266. }
  267. if (data.curTargetData.TgtChara && data.curTargetData.TgtChara != this.MyIKCtrl.TgtChara)
  268. {
  269. IKCtrlData ikdata = data.curTargetData.TgtChara.IKCtrl.GetIKData(data.curTargetData.Tgt_AttachName);
  270. if (ikdata != null && ikdata.IsIKExec)
  271. {
  272. IKCtrlData.IKSettingData iksettingData = ikdata.GetIKSettingData(data.MyType);
  273. this.m_EachOtherIK = this.IsEachBoneIK(iksettingData);
  274. }
  275. if (!data.curTargetData.TgtChara.body0.LateUpdateEnd && !this.MyIKCtrl.TgtBody.LateUpdateEnd)
  276. {
  277. this.MyIKCtrl.IsUpdateLate = true;
  278. if (data.curTargetData.TgtChara.IKCtrl.IsIKExec)
  279. {
  280. FullBodyIKCtrl ikctrl = data.curTargetData.TgtChara.IKCtrl;
  281. ikctrl.PostSolverUpdate = (Action)Delegate.Combine(ikctrl.PostSolverUpdate, new Action(this.MyIKCtrl.LateIKUpdate));
  282. }
  283. else
  284. {
  285. TBody body = data.curTargetData.TgtChara.body0;
  286. body.OnLateUpdateEnd = (Action)Delegate.Combine(body.OnLateUpdateEnd, new Action(this.MyIKCtrl.LateIKUpdate));
  287. }
  288. return;
  289. }
  290. }
  291. if (data.BlendType != IKCtrlData.IKBlendType.Not_Blend && data.BlendTime <= 0f)
  292. {
  293. data.BlendReset(false);
  294. }
  295. data.DoSetOffset = false;
  296. data.IsIKExec = true;
  297. Vector3 position = this.TargetBone.position;
  298. Quaternion rotation = this.TargetBone.rotation;
  299. if (this.GetFlagData(data.MyType).IsEnable)
  300. {
  301. if (!this.GetFlagData(data.MyType).BlendCtrlSelf)
  302. {
  303. IKCtrlData.IKExecTiming curExecTiming = data.changeFlagData.curExecTiming;
  304. this.MultiTgtDataToPosRot(data, IKCtrlData.IKExecTiming.Normal, curExecTiming, ref position, ref rotation);
  305. data.DoSetOffset = true;
  306. data.IsIKExec = true;
  307. }
  308. else
  309. {
  310. IKCtrlData.IKExecTiming lastExecTiming = data.changeFlagData.lastExecTiming;
  311. if (this.GetFlagData(data.MyType).IsFlagChange())
  312. {
  313. IKCtrlData.IKTargetData tgtData = data.GetTgtData(lastExecTiming);
  314. data.BlendReset(true);
  315. data.curTargetData.SetLastTarget(tgtData.Tgt_AttachName, tgtData.TgtChara, tgtData.Target, tgtData.TgtOffset);
  316. data.CheckBlendType(true);
  317. if (data.MyType == IKCtrlData.IKAttachType.Rotate)
  318. {
  319. this.BlendPosRot.rot = this.m_lastIKPosRot.rot;
  320. }
  321. else
  322. {
  323. this.BlendPosRot.pos = this.m_lastIKPosRot.pos;
  324. }
  325. this.SetIKPosRot(data, ref position, ref rotation, false, IKCtrlData.IKExecTiming.Normal);
  326. }
  327. else
  328. {
  329. this.SetIKPosRot(data, ref position, ref rotation, false, IKCtrlData.IKExecTiming.Normal);
  330. }
  331. }
  332. }
  333. else
  334. {
  335. this.SetIKPosRot(data, ref position, ref rotation, false, IKCtrlData.IKExecTiming.Normal);
  336. }
  337. if (data.IsIKExec)
  338. {
  339. if (data.FirstFrame && !data.BlendNow)
  340. {
  341. if (data.IsPointAttach)
  342. {
  343. this.m_FirstTgtPosRot.pos = position;
  344. }
  345. else
  346. {
  347. this.m_FirstTgtPosRot.rot = rotation;
  348. }
  349. }
  350. this.SetTargetTransform(data, position, rotation);
  351. if (this.m_EachOtherIK && !data.curTargetData.TgtChara.IKCtrl.IsUpdateEnd)
  352. {
  353. if (data.IsPointAttach)
  354. {
  355. this.PositionWeight *= 0.5f;
  356. }
  357. else
  358. {
  359. this.RotationWeight *= 0.5f;
  360. }
  361. }
  362. if (data.DoAnimation && !data.BlendNow)
  363. {
  364. if (!data.DoSetPosRot)
  365. {
  366. Transform targetBone = this.TargetBone;
  367. if (data.IsPointAttach)
  368. {
  369. if (!data.FirstFrame)
  370. {
  371. this.IKTarget.position += targetBone.position - this.m_FirstTgtPosRot.pos - this.m_FirstPosRotOffset.pos;
  372. }
  373. else
  374. {
  375. this.m_FirstPosRotOffset.pos = targetBone.position - this.m_FirstTgtPosRot.pos;
  376. }
  377. }
  378. else if (!data.FirstFrame)
  379. {
  380. this.IKTarget.rotation *= targetBone.rotation * Quaternion.Inverse(this.m_FirstTgtPosRot.rot) * Quaternion.Inverse(this.m_FirstPosRotOffset.rot);
  381. }
  382. else
  383. {
  384. this.m_FirstPosRotOffset.rot = targetBone.rotation * Quaternion.Inverse(this.m_FirstTgtPosRot.rot);
  385. }
  386. }
  387. }
  388. else
  389. {
  390. this.m_AnimPosRotOffset.Reset();
  391. }
  392. if (!data.BlendNow)
  393. {
  394. data.FirstFrame = false;
  395. }
  396. if (data.curTargetData.IsTgtAxis)
  397. {
  398. KasaiUtility.DrawAxis(position, rotation, 0.125f);
  399. }
  400. if (!data.DoSetPosRot && data.BlendType != IKCtrlData.IKBlendType.Not_Blend)
  401. {
  402. data.ElapsedTime += Time.deltaTime;
  403. if (data.ElapsedTime >= data.BlendTime)
  404. {
  405. data.BlendReset(false);
  406. }
  407. }
  408. data.DoSetPosRot = true;
  409. }
  410. }
  411. private void SetIKPosRot(IKCtrlData.IKSettingData setting_data, ref Vector3 pos, ref Quaternion rot, bool include_offset = false, IKCtrlData.IKExecTiming flag_type = IKCtrlData.IKExecTiming.Normal)
  412. {
  413. this.SetIKPosRot(setting_data, setting_data.GetTgtData(flag_type), ref pos, ref rot, include_offset);
  414. }
  415. private void SetIKPosRot(IKCtrlData.IKSettingData setting_data, IKCtrlData.IKTargetData tgt_data, ref Vector3 pos, ref Quaternion rot, bool include_offset = false)
  416. {
  417. if (tgt_data.Target != null)
  418. {
  419. pos = tgt_data.Target.position;
  420. rot = tgt_data.Target.rotation;
  421. }
  422. else if (tgt_data.Tgt_AttachName != string.Empty)
  423. {
  424. if (this.MyIKCtrl.TgtBody.goSlot[tgt_data.Tgt_AttachSlot].morph != null)
  425. {
  426. if (tgt_data.TgtChara != null && tgt_data.TgtChara.body0 != null)
  427. {
  428. tgt_data.TgtChara.body0.SkinMeshUpdateOnce();
  429. Vector3 vector;
  430. tgt_data.TgtChara.body0.goSlot[tgt_data.Tgt_AttachSlot].morph.GetAttachPoint(tgt_data.Tgt_AttachName, out pos, out rot, out vector, false);
  431. if (setting_data.MyType == IKCtrlData.IKAttachType.NewPoint && tgt_data.AxisTgt)
  432. {
  433. rot = tgt_data.AxisTgt.rotation;
  434. }
  435. }
  436. else
  437. {
  438. setting_data.IsIKExec = false;
  439. tgt_data.Tgt_AttachName = string.Empty;
  440. }
  441. }
  442. }
  443. else if (this.ForceIK)
  444. {
  445. pos = this.m_IKTarget.position;
  446. rot = this.m_IKTarget.rotation;
  447. }
  448. else if (setting_data.BlendType == IKCtrlData.IKBlendType.IK_To_Detach)
  449. {
  450. pos = this.BlendPosRot.pos;
  451. rot = this.BlendPosRot.rot;
  452. }
  453. else
  454. {
  455. setting_data.IsIKExec = false;
  456. }
  457. if (setting_data.IsIKExec && include_offset)
  458. {
  459. if (setting_data.IsPointAttach)
  460. {
  461. Vector3 start = pos;
  462. switch (this.posOffsetType)
  463. {
  464. case IKCtrlData.PosOffsetType.OffsetTarget:
  465. pos += rot * tgt_data.TgtOffset;
  466. break;
  467. case IKCtrlData.PosOffsetType.OffsetWorld:
  468. pos += tgt_data.TgtOffset;
  469. break;
  470. case IKCtrlData.PosOffsetType.OffsetBone:
  471. pos -= this.TargetBone.rotation * tgt_data.TgtOffset;
  472. break;
  473. }
  474. Debug.DrawLine(start, pos, Color.white);
  475. }
  476. else
  477. {
  478. rot *= Quaternion.Euler(tgt_data.TgtOffset);
  479. }
  480. }
  481. }
  482. protected bool IsEachBoneIK(IKCtrlData.IKSettingData data)
  483. {
  484. return data.IsIKExec && data.curTargetData.Target == this.TargetBone;
  485. }
  486. private void MultiTgtDataToPosRot(IKCtrlData.IKSettingData data, IKCtrlData.IKExecTiming from, IKCtrlData.IKExecTiming to, ref Vector3 pos, ref Quaternion rot)
  487. {
  488. IKCtrlData.IKTargetData tgtData = data.GetTgtData(from);
  489. IKCtrlData.IKTargetData tgtData2 = data.GetTgtData(to);
  490. Vector3 a = pos;
  491. Quaternion a2 = rot;
  492. this.SetIKPosRot(data, tgtData, ref a, ref a2, true);
  493. Vector3 b = pos;
  494. Quaternion b2 = rot;
  495. this.SetIKPosRot(data, tgtData2, ref b, ref b2, true);
  496. float blendValue = this.GetFlagData(data.MyType).GetBlendValue(from, to);
  497. if (data.IsPointAttach)
  498. {
  499. if (!tgtData.ExistTgt)
  500. {
  501. this.m_PosWeightBase = ((!tgtData2.ExistTgt) ? 0f : blendValue);
  502. }
  503. else
  504. {
  505. this.m_PosWeightBase = 1f;
  506. }
  507. pos = Vector3.Lerp(a, b, blendValue);
  508. }
  509. else
  510. {
  511. if (!tgtData.ExistTgt)
  512. {
  513. this.m_RotWeightBase = ((!tgtData2.ExistTgt) ? 0f : blendValue);
  514. }
  515. else
  516. {
  517. this.m_RotWeightBase = 1f;
  518. }
  519. rot = Quaternion.Lerp(a2, b2, blendValue);
  520. }
  521. }
  522. protected virtual void SetTargetTransform(IKCtrlData.IKSettingData data, Vector3 pos, Quaternion rot)
  523. {
  524. IKCtrlData.IKTargetData curTargetData = data.curTargetData;
  525. switch (data.MyType)
  526. {
  527. case IKCtrlData.IKAttachType.Point:
  528. pos += this.m_AnimPosRotOffset.pos;
  529. Debug.DrawLine(pos, pos + rot * Vector3.forward * 0.2f, Color.cyan);
  530. if (!data.DoSetOffset)
  531. {
  532. this.IkCmoPorc(pos, data.curTargetData.TgtOffset);
  533. }
  534. else
  535. {
  536. this.IkCmoPorc(pos, Vector3.zero);
  537. }
  538. break;
  539. case IKCtrlData.IKAttachType.Rotate:
  540. rot *= this.m_AnimPosRotOffset.rot;
  541. if (!data.DoSetOffset)
  542. {
  543. rot *= Quaternion.Euler(data.curTargetData.TgtOffset);
  544. }
  545. rot = Quaternion.Euler(this.GetIKEnable(data.MyType).GetEnable(this.TargetBone.eulerAngles, rot.eulerAngles, false));
  546. this.m_IKTarget.rotation = rot;
  547. if (data.BlendType == IKCtrlData.IKBlendType.IK_To_IK)
  548. {
  549. this.m_IKTarget.rotation = Quaternion.Lerp(this.BlendPosRot.rot, this.m_IKTarget.rotation, data.BlendWeight);
  550. this.RotationWeight = this.m_RotWeightBase;
  551. }
  552. else if (data.BlendType == IKCtrlData.IKBlendType.IK_To_Detach)
  553. {
  554. this.RotationWeight = this.m_RotWeightBase * (1f - data.BlendWeight);
  555. }
  556. else
  557. {
  558. this.RotationWeight = this.m_RotWeightBase * data.BlendWeight;
  559. }
  560. break;
  561. case IKCtrlData.IKAttachType.NewPoint:
  562. pos += this.m_AnimPosRotOffset.pos;
  563. if (!data.DoSetOffset)
  564. {
  565. Vector3 start = pos;
  566. switch (this.posOffsetType)
  567. {
  568. case IKCtrlData.PosOffsetType.OffsetTarget:
  569. pos += rot * curTargetData.TgtOffset;
  570. break;
  571. case IKCtrlData.PosOffsetType.OffsetWorld:
  572. pos += curTargetData.TgtOffset;
  573. break;
  574. case IKCtrlData.PosOffsetType.OffsetBone:
  575. pos -= this.TargetBone.rotation * curTargetData.TgtOffset;
  576. break;
  577. }
  578. Debug.DrawLine(start, pos, Color.white);
  579. }
  580. pos = this.GetIKEnable(data.MyType).GetEnable(this.TargetBone.position, pos, false);
  581. this.m_IKTarget.position = pos;
  582. if (data.BlendType == IKCtrlData.IKBlendType.IK_To_IK)
  583. {
  584. this.m_IKTarget.position = Vector3.Lerp(this.BlendPosRot.pos, this.m_IKTarget.position, data.BlendWeight);
  585. this.PositionWeight = this.m_PosWeightBase;
  586. }
  587. else if (data.BlendType == IKCtrlData.IKBlendType.IK_To_Detach)
  588. {
  589. this.PositionWeight = this.m_PosWeightBase * (1f - data.BlendWeight);
  590. }
  591. else
  592. {
  593. this.PositionWeight = this.m_PosWeightBase * data.BlendWeight;
  594. }
  595. break;
  596. }
  597. data.DoSetOffset = true;
  598. }
  599. private void IkCmoPorc(Vector3 tgt, Vector3 vechand_offset)
  600. {
  601. if (!this.UseOldIK)
  602. {
  603. return;
  604. }
  605. for (int i = 0; i < 3; i++)
  606. {
  607. this.IKCmo.Porc(this.TargetBone.parent.parent, this.TargetBone.parent, this.TargetBone, tgt, vechand_offset, this);
  608. }
  609. }
  610. public virtual void Update()
  611. {
  612. }
  613. public virtual void LateUpdate()
  614. {
  615. this.SaveLastBonePosRot();
  616. this.GetIKSettingData(IKCtrlData.IKAttachType.NewPoint).DoSetPosRot = (this.GetIKSettingData(IKCtrlData.IKAttachType.Rotate).DoSetPosRot = false);
  617. }
  618. public virtual void SaveLastBonePosRot()
  619. {
  620. this.m_lastIKPosRot.Copy(this.m_TargetBone);
  621. }
  622. public virtual void Detach(IKCtrlData.IKAttachType attachType)
  623. {
  624. this.ForceIK = false;
  625. this.m_BoneTgtPair.PosOffset = Vector3.zero;
  626. this.IsSelfIKAttach = false;
  627. this.BlendPosRot.Copy(this.m_lastIKPosRot);
  628. this.GetFlagData(attachType).Reset();
  629. this.GetIKSettingData(attachType).Detach();
  630. }
  631. public IKCtrlData.IKSettingData GetIKSettingData(IKCtrlData.IKAttachType attach_type)
  632. {
  633. if (attach_type == IKCtrlData.IKAttachType.Rotate)
  634. {
  635. return this.m_RotateIKData;
  636. }
  637. return this.m_PointIKData;
  638. }
  639. public IKCtrlData.ChangeFlagData GetFlagData(IKCtrlData.IKAttachType attach_type)
  640. {
  641. return this.GetIKSettingData(attach_type).changeFlagData;
  642. }
  643. public IKCtrlData.IKTargetData GetTargetData(IKCtrlData.IKAttachType attach_type)
  644. {
  645. return this.GetIKSettingData(attach_type).curTargetData;
  646. }
  647. public IKCtrlData.IKTargetData GetTargetData(IKCtrlData.IKAttachType attach_type, IKCtrlData.IKExecTiming exec_timing)
  648. {
  649. return this.GetIKSettingData(attach_type).GetTgtData(exec_timing);
  650. }
  651. private bool IsIKTargetChara(IKCtrlData.IKAttachType attach_type, Maid chara)
  652. {
  653. IKCtrlData.IKSettingData iksettingData = this.GetIKSettingData(attach_type);
  654. foreach (IKCtrlData.IKExecTiming timing in (IKCtrlData.IKExecTiming[])Enum.GetValues(typeof(IKCtrlData.IKExecTiming)))
  655. {
  656. IKCtrlData.IKTargetData tgtData = iksettingData.GetTgtData(timing);
  657. if (tgtData.TgtChara == chara)
  658. {
  659. return true;
  660. }
  661. }
  662. return false;
  663. }
  664. public bool IsIKTargetChara(Maid chara)
  665. {
  666. return this.IsIKTargetChara(IKCtrlData.IKAttachType.NewPoint, chara) || this.IsIKTargetChara(IKCtrlData.IKAttachType.Rotate, chara);
  667. }
  668. public IKCtrlData.Vec3Enable GetIKEnable(IKCtrlData.IKAttachType attach_type)
  669. {
  670. return this.GetIKSettingData(attach_type).offsetEnable;
  671. }
  672. public bool GetIKExecTruth(IKCtrlData.IKAttachType attach_type)
  673. {
  674. IKCtrlData.IKSettingData iksettingData = (attach_type != IKCtrlData.IKAttachType.Rotate) ? this.PointIK : this.RotateIK;
  675. float num = (attach_type != IKCtrlData.IKAttachType.Rotate) ? this.PositionWeight : this.RotationWeight;
  676. bool flag = iksettingData.IsIKExec && num > 0f;
  677. if (iksettingData.changeFlagData.IsEnable)
  678. {
  679. flag &= (iksettingData.changeFlagData.GetFlagValue() > 0f);
  680. }
  681. return flag;
  682. }
  683. [SerializeField]
  684. [Header("位置IK")]
  685. private IKCtrlData.IKSettingData m_PointIKData = new IKCtrlData.IKSettingData(IKCtrlData.IKAttachType.NewPoint);
  686. [SerializeField]
  687. [Header("回転IK")]
  688. private IKCtrlData.IKSettingData m_RotateIKData = new IKCtrlData.IKSettingData(IKCtrlData.IKAttachType.Rotate);
  689. private TBody.IKCMO m_IKCmo = new TBody.IKCMO();
  690. private IKCtrlData.PosRotPair m_BlendPosRot = new IKCtrlData.PosRotPair();
  691. [SerializeField]
  692. [Space]
  693. private IKCtrlData.PosRotPair m_AnimPosRotOffset = new IKCtrlData.PosRotPair();
  694. private IKCtrlData.PosRotPair m_FirstPosRotOffset = new IKCtrlData.PosRotPair();
  695. [SerializeField]
  696. private bool m_AttachPointIK;
  697. [SerializeField]
  698. private Transform m_TargetBone;
  699. [SerializeField]
  700. private Transform m_IKTarget;
  701. [SerializeField]
  702. private bool m_DrawLine = true;
  703. private IKCtrlData.BoneTgtPair m_BoneTgtPair;
  704. protected IKCtrlData.PosRotPair m_FirstTgtPosRot = new IKCtrlData.PosRotPair();
  705. protected IKCtrlData.PosRotPair m_lastIKPosRot = new IKCtrlData.PosRotPair();
  706. [SerializeField]
  707. [Range(0f, 1f)]
  708. protected float m_PosWeightBase = 1f;
  709. [SerializeField]
  710. [Range(0f, 1f)]
  711. protected float m_RotWeightBase = 1f;
  712. [SerializeField]
  713. protected bool m_ForceIK;
  714. protected bool m_ForceIKEnable;
  715. protected bool m_EachOtherIK;
  716. protected IKCtrlData.Vec3Enable m_OffsetEnable = new IKCtrlData.Vec3Enable();
  717. [Space]
  718. public IKCtrlData.PosOffsetType posOffsetType;
  719. public readonly FullBodyIKCtrl MyIKCtrl;
  720. public readonly bool UseOldIK;
  721. protected Transform[] m_ChainBones;
  722. public enum IKAttachType
  723. {
  724. Point,
  725. Rotate,
  726. NewPoint
  727. }
  728. public enum IKBlendType
  729. {
  730. Detach_To_IK,
  731. IK_To_IK,
  732. IK_To_Detach,
  733. Not_Blend
  734. }
  735. public enum PosOffsetType
  736. {
  737. OffsetTarget,
  738. OffsetWorld,
  739. OffsetBone
  740. }
  741. public enum IKExecTiming
  742. {
  743. Normal,
  744. FlagPositive,
  745. FlagNegative = -1
  746. }
  747. [Serializable]
  748. public class Vec3Enable
  749. {
  750. public bool AnyDisable
  751. {
  752. get
  753. {
  754. return !this.EnableX || !this.EnableY || !this.EnableZ;
  755. }
  756. }
  757. public Vector3 GetEnable(Vector3 pos, bool inverse = false)
  758. {
  759. if (this.EnableX == inverse)
  760. {
  761. pos.x = 0f;
  762. }
  763. if (this.EnableY == inverse)
  764. {
  765. pos.y = 0f;
  766. }
  767. if (this.EnableZ == inverse)
  768. {
  769. pos.z = 0f;
  770. }
  771. return pos;
  772. }
  773. public Vector3 GetEnable(Vector3 from, Vector3 to, bool inverse = false)
  774. {
  775. if (this.EnableX == inverse)
  776. {
  777. to.x = from.x;
  778. }
  779. if (this.EnableY == inverse)
  780. {
  781. to.y = from.y;
  782. }
  783. if (this.EnableZ == inverse)
  784. {
  785. to.z = from.z;
  786. }
  787. return to;
  788. }
  789. public void Recet()
  790. {
  791. this.EnableX = (this.EnableY = (this.EnableZ = true));
  792. }
  793. public void Copy(IKCtrlData.Vec3Enable cpy)
  794. {
  795. this.EnableX = cpy.EnableX;
  796. this.EnableY = cpy.EnableY;
  797. this.EnableZ = cpy.EnableZ;
  798. }
  799. public string OffEnableToStr()
  800. {
  801. if (!this.AnyDisable)
  802. {
  803. return string.Empty;
  804. }
  805. string text = " disable=";
  806. if (!this.EnableX)
  807. {
  808. text += "x";
  809. }
  810. if (!this.EnableY)
  811. {
  812. if (!this.EnableX)
  813. {
  814. text += ",";
  815. }
  816. text += "y";
  817. }
  818. if (!this.EnableZ)
  819. {
  820. if (!this.EnableX || !this.EnableY)
  821. {
  822. text += ",";
  823. }
  824. text += "z";
  825. }
  826. return text;
  827. }
  828. public bool EnableX = true;
  829. public bool EnableY = true;
  830. public bool EnableZ = true;
  831. }
  832. [Serializable]
  833. public class PosRotPair
  834. {
  835. public void Reset()
  836. {
  837. this.pos = Vector3.zero;
  838. this.rot = new Quaternion(0f, 0f, 0f, 1f);
  839. }
  840. public void Copy(IKCtrlData.PosRotPair pair)
  841. {
  842. this.pos = pair.pos;
  843. this.rot = pair.rot;
  844. }
  845. public void Copy(Transform transform)
  846. {
  847. this.pos = transform.position;
  848. this.rot = transform.rotation;
  849. }
  850. public void DrawAxis()
  851. {
  852. KasaiUtility.DrawAxis(this.pos, this.rot, 0.0625f);
  853. }
  854. public Vector3 pos = Vector3.zero;
  855. public Quaternion rot = new Quaternion(0f, 0f, 0f, 1f);
  856. }
  857. public class BoneTgtPair
  858. {
  859. public BoneTgtPair(Transform bone, Transform target)
  860. {
  861. this.Bone = bone;
  862. this.Target = target;
  863. }
  864. public void Copy()
  865. {
  866. this.Target.position = this.Bone.position + this.PosOffset;
  867. this.Target.rotation = this.Bone.rotation;
  868. }
  869. public readonly Transform Bone;
  870. public readonly Transform Target;
  871. public Vector3 PosOffset = Vector3.zero;
  872. }
  873. [Serializable]
  874. public class ChangeFlagData
  875. {
  876. public bool IsEnable
  877. {
  878. get
  879. {
  880. return this.Target != null;
  881. }
  882. }
  883. public IKCtrlData.IKExecTiming lastExecTiming { get; private set; }
  884. public IKCtrlData.IKExecTiming curExecTiming
  885. {
  886. get
  887. {
  888. if (this.GetFlagValue() > 0f)
  889. {
  890. return IKCtrlData.IKExecTiming.FlagPositive;
  891. }
  892. if (this.GetFlagValue() < 0f)
  893. {
  894. return IKCtrlData.IKExecTiming.FlagNegative;
  895. }
  896. return IKCtrlData.IKExecTiming.Normal;
  897. }
  898. }
  899. public float GetFlagValue()
  900. {
  901. if (!this.Target)
  902. {
  903. return 0f;
  904. }
  905. return Vector3.Dot(this.Target.localPosition, this.Axis) / this.OnValue;
  906. }
  907. public float GetBlendValue(IKCtrlData.IKExecTiming from, IKCtrlData.IKExecTiming to)
  908. {
  909. if (from == to)
  910. {
  911. return 1f;
  912. }
  913. return Mathf.InverseLerp((float)from, (float)to, this.GetFlagValue());
  914. }
  915. public bool IsFlagChange()
  916. {
  917. if (!this.Target)
  918. {
  919. return false;
  920. }
  921. IKCtrlData.IKExecTiming lastExecTiming = this.lastExecTiming;
  922. this.lastExecTiming = this.curExecTiming;
  923. return lastExecTiming != this.lastExecTiming;
  924. }
  925. public void Reset()
  926. {
  927. this.Target = null;
  928. this.lastExecTiming = IKCtrlData.IKExecTiming.Normal;
  929. this.BlendCtrlSelf = false;
  930. }
  931. public Transform Target;
  932. public Vector3 Axis = Vector3.forward;
  933. public float OnValue = 0.1f;
  934. [HideInInspector]
  935. public bool BlendCtrlSelf;
  936. }
  937. [Serializable]
  938. public class IKTargetData
  939. {
  940. public IKTargetData(bool is_for_point)
  941. {
  942. this.IsForPointTarget = is_for_point;
  943. }
  944. public string lastAttachName
  945. {
  946. get
  947. {
  948. return this.m_LastAttachName;
  949. }
  950. }
  951. public Transform lastTarget
  952. {
  953. get
  954. {
  955. return this.m_LastTarget;
  956. }
  957. }
  958. public Maid lastTgtChara
  959. {
  960. get
  961. {
  962. return this.m_LastTgtChara;
  963. }
  964. }
  965. public Vector3 lastOffset
  966. {
  967. get
  968. {
  969. return this.m_LastOffset;
  970. }
  971. }
  972. public bool ExistTgt
  973. {
  974. get
  975. {
  976. return this.Target != null || !string.IsNullOrEmpty(this.Tgt_AttachName);
  977. }
  978. }
  979. public bool IsEachOtherIK(bool check_update = false)
  980. {
  981. return this.TgtChara && this.TgtChara.IKCtrl.IsIKExec && this.TgtChara.IKCtrl.IsUpdateEnd == check_update;
  982. }
  983. public void SaveLastTarget()
  984. {
  985. this.m_LastAttachName = this.Tgt_AttachName;
  986. this.m_LastTgtChara = this.TgtChara;
  987. this.m_LastTarget = this.Target;
  988. this.m_LastOffset = this.TgtOffset;
  989. }
  990. public void SetLastTarget(string attach_name, Maid maid, Transform target, Vector3 offset)
  991. {
  992. this.m_LastAttachName = attach_name;
  993. this.m_LastTgtChara = maid;
  994. this.m_LastTarget = target;
  995. this.m_LastOffset = offset;
  996. }
  997. public void SetIKSetting(Maid tgt_maid, int slot_no, string attach_name, Transform axis_bone, Transform target, Vector3 f_vecOffset)
  998. {
  999. this.SetLastTarget(this.Tgt_AttachName, this.TgtChara, this.Target, this.TgtOffset);
  1000. this.TgtChara = tgt_maid;
  1001. this.Tgt_AttachSlot = slot_no;
  1002. this.Tgt_AttachName = attach_name;
  1003. this.Target = target;
  1004. this.AxisTgt = axis_bone;
  1005. if (this.IsForPointTarget)
  1006. {
  1007. this.TgtOffset = f_vecOffset;
  1008. }
  1009. else
  1010. {
  1011. this.TgtOffset = KasaiUtility.AngleRimmit360(f_vecOffset);
  1012. }
  1013. this.IsIKExec = true;
  1014. }
  1015. public void Detach()
  1016. {
  1017. this.SetLastTarget(this.Tgt_AttachName, this.TgtChara, this.Target, this.TgtOffset);
  1018. this.TgtChara = null;
  1019. this.Tgt_AttachSlot = -1;
  1020. this.Tgt_AttachName = string.Empty;
  1021. this.Target = null;
  1022. this.AxisTgt = null;
  1023. this.TgtOffset = Vector3.zero;
  1024. }
  1025. private string m_LastAttachName = string.Empty;
  1026. private Transform m_LastTarget;
  1027. private Maid m_LastTgtChara;
  1028. private Vector3 m_LastOffset = Vector3.zero;
  1029. public Transform Target;
  1030. public Vector3 TgtOffset;
  1031. public int Tgt_AttachSlot = -1;
  1032. public string Tgt_AttachName = string.Empty;
  1033. public Maid TgtChara;
  1034. public bool IsTgtAxis;
  1035. public bool IsIKExec;
  1036. public Transform AxisTgt;
  1037. public readonly bool IsForPointTarget;
  1038. }
  1039. [Serializable]
  1040. public class IKSettingData
  1041. {
  1042. public IKSettingData(IKCtrlData.IKAttachType type)
  1043. {
  1044. this.MyType = type;
  1045. this.BlendType = IKCtrlData.IKBlendType.Not_Blend;
  1046. this.m_NormalTgtData = new IKCtrlData.IKTargetData(this.IsPointAttach);
  1047. this.m_FlagPositiveTgtData = new IKCtrlData.IKTargetData(this.IsPointAttach);
  1048. this.m_FlagNegativeTgtData = new IKCtrlData.IKTargetData(this.IsPointAttach);
  1049. }
  1050. public IKCtrlData.Vec3Enable offsetEnable
  1051. {
  1052. get
  1053. {
  1054. return this.m_OffsetEnable;
  1055. }
  1056. }
  1057. public IKCtrlData.ChangeFlagData changeFlagData
  1058. {
  1059. get
  1060. {
  1061. return this.m_ChangeFlagData;
  1062. }
  1063. }
  1064. public IKCtrlData.IKTargetData curTargetData
  1065. {
  1066. get
  1067. {
  1068. IKCtrlData.IKExecTiming curExecTiming = this.changeFlagData.curExecTiming;
  1069. if (curExecTiming == IKCtrlData.IKExecTiming.FlagPositive)
  1070. {
  1071. return this.m_FlagPositiveTgtData;
  1072. }
  1073. if (curExecTiming != IKCtrlData.IKExecTiming.FlagNegative)
  1074. {
  1075. return this.m_NormalTgtData;
  1076. }
  1077. return this.m_FlagNegativeTgtData;
  1078. }
  1079. }
  1080. public float BlendTime
  1081. {
  1082. get
  1083. {
  1084. return (!this.IKCtrl) ? -1f : this.IKCtrl.BlendTime;
  1085. }
  1086. }
  1087. public IKCtrlData.IKAttachType MyType { get; private set; }
  1088. public IKCtrlData.IKBlendType BlendType { get; private set; }
  1089. public bool DoIKBlend
  1090. {
  1091. get
  1092. {
  1093. return this.m_DoIKBlend && this.BlendTime > 0f;
  1094. }
  1095. }
  1096. public bool IsPointAttach
  1097. {
  1098. get
  1099. {
  1100. return this.MyType != IKCtrlData.IKAttachType.Rotate;
  1101. }
  1102. }
  1103. public bool NeedBlend
  1104. {
  1105. get
  1106. {
  1107. return this.BlendTime > 0f && this.BlendType != IKCtrlData.IKBlendType.Not_Blend;
  1108. }
  1109. }
  1110. public float BlendWeight
  1111. {
  1112. get
  1113. {
  1114. return (!this.NeedBlend || !this.DoIKBlend) ? 1f : Mathf.Clamp01(this.ElapsedTime / this.BlendTime);
  1115. }
  1116. }
  1117. public bool BlendNow
  1118. {
  1119. get
  1120. {
  1121. return this.NeedBlend && this.ElapsedTime < this.BlendTime;
  1122. }
  1123. }
  1124. public bool IsOldIK
  1125. {
  1126. get
  1127. {
  1128. return this.MyType == IKCtrlData.IKAttachType.Point;
  1129. }
  1130. }
  1131. public void ChangeIKType(IKCtrlData.IKAttachType type)
  1132. {
  1133. if (this.MyType == IKCtrlData.IKAttachType.Rotate)
  1134. {
  1135. return;
  1136. }
  1137. this.MyType = type;
  1138. }
  1139. public void CheckBlendType(bool check_time = true)
  1140. {
  1141. this.BlendType = IKCtrlData.IKBlendType.IK_To_IK;
  1142. this.m_DoIKBlend = true;
  1143. float num = Vector3.Distance(this.curTargetData.lastOffset, this.curTargetData.TgtOffset);
  1144. if (this.curTargetData.lastTarget)
  1145. {
  1146. if (!this.curTargetData.Target && string.IsNullOrEmpty(this.curTargetData.Tgt_AttachName))
  1147. {
  1148. this.BlendType = IKCtrlData.IKBlendType.IK_To_Detach;
  1149. }
  1150. else if (this.curTargetData.Target)
  1151. {
  1152. this.m_DoIKBlend = (this.curTargetData.lastTarget != this.curTargetData.Target || num > 0.01f);
  1153. }
  1154. }
  1155. else if (!string.IsNullOrEmpty(this.curTargetData.lastAttachName))
  1156. {
  1157. if (string.IsNullOrEmpty(this.curTargetData.Tgt_AttachName) && !this.curTargetData.Target)
  1158. {
  1159. this.BlendType = IKCtrlData.IKBlendType.IK_To_Detach;
  1160. }
  1161. else if (!this.curTargetData.Target)
  1162. {
  1163. this.m_DoIKBlend = (this.curTargetData.lastAttachName != this.curTargetData.Tgt_AttachName || this.curTargetData.lastTgtChara != this.curTargetData.TgtChara || num > 0.01f);
  1164. }
  1165. }
  1166. else
  1167. {
  1168. this.BlendType = IKCtrlData.IKBlendType.Detach_To_IK;
  1169. if (!this.curTargetData.Target && string.IsNullOrEmpty(this.curTargetData.Tgt_AttachName))
  1170. {
  1171. this.BlendType = IKCtrlData.IKBlendType.Not_Blend;
  1172. this.m_DoIKBlend = false;
  1173. }
  1174. }
  1175. }
  1176. public void BlendReset(bool elpsed_only = false)
  1177. {
  1178. this.ElapsedTime = 0f;
  1179. if (!elpsed_only)
  1180. {
  1181. this.m_DoIKBlend = false;
  1182. this.BlendType = IKCtrlData.IKBlendType.Not_Blend;
  1183. }
  1184. }
  1185. public IKCtrlData.IKTargetData GetTgtData(IKCtrlData.IKExecTiming timing)
  1186. {
  1187. if (timing == IKCtrlData.IKExecTiming.FlagPositive)
  1188. {
  1189. return this.m_FlagPositiveTgtData;
  1190. }
  1191. if (timing != IKCtrlData.IKExecTiming.FlagNegative)
  1192. {
  1193. return this.m_NormalTgtData;
  1194. }
  1195. return this.m_FlagNegativeTgtData;
  1196. }
  1197. public void SetIKSetting(IKCtrlData.IKExecTiming timing, Maid tgt_chara, int slot_no, string attach_name, Transform axis_bone, Transform target, Vector3 f_vecOffset, bool do_animation)
  1198. {
  1199. this.BlendReset(false);
  1200. this.DoAnimation = do_animation;
  1201. this.IsIKExec = true;
  1202. this.FirstFrame = true;
  1203. this.GetTgtData(timing).SetIKSetting(tgt_chara, slot_no, attach_name, axis_bone, target, f_vecOffset);
  1204. this.CheckBlendType(true);
  1205. this.m_ChangeFlagData.IsFlagChange();
  1206. }
  1207. public void Detach()
  1208. {
  1209. this.BlendReset(false);
  1210. this.m_NormalTgtData.Detach();
  1211. this.m_FlagPositiveTgtData.Detach();
  1212. this.m_FlagNegativeTgtData.Detach();
  1213. this.CheckBlendType(true);
  1214. this.m_ChangeFlagData.Reset();
  1215. this.DoSetOffset = false;
  1216. this.DoSetPosRot = false;
  1217. this.DoAnimation = false;
  1218. this.IsIKExec = false;
  1219. this.FirstFrame = false;
  1220. }
  1221. [SerializeField]
  1222. [Header("通常時のターゲットデータ")]
  1223. private IKCtrlData.IKTargetData m_NormalTgtData;
  1224. [SerializeField]
  1225. [Header("フラグ値が0以上のときのターゲットデータ")]
  1226. private IKCtrlData.IKTargetData m_FlagPositiveTgtData;
  1227. [SerializeField]
  1228. [Header("フラグ値が0以下のときのターゲットデータ")]
  1229. private IKCtrlData.IKTargetData m_FlagNegativeTgtData;
  1230. [SerializeField]
  1231. [Space]
  1232. private IKCtrlData.Vec3Enable m_OffsetEnable = new IKCtrlData.Vec3Enable();
  1233. [SerializeField]
  1234. private IKCtrlData.ChangeFlagData m_ChangeFlagData = new IKCtrlData.ChangeFlagData();
  1235. private bool m_DoIKBlend;
  1236. public bool IsIKExec;
  1237. public float ElapsedTime;
  1238. [Range(0f, 1f)]
  1239. public float Weight;
  1240. [HideInInspector]
  1241. public bool FirstFrame;
  1242. public bool DoAnimation;
  1243. [HideInInspector]
  1244. public bool DoSetPosRot;
  1245. [HideInInspector]
  1246. public bool DoSetOffset;
  1247. [HideInInspector]
  1248. public FullBodyIKCtrl IKCtrl;
  1249. }
  1250. }