FullBodyIKCtrl.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using RootMotion.FinalIK;
  5. using UnityEngine;
  6. public class FullBodyIKCtrl : MonoBehaviour
  7. {
  8. public TBody TgtBody
  9. {
  10. get
  11. {
  12. return this.m_TgtBody;
  13. }
  14. }
  15. public Maid TgtChara
  16. {
  17. get
  18. {
  19. return this.m_TgtBody.maid;
  20. }
  21. }
  22. public Transform IKTgtRoot
  23. {
  24. get
  25. {
  26. return this.m_IKTgtRoot;
  27. }
  28. }
  29. public FullBodyBipedIK FullbodyIK
  30. {
  31. get
  32. {
  33. return this.m_FullbodyIK;
  34. }
  35. }
  36. public IKEffector BodyEffector
  37. {
  38. get
  39. {
  40. return this.m_FullbodyIK.solver.bodyEffector;
  41. }
  42. }
  43. public BodyCtrlData BodyCtrlData
  44. {
  45. get
  46. {
  47. return this.m_BodyCtrlData;
  48. }
  49. }
  50. public Transform BodyTarget { get; private set; }
  51. public bool IsUpdateEnd { get; private set; }
  52. public Dictionary<string, IKCtrlData> strIKDataPair
  53. {
  54. get
  55. {
  56. return this.m_StrIKDataPair;
  57. }
  58. }
  59. public bool IsIKExec
  60. {
  61. get
  62. {
  63. return this.m_StrIKDataPair.Any((KeyValuePair<string, IKCtrlData> ik) => ik.Value.IsIKExec) && this.IKActive;
  64. }
  65. }
  66. public bool IsSelfIKAttach
  67. {
  68. get
  69. {
  70. return this.m_StrIKDataPair.Any((KeyValuePair<string, IKCtrlData> ik) => ik.Value.IsSelfIKAttach) && this.IKActive;
  71. }
  72. }
  73. public void Init()
  74. {
  75. this.m_TgtBody = base.GetComponent<TBody>();
  76. if (!this.m_IKTgtRoot)
  77. {
  78. this.m_IKTgtRoot = new GameObject("IK Target Root").transform;
  79. this.m_IKTgtRoot.SetParent(this.m_TgtBody.m_trBones, false);
  80. }
  81. if (!this.TgtChara.boMAN)
  82. {
  83. this.m_STRoot = this.m_TgtBody.m_trBones.Find("ST_Root");
  84. }
  85. if (this.m_FullbodyIK)
  86. {
  87. UnityEngine.Object.DestroyImmediate(this.m_FullbodyIK);
  88. }
  89. this.m_FullbodyIK = this.m_IKTgtRoot.gameObject.AddComponent<FullBodyBipedIK>();
  90. if (this.m_Mouth)
  91. {
  92. UnityEngine.Object.DestroyImmediate(this.m_Mouth);
  93. }
  94. this.m_Mouth = new GameObject("Mouth").transform;
  95. this.m_Mouth.SetParent(this.TgtBody.trsHead, false);
  96. this.m_Mouth.localEulerAngles = new Vector3(-90f, 90f, 0f);
  97. if (!this.TgtChara.boMAN)
  98. {
  99. if (this.m_NippleL)
  100. {
  101. UnityEngine.Object.DestroyImmediate(this.m_NippleL);
  102. }
  103. if (this.m_NippleR)
  104. {
  105. UnityEngine.Object.DestroyImmediate(this.m_NippleR);
  106. }
  107. this.m_NippleL = new GameObject("Nipple_L").transform;
  108. this.m_NippleL.SetParent(CMT.SearchObjName(this.TgtBody.m_trBones, "Mune_L_sub", true), false);
  109. this.m_NippleR = new GameObject("Nipple_R").transform;
  110. this.m_NippleR.SetParent(CMT.SearchObjName(this.TgtBody.m_trBones, "Mune_R_sub", true), false);
  111. }
  112. this.m_NameFlagObjpair.Clear();
  113. this.m_IKBoneDic = FullBodyIKCtrl.GetAllIKBoneDic(this.TgtChara);
  114. this.m_FullbodyIK.references.root = this.m_TgtBody.m_trBones;
  115. this.m_FullbodyIK.references.pelvis = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Root);
  116. if (!this.TgtChara.boMAN)
  117. {
  118. this.m_FullbodyIK.references.spine = new Transform[]
  119. {
  120. this.m_IKBoneDic[FullBodyIKCtrl.IKBoneType.Spine0],
  121. this.m_IKBoneDic[FullBodyIKCtrl.IKBoneType.Spine3]
  122. };
  123. }
  124. else
  125. {
  126. this.m_FullbodyIK.references.spine = new Transform[]
  127. {
  128. this.m_IKBoneDic[FullBodyIKCtrl.IKBoneType.Spine0],
  129. this.m_IKBoneDic[FullBodyIKCtrl.IKBoneType.Spine2]
  130. };
  131. }
  132. this.m_FullbodyIK.references.head = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Head);
  133. this.m_FullbodyIK.references.leftUpperArm = this.GetIKBone(FullBodyIKCtrl.IKBoneType.UpperArm_L);
  134. this.m_FullbodyIK.references.leftForearm = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Forearm_L);
  135. this.m_FullbodyIK.references.leftHand = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Hand_L);
  136. this.m_FullbodyIK.references.rightUpperArm = this.GetIKBone(FullBodyIKCtrl.IKBoneType.UpperArm_R);
  137. this.m_FullbodyIK.references.rightForearm = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Forearm_R);
  138. this.m_FullbodyIK.references.rightHand = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Hand_R);
  139. this.m_FullbodyIK.references.leftThigh = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Thigh_L);
  140. this.m_FullbodyIK.references.leftCalf = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Calf_L);
  141. this.m_FullbodyIK.references.leftFoot = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Foot_L);
  142. this.m_FullbodyIK.references.rightThigh = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Thigh_R);
  143. this.m_FullbodyIK.references.rightCalf = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Calf_R);
  144. this.m_FullbodyIK.references.rightFoot = this.GetIKBone(FullBodyIKCtrl.IKBoneType.Foot_R);
  145. this.m_FullbodyIK.solver.SetToReferences(this.m_FullbodyIK.references, null);
  146. this.m_FullbodyIK.fixTransforms = false;
  147. foreach (IKEffector ikeffector in this.m_FullbodyIK.solver.effectors)
  148. {
  149. ikeffector.positionWeight = 0f;
  150. ikeffector.rotationWeight = 0f;
  151. }
  152. foreach (FBIKChain fbikchain in this.m_FullbodyIK.solver.chain)
  153. {
  154. fbikchain.bendConstraint.weight = 0f;
  155. }
  156. this.m_BodyCtrlData = this.SafeAddBodyCtrlData("体全体");
  157. this.AddLimbIKData(FullBodyIKCtrl.IKBoneType.Hand_L, FullBodyIKCtrl.IKBoneType.Forearm_L, FullBodyIKCtrl.IKBoneType.UpperArm_L, FullBodyBipedEffector.LeftHand, FullBodyBipedEffector.LeftShoulder, true);
  158. this.AddLimbIKData(FullBodyIKCtrl.IKBoneType.Hand_R, FullBodyIKCtrl.IKBoneType.Forearm_R, FullBodyIKCtrl.IKBoneType.UpperArm_R, FullBodyBipedEffector.RightHand, FullBodyBipedEffector.RightShoulder, true);
  159. this.AddLimbIKData(FullBodyIKCtrl.IKBoneType.Foot_L, FullBodyIKCtrl.IKBoneType.Calf_L, FullBodyIKCtrl.IKBoneType.Thigh_L, FullBodyBipedEffector.LeftFoot, FullBodyBipedEffector.LeftThigh, false);
  160. this.AddLimbIKData(FullBodyIKCtrl.IKBoneType.Foot_R, FullBodyIKCtrl.IKBoneType.Calf_R, FullBodyIKCtrl.IKBoneType.Thigh_R, FullBodyBipedEffector.RightFoot, FullBodyBipedEffector.RightThigh, false);
  161. this.GetIKData<HandFootIKData>(FullBodyIKCtrl.IKBoneType.Foot_L).Chain.pull = 0f;
  162. this.GetIKData<HandFootIKData>(FullBodyIKCtrl.IKBoneType.Foot_R).Chain.pull = 0f;
  163. if (!this.BodyTarget)
  164. {
  165. Transform transform = this.m_IKTgtRoot.Find(this.BodyEffector.bone.name);
  166. if (!transform)
  167. {
  168. transform = new GameObject(this.BodyEffector.bone.name).transform;
  169. }
  170. transform.SetParent(this.m_IKTgtRoot, false);
  171. this.BodyTarget = new GameObject("IKTarget").transform;
  172. this.BodyTarget.SetParent(transform, false);
  173. }
  174. this.BodyEffector.target = this.BodyTarget;
  175. this.BodyEffector.effectChildNodes = false;
  176. this.m_FullbodyIK.enabled = false;
  177. }
  178. private BodyCtrlData SafeAddBodyCtrlData(string key_str)
  179. {
  180. BodyCtrlData bodyCtrlData = new BodyCtrlData(this);
  181. if (this.m_StrIKDataPair.ContainsKey(key_str))
  182. {
  183. this.m_StrIKDataPair[key_str] = bodyCtrlData;
  184. }
  185. else
  186. {
  187. this.m_StrIKDataPair.Add(key_str, bodyCtrlData);
  188. }
  189. this.m_BodyCtrlData = bodyCtrlData;
  190. return (BodyCtrlData)this.m_StrIKDataPair[key_str];
  191. }
  192. private LimbIKData[] AddLimbIKData(FullBodyIKCtrl.IKBoneType hand_foot, FullBodyIKCtrl.IKBoneType elbow_knee, FullBodyIKCtrl.IKBoneType shoulder_thigh, FullBodyBipedEffector handfoot_effector, FullBodyBipedEffector shoulderthigh_effector, bool use_old = false)
  193. {
  194. IKSolverFullBodyBiped solver = this.FullbodyIK.solver;
  195. IKMappingLimb limbMapping = solver.GetLimbMapping(handfoot_effector);
  196. FBIKChain chain = solver.GetChain(handfoot_effector);
  197. ShoulderThighIKData shoulderThighIKData = new ShoulderThighIKData(solver.GetEffector(shoulderthigh_effector), chain, limbMapping, this, this.GetIKBone(shoulder_thigh));
  198. this.m_StrIKDataPair[FullBodyIKCtrl.IKBoneTypeStrDic[shoulder_thigh]] = shoulderThighIKData;
  199. ElbowKneeIKData elbowKneeIKData = new ElbowKneeIKData(chain, this, this.GetIKBone(elbow_knee));
  200. this.m_StrIKDataPair[FullBodyIKCtrl.IKBoneTypeStrDic[elbow_knee]] = elbowKneeIKData;
  201. HandFootIKData handFootIKData = new HandFootIKData(solver.GetEffector(handfoot_effector), chain, limbMapping, this, this.GetIKBone(hand_foot), use_old);
  202. this.m_StrIKDataPair[FullBodyIKCtrl.IKBoneTypeStrDic[hand_foot]] = handFootIKData;
  203. shoulderThighIKData.SetChainData(handFootIKData, elbowKneeIKData);
  204. elbowKneeIKData.SetChainData(handFootIKData, shoulderThighIKData);
  205. handFootIKData.SetChainData(elbowKneeIKData, shoulderThighIKData);
  206. return new LimbIKData[]
  207. {
  208. shoulderThighIKData,
  209. elbowKneeIKData,
  210. handFootIKData
  211. };
  212. }
  213. private void Update()
  214. {
  215. this.IsUpdateEnd = false;
  216. if (this.IKActive)
  217. {
  218. this.BodyCtrlData.CharaPosReset();
  219. }
  220. }
  221. private void OnDestroy()
  222. {
  223. if (this.m_IKTgtRoot)
  224. {
  225. UnityEngine.Object.Destroy(this.m_IKTgtRoot);
  226. }
  227. }
  228. public void IKUpdate()
  229. {
  230. this.BodyEffector.positionWeight = 1f;
  231. this.BodyTarget.position = this.BodyEffector.bone.position;
  232. this.IsUpdateLate = false;
  233. foreach (IKCtrlData ikctrlData in this.m_StrIKDataPair.Values)
  234. {
  235. ikctrlData.TagetTransCpy();
  236. }
  237. this.BodyCtrlData.ApplyIKSetting();
  238. if (this.IsUpdateLate)
  239. {
  240. return;
  241. }
  242. if (this.BodyCtrlData.IsIKExec)
  243. {
  244. this.BodyCtrlData.Update();
  245. }
  246. foreach (IKCtrlData ikctrlData2 in this.m_StrIKDataPair.Values)
  247. {
  248. if (!(ikctrlData2 is BodyCtrlData))
  249. {
  250. ikctrlData2.ApplyIKSetting();
  251. }
  252. }
  253. if (!this.IsUpdateLate)
  254. {
  255. if (this.IsIKExec || this.AllForceIK)
  256. {
  257. this.SolverUpdate();
  258. }
  259. else
  260. {
  261. foreach (IKCtrlData ikctrlData3 in this.m_StrIKDataPair.Values)
  262. {
  263. ikctrlData3.SaveLastBonePosRot();
  264. }
  265. }
  266. }
  267. }
  268. public void AttachPointTransCpy(Transform trans, string slot_name, string attach_name, bool scale_cpy = false)
  269. {
  270. int slotNo = this.TgtBody.GetSlotNo(slot_name);
  271. if (this.TgtBody.goSlot[slotNo].morph == null)
  272. {
  273. return;
  274. }
  275. Vector3 position;
  276. Quaternion rotation;
  277. Vector3 localScale;
  278. this.TgtBody.goSlot[slotNo].morph.GetAttachPoint(attach_name, out position, out rotation, out localScale, false);
  279. trans.position = position;
  280. trans.rotation = rotation;
  281. if (scale_cpy)
  282. {
  283. trans.localScale = localScale;
  284. }
  285. }
  286. public void SolverUpdate()
  287. {
  288. this.IsUpdateEnd = true;
  289. Action postSolverUpdate = this.PostSolverUpdate;
  290. this.PostSolverUpdate = null;
  291. if (this.IKActive)
  292. {
  293. bool flag = false;
  294. foreach (IKCtrlData ikctrlData in this.m_StrIKDataPair.Values)
  295. {
  296. if (!(ikctrlData is BodyCtrlData))
  297. {
  298. if (ikctrlData.IsIKExec && !ikctrlData.OldIkExec)
  299. {
  300. flag = true;
  301. break;
  302. }
  303. }
  304. }
  305. if (flag)
  306. {
  307. Vector3 localPosition = this.m_FullbodyIK.references.spine[1].localPosition;
  308. this.m_FullbodyIK.solver.Update();
  309. this.m_FullbodyIK.references.spine[1].localPosition = localPosition;
  310. foreach (IKCtrlData ikctrlData2 in this.m_StrIKDataPair.Values)
  311. {
  312. if (!(ikctrlData2 is BodyCtrlData) && !(ikctrlData2 is LimbIKData))
  313. {
  314. if (ikctrlData2.IsIKExec)
  315. {
  316. ikctrlData2.Update();
  317. }
  318. }
  319. }
  320. }
  321. }
  322. foreach (IKCtrlData ikctrlData3 in this.m_StrIKDataPair.Values)
  323. {
  324. ikctrlData3.LateUpdate();
  325. }
  326. if (this.IKActive && postSolverUpdate != null)
  327. {
  328. postSolverUpdate();
  329. }
  330. }
  331. public void LateIKUpdate()
  332. {
  333. this.IKUpdate();
  334. this.TgtBody.AutoTwist();
  335. for (int i = 0; i < this.TgtBody.goSlot.Count; i++)
  336. {
  337. if (this.TgtBody.goSlot[i].obj != null)
  338. {
  339. this.TgtBody.goSlot[i].CopyTrans();
  340. }
  341. this.TgtBody.goSlot[i].Update();
  342. }
  343. }
  344. public Transform GetIKBone(FullBodyIKCtrl.IKBoneType boneType)
  345. {
  346. return (!this.m_IKBoneDic.ContainsKey(boneType)) ? null : this.m_IKBoneDic[boneType];
  347. }
  348. public Transform[] GetChainBonesToInit(FullBodyIKCtrl.IKBoneType boneType)
  349. {
  350. Transform[] result = new Transform[0];
  351. switch (boneType)
  352. {
  353. case FullBodyIKCtrl.IKBoneType.UpperArm_R:
  354. case FullBodyIKCtrl.IKBoneType.Forearm_R:
  355. case FullBodyIKCtrl.IKBoneType.Hand_R:
  356. result = new Transform[]
  357. {
  358. this.GetIKBone(FullBodyIKCtrl.IKBoneType.UpperArm_R),
  359. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Forearm_R),
  360. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Hand_R)
  361. };
  362. break;
  363. case FullBodyIKCtrl.IKBoneType.UpperArm_L:
  364. case FullBodyIKCtrl.IKBoneType.Forearm_L:
  365. case FullBodyIKCtrl.IKBoneType.Hand_L:
  366. result = new Transform[]
  367. {
  368. this.GetIKBone(FullBodyIKCtrl.IKBoneType.UpperArm_L),
  369. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Forearm_L),
  370. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Hand_L)
  371. };
  372. break;
  373. case FullBodyIKCtrl.IKBoneType.Thigh_R:
  374. case FullBodyIKCtrl.IKBoneType.Calf_R:
  375. case FullBodyIKCtrl.IKBoneType.Foot_R:
  376. result = new Transform[]
  377. {
  378. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Thigh_R),
  379. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Calf_R),
  380. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Foot_R)
  381. };
  382. break;
  383. case FullBodyIKCtrl.IKBoneType.Thigh_L:
  384. case FullBodyIKCtrl.IKBoneType.Calf_L:
  385. case FullBodyIKCtrl.IKBoneType.Foot_L:
  386. result = new Transform[]
  387. {
  388. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Thigh_L),
  389. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Calf_L),
  390. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Foot_L)
  391. };
  392. break;
  393. }
  394. return result;
  395. }
  396. public IKCtrlData GetIKData(string tag_name, bool flagcheck = false)
  397. {
  398. return this.GetIKData(tag_name);
  399. }
  400. public IKCtrlData GetIKData(string tag_name)
  401. {
  402. if (this.m_StrIKDataPair.ContainsKey(tag_name))
  403. {
  404. return this.m_StrIKDataPair[tag_name];
  405. }
  406. return null;
  407. }
  408. public T GetIKData<T>(string tag_name) where T : IKCtrlData
  409. {
  410. IKCtrlData ikdata = this.GetIKData(tag_name);
  411. if (ikdata != null && ikdata is T)
  412. {
  413. return ikdata as T;
  414. }
  415. return (T)((object)null);
  416. }
  417. public IKCtrlData GetIKData(FullBodyIKCtrl.IKBoneType bone_type)
  418. {
  419. if (FullBodyIKCtrl.IKBoneTypeStrDic.ContainsKey(bone_type))
  420. {
  421. return this.GetIKData(FullBodyIKCtrl.IKBoneTypeStrDic[bone_type]);
  422. }
  423. return null;
  424. }
  425. public T GetIKData<T>(FullBodyIKCtrl.IKBoneType bone_type) where T : IKCtrlData
  426. {
  427. IKCtrlData ikdata = this.GetIKData(bone_type);
  428. if (ikdata != null && ikdata is T)
  429. {
  430. return ikdata as T;
  431. }
  432. return (T)((object)null);
  433. }
  434. public Transform GetSTFlagObj(string name)
  435. {
  436. if (this.m_NameFlagObjpair.ContainsKey(name))
  437. {
  438. return this.m_NameFlagObjpair[name];
  439. }
  440. Transform transform = this.m_STRoot.Find(name);
  441. if (!transform)
  442. {
  443. transform = this.TgtBody.GetBone(name);
  444. if (!transform)
  445. {
  446. Debug.LogErrorFormat("{0}は存在しません", new object[]
  447. {
  448. name
  449. });
  450. return null;
  451. }
  452. }
  453. this.m_NameFlagObjpair.Add(name, transform);
  454. return transform;
  455. }
  456. public bool IsCharaIKAttach(Maid chara)
  457. {
  458. if (!this.IKActive || !this.IsIKExec)
  459. {
  460. return false;
  461. }
  462. foreach (IKCtrlData ikctrlData in this.strIKDataPair.Values)
  463. {
  464. if (ikctrlData.IsIKTargetChara(chara))
  465. {
  466. return true;
  467. }
  468. }
  469. return false;
  470. }
  471. public bool IsTargetIKAttachSelf(bool check_ikend = true)
  472. {
  473. if (!this.IKActive || !this.IsIKExec)
  474. {
  475. return false;
  476. }
  477. using (Dictionary<string, IKCtrlData>.ValueCollection.Enumerator enumerator = this.strIKDataPair.Values.GetEnumerator())
  478. {
  479. while (enumerator.MoveNext())
  480. {
  481. IKCtrlData ik_data = enumerator.Current;
  482. Func<IKCtrlData.IKAttachType, bool> func = delegate(IKCtrlData.IKAttachType attach_type)
  483. {
  484. IKCtrlData.IKSettingData iksettingData = ik_data.GetIKSettingData(attach_type);
  485. foreach (IKCtrlData.IKExecTiming exec_timing in (IKCtrlData.IKExecTiming[])Enum.GetValues(typeof(IKCtrlData.IKExecTiming)))
  486. {
  487. IKCtrlData.IKTargetData targetData = ik_data.GetTargetData(attach_type, exec_timing);
  488. if (targetData.TgtChara)
  489. {
  490. bool flag;
  491. if (check_ikend)
  492. {
  493. flag = (targetData.TgtChara.IKCtrl.IsCharaIKAttach(this.TgtChara) && !targetData.TgtChara.IKCtrl.IsUpdateEnd && !targetData.TgtChara.IKCtrl.IsUpdateLate);
  494. }
  495. else
  496. {
  497. flag = targetData.TgtChara.IKCtrl.IsCharaIKAttach(this.TgtChara);
  498. }
  499. if (flag)
  500. {
  501. return true;
  502. }
  503. }
  504. }
  505. return false;
  506. };
  507. if (func(IKCtrlData.IKAttachType.NewPoint) || func(IKCtrlData.IKAttachType.Rotate))
  508. {
  509. return true;
  510. }
  511. }
  512. }
  513. return false;
  514. }
  515. public static Dictionary<FullBodyIKCtrl.IKBoneType, Transform> GetAllIKBoneDic(Maid chara)
  516. {
  517. if (chara == null)
  518. {
  519. return null;
  520. }
  521. NDebug.Assert(chara.body0 != null, "[body0] it does not end load.");
  522. string text = (!chara.boMAN) ? "Bip01" : "ManBip";
  523. Dictionary<FullBodyIKCtrl.IKBoneType, Transform> dictionary = new Dictionary<FullBodyIKCtrl.IKBoneType, Transform>();
  524. dictionary.Add(FullBodyIKCtrl.IKBoneType.TopFixed, chara.body0.GetBone(text).parent);
  525. dictionary.Add(FullBodyIKCtrl.IKBoneType.Root, chara.body0.GetBone(text));
  526. dictionary.Add(FullBodyIKCtrl.IKBoneType.Pelvis, chara.body0.GetBone(text + " Pelvis"));
  527. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine0, chara.body0.GetBone(text + " Spine"));
  528. if (!chara.boMAN)
  529. {
  530. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine1, chara.body0.GetBone(text + " Spine0a"));
  531. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine2, chara.body0.GetBone(text + " Spine1"));
  532. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine3, chara.body0.GetBone(text + " Spine1a"));
  533. }
  534. else
  535. {
  536. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine1, chara.body0.GetBone(text + " Spine1"));
  537. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine2, chara.body0.GetBone(text + " Spine2"));
  538. }
  539. dictionary.Add(FullBodyIKCtrl.IKBoneType.Head, chara.body0.GetBone(text + " Head"));
  540. dictionary.Add(FullBodyIKCtrl.IKBoneType.Neck, chara.body0.GetBone(text + " Neck"));
  541. dictionary.Add(FullBodyIKCtrl.IKBoneType.UpperArm_R, chara.body0.GetBone(text + " R UpperArm"));
  542. dictionary.Add(FullBodyIKCtrl.IKBoneType.Forearm_R, chara.body0.GetBone(text + " R Forearm"));
  543. dictionary.Add(FullBodyIKCtrl.IKBoneType.Hand_R, chara.body0.GetBone(text + " R Hand"));
  544. dictionary.Add(FullBodyIKCtrl.IKBoneType.UpperArm_L, chara.body0.GetBone(text + " L UpperArm"));
  545. dictionary.Add(FullBodyIKCtrl.IKBoneType.Forearm_L, chara.body0.GetBone(text + " L Forearm"));
  546. dictionary.Add(FullBodyIKCtrl.IKBoneType.Hand_L, chara.body0.GetBone(text + " L Hand"));
  547. dictionary.Add(FullBodyIKCtrl.IKBoneType.Thigh_R, chara.body0.GetBone(text + " R Thigh"));
  548. dictionary.Add(FullBodyIKCtrl.IKBoneType.Calf_R, chara.body0.GetBone(text + " R Calf"));
  549. dictionary.Add(FullBodyIKCtrl.IKBoneType.Foot_R, chara.body0.GetBone(text + " R Foot"));
  550. dictionary.Add(FullBodyIKCtrl.IKBoneType.Thigh_L, chara.body0.GetBone(text + " L Thigh"));
  551. dictionary.Add(FullBodyIKCtrl.IKBoneType.Calf_L, chara.body0.GetBone(text + " L Calf"));
  552. dictionary.Add(FullBodyIKCtrl.IKBoneType.Foot_L, chara.body0.GetBone(text + " L Foot"));
  553. return dictionary;
  554. }
  555. public const float PULL_MIN_VALUE = 0.1f;
  556. public static readonly Dictionary<FullBodyIKCtrl.IKBoneType, string> IKBoneTypeStrDic = new Dictionary<FullBodyIKCtrl.IKBoneType, string>
  557. {
  558. {
  559. FullBodyIKCtrl.IKBoneType.Root,
  560. "体全体"
  561. },
  562. {
  563. FullBodyIKCtrl.IKBoneType.Hand_R,
  564. "右手"
  565. },
  566. {
  567. FullBodyIKCtrl.IKBoneType.Forearm_R,
  568. "右肘"
  569. },
  570. {
  571. FullBodyIKCtrl.IKBoneType.UpperArm_R,
  572. "右肩"
  573. },
  574. {
  575. FullBodyIKCtrl.IKBoneType.Hand_L,
  576. "左手"
  577. },
  578. {
  579. FullBodyIKCtrl.IKBoneType.Forearm_L,
  580. "左肘"
  581. },
  582. {
  583. FullBodyIKCtrl.IKBoneType.UpperArm_L,
  584. "左肩"
  585. },
  586. {
  587. FullBodyIKCtrl.IKBoneType.Foot_R,
  588. "右足"
  589. },
  590. {
  591. FullBodyIKCtrl.IKBoneType.Calf_R,
  592. "右膝"
  593. },
  594. {
  595. FullBodyIKCtrl.IKBoneType.Thigh_R,
  596. "右腿"
  597. },
  598. {
  599. FullBodyIKCtrl.IKBoneType.Foot_L,
  600. "左足"
  601. },
  602. {
  603. FullBodyIKCtrl.IKBoneType.Calf_L,
  604. "左膝"
  605. },
  606. {
  607. FullBodyIKCtrl.IKBoneType.Thigh_L,
  608. "左腿"
  609. }
  610. };
  611. [SerializeField]
  612. private TBody m_TgtBody;
  613. [SerializeField]
  614. private Transform m_IKTgtRoot;
  615. [SerializeField]
  616. private Transform m_STRoot;
  617. [SerializeField]
  618. private FullBodyBipedIK m_FullbodyIK;
  619. private Dictionary<FullBodyIKCtrl.IKBoneType, Transform> m_IKBoneDic = new Dictionary<FullBodyIKCtrl.IKBoneType, Transform>();
  620. [SerializeField]
  621. private BodyCtrlData m_BodyCtrlData;
  622. private Transform m_NippleL;
  623. private Transform m_NippleR;
  624. private Transform m_Mouth;
  625. private Dictionary<string, IKCtrlData> m_StrIKDataPair = new Dictionary<string, IKCtrlData>();
  626. private Dictionary<string, Transform> m_NameFlagObjpair = new Dictionary<string, Transform>();
  627. public bool IKActive = true;
  628. [HideInInspector]
  629. public bool IsUpdateLate;
  630. public Action PostSolverUpdate;
  631. public bool AllForceIK;
  632. public float BlendTime = 0.5f;
  633. public enum IKBoneType
  634. {
  635. TopFixed,
  636. Root,
  637. Spine0,
  638. Spine1,
  639. Spine2,
  640. Spine3,
  641. Neck,
  642. Head,
  643. Clavicle_R,
  644. UpperArm_R,
  645. Forearm_R,
  646. Hand_R,
  647. Clavicle_L,
  648. UpperArm_L,
  649. Forearm_L,
  650. Hand_L,
  651. Pelvis,
  652. Thigh_R,
  653. Calf_R,
  654. Foot_R,
  655. Thigh_L,
  656. Calf_L,
  657. Foot_L
  658. }
  659. }