FullBodyIKCtrl.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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.FullbodyIK.solver.GetChain(FullBodyBipedChain.LeftLeg).pull = 0f;
  158. this.FullbodyIK.solver.GetChain(FullBodyBipedChain.RightLeg).pull = 0f;
  159. this.AddLimbIKData(FullBodyIKCtrl.IKBoneType.Hand_L, FullBodyIKCtrl.IKBoneType.Forearm_L, FullBodyIKCtrl.IKBoneType.UpperArm_L, FullBodyBipedEffector.LeftHand, FullBodyBipedEffector.LeftShoulder, true);
  160. this.AddLimbIKData(FullBodyIKCtrl.IKBoneType.Hand_R, FullBodyIKCtrl.IKBoneType.Forearm_R, FullBodyIKCtrl.IKBoneType.UpperArm_R, FullBodyBipedEffector.RightHand, FullBodyBipedEffector.RightShoulder, true);
  161. this.AddLimbIKData(FullBodyIKCtrl.IKBoneType.Foot_L, FullBodyIKCtrl.IKBoneType.Calf_L, FullBodyIKCtrl.IKBoneType.Thigh_L, FullBodyBipedEffector.LeftFoot, FullBodyBipedEffector.LeftThigh, false);
  162. this.AddLimbIKData(FullBodyIKCtrl.IKBoneType.Foot_R, FullBodyIKCtrl.IKBoneType.Calf_R, FullBodyIKCtrl.IKBoneType.Thigh_R, FullBodyBipedEffector.RightFoot, FullBodyBipedEffector.RightThigh, false);
  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, limbMapping, 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. if (!this.m_IsPelvisPull)
  231. {
  232. this.BodyEffector.positionWeight = 1f;
  233. }
  234. else
  235. {
  236. this.BodyEffector.positionWeight = 0f;
  237. }
  238. this.BodyTarget.position = this.BodyEffector.bone.position;
  239. this.IsUpdateLate = false;
  240. foreach (IKCtrlData ikctrlData in this.m_StrIKDataPair.Values)
  241. {
  242. ikctrlData.TagetTransCpy();
  243. }
  244. this.BodyCtrlData.ApplyIKSetting();
  245. if (this.IsUpdateLate)
  246. {
  247. return;
  248. }
  249. if (this.BodyCtrlData.IsIKExec)
  250. {
  251. this.BodyCtrlData.Update();
  252. }
  253. foreach (IKCtrlData ikctrlData2 in this.m_StrIKDataPair.Values)
  254. {
  255. if (!(ikctrlData2 is BodyCtrlData))
  256. {
  257. ikctrlData2.ApplyIKSetting();
  258. }
  259. }
  260. if (!this.IsUpdateLate)
  261. {
  262. if (this.IsIKExec || this.AllForceIK)
  263. {
  264. this.SolverUpdate();
  265. }
  266. else
  267. {
  268. foreach (IKCtrlData ikctrlData3 in this.m_StrIKDataPair.Values)
  269. {
  270. ikctrlData3.SaveLastBonePosRot();
  271. }
  272. }
  273. }
  274. }
  275. public void AttachPointTransCpy(Transform trans, string slot_name, string attach_name, bool scale_cpy = false)
  276. {
  277. int slotNo = this.TgtBody.GetSlotNo(slot_name);
  278. if (this.TgtBody.goSlot[slotNo].morph == null)
  279. {
  280. return;
  281. }
  282. Vector3 position;
  283. Quaternion rotation;
  284. Vector3 localScale;
  285. this.TgtBody.goSlot[slotNo].morph.GetAttachPoint(attach_name, out position, out rotation, out localScale, false);
  286. trans.position = position;
  287. trans.rotation = rotation;
  288. if (scale_cpy)
  289. {
  290. trans.localScale = localScale;
  291. }
  292. }
  293. public void SolverUpdate()
  294. {
  295. this.IsUpdateEnd = true;
  296. Action postSolverUpdate = this.PostSolverUpdate;
  297. this.PostSolverUpdate = null;
  298. if (this.IKActive)
  299. {
  300. bool flag = false;
  301. foreach (IKCtrlData ikctrlData in this.m_StrIKDataPair.Values)
  302. {
  303. if (!(ikctrlData is BodyCtrlData))
  304. {
  305. if (ikctrlData.NeedFullbodySolverUpdate)
  306. {
  307. flag = true;
  308. break;
  309. }
  310. }
  311. }
  312. if (flag)
  313. {
  314. Vector3 localPosition = this.m_FullbodyIK.references.spine[1].localPosition;
  315. this.m_FullbodyIK.solver.Update();
  316. this.m_FullbodyIK.references.spine[1].localPosition = localPosition;
  317. }
  318. foreach (IKCtrlData ikctrlData2 in this.m_StrIKDataPair.Values)
  319. {
  320. if (!(ikctrlData2 is BodyCtrlData))
  321. {
  322. if (ikctrlData2.IsIKExec)
  323. {
  324. ikctrlData2.Update();
  325. }
  326. }
  327. }
  328. }
  329. foreach (IKCtrlData ikctrlData3 in this.m_StrIKDataPair.Values)
  330. {
  331. ikctrlData3.LateUpdate();
  332. }
  333. if (this.IKActive && postSolverUpdate != null)
  334. {
  335. postSolverUpdate();
  336. }
  337. }
  338. public void LateIKUpdate()
  339. {
  340. this.IKUpdate();
  341. this.TgtBody.AutoTwist();
  342. this.TgtBody.SkinMeshUpdate();
  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 void SetPelvisPull(bool pull_on)
  516. {
  517. this.m_IsPelvisPull = pull_on;
  518. }
  519. public static Dictionary<FullBodyIKCtrl.IKBoneType, Transform> GetAllIKBoneDic(Maid chara)
  520. {
  521. if (chara == null)
  522. {
  523. return null;
  524. }
  525. NDebug.Assert(chara.body0 != null, "[body0] it does not end load.");
  526. string text = (!chara.boMAN) ? "Bip01" : "ManBip";
  527. Dictionary<FullBodyIKCtrl.IKBoneType, Transform> dictionary = new Dictionary<FullBodyIKCtrl.IKBoneType, Transform>();
  528. dictionary.Add(FullBodyIKCtrl.IKBoneType.TopFixed, chara.body0.GetBone(text).parent);
  529. dictionary.Add(FullBodyIKCtrl.IKBoneType.Root, chara.body0.GetBone(text));
  530. dictionary.Add(FullBodyIKCtrl.IKBoneType.Pelvis, chara.body0.GetBone(text + " Pelvis"));
  531. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine0, chara.body0.GetBone(text + " Spine"));
  532. if (!chara.boMAN)
  533. {
  534. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine1, chara.body0.GetBone(text + " Spine0a"));
  535. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine2, chara.body0.GetBone(text + " Spine1"));
  536. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine3, chara.body0.GetBone(text + " Spine1a"));
  537. }
  538. else
  539. {
  540. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine1, chara.body0.GetBone(text + " Spine1"));
  541. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine2, chara.body0.GetBone(text + " Spine2"));
  542. }
  543. dictionary.Add(FullBodyIKCtrl.IKBoneType.Head, chara.body0.GetBone(text + " Head"));
  544. dictionary.Add(FullBodyIKCtrl.IKBoneType.Neck, chara.body0.GetBone(text + " Neck"));
  545. dictionary.Add(FullBodyIKCtrl.IKBoneType.UpperArm_R, chara.body0.GetBone(text + " R UpperArm"));
  546. dictionary.Add(FullBodyIKCtrl.IKBoneType.Forearm_R, chara.body0.GetBone(text + " R Forearm"));
  547. dictionary.Add(FullBodyIKCtrl.IKBoneType.Hand_R, chara.body0.GetBone(text + " R Hand"));
  548. dictionary.Add(FullBodyIKCtrl.IKBoneType.UpperArm_L, chara.body0.GetBone(text + " L UpperArm"));
  549. dictionary.Add(FullBodyIKCtrl.IKBoneType.Forearm_L, chara.body0.GetBone(text + " L Forearm"));
  550. dictionary.Add(FullBodyIKCtrl.IKBoneType.Hand_L, chara.body0.GetBone(text + " L Hand"));
  551. dictionary.Add(FullBodyIKCtrl.IKBoneType.Thigh_R, chara.body0.GetBone(text + " R Thigh"));
  552. dictionary.Add(FullBodyIKCtrl.IKBoneType.Calf_R, chara.body0.GetBone(text + " R Calf"));
  553. dictionary.Add(FullBodyIKCtrl.IKBoneType.Foot_R, chara.body0.GetBone(text + " R Foot"));
  554. dictionary.Add(FullBodyIKCtrl.IKBoneType.Thigh_L, chara.body0.GetBone(text + " L Thigh"));
  555. dictionary.Add(FullBodyIKCtrl.IKBoneType.Calf_L, chara.body0.GetBone(text + " L Calf"));
  556. dictionary.Add(FullBodyIKCtrl.IKBoneType.Foot_L, chara.body0.GetBone(text + " L Foot"));
  557. return dictionary;
  558. }
  559. public const float PULL_MIN_VALUE = 0.1f;
  560. public static readonly Dictionary<FullBodyIKCtrl.IKBoneType, string> IKBoneTypeStrDic = new Dictionary<FullBodyIKCtrl.IKBoneType, string>
  561. {
  562. {
  563. FullBodyIKCtrl.IKBoneType.Root,
  564. "体全体"
  565. },
  566. {
  567. FullBodyIKCtrl.IKBoneType.Hand_R,
  568. "右手"
  569. },
  570. {
  571. FullBodyIKCtrl.IKBoneType.Forearm_R,
  572. "右肘"
  573. },
  574. {
  575. FullBodyIKCtrl.IKBoneType.UpperArm_R,
  576. "右肩"
  577. },
  578. {
  579. FullBodyIKCtrl.IKBoneType.Hand_L,
  580. "左手"
  581. },
  582. {
  583. FullBodyIKCtrl.IKBoneType.Forearm_L,
  584. "左肘"
  585. },
  586. {
  587. FullBodyIKCtrl.IKBoneType.UpperArm_L,
  588. "左肩"
  589. },
  590. {
  591. FullBodyIKCtrl.IKBoneType.Foot_R,
  592. "右足"
  593. },
  594. {
  595. FullBodyIKCtrl.IKBoneType.Calf_R,
  596. "右膝"
  597. },
  598. {
  599. FullBodyIKCtrl.IKBoneType.Thigh_R,
  600. "右腿"
  601. },
  602. {
  603. FullBodyIKCtrl.IKBoneType.Foot_L,
  604. "左足"
  605. },
  606. {
  607. FullBodyIKCtrl.IKBoneType.Calf_L,
  608. "左膝"
  609. },
  610. {
  611. FullBodyIKCtrl.IKBoneType.Thigh_L,
  612. "左腿"
  613. }
  614. };
  615. [SerializeField]
  616. private TBody m_TgtBody;
  617. [SerializeField]
  618. private Transform m_IKTgtRoot;
  619. [SerializeField]
  620. private Transform m_STRoot;
  621. [SerializeField]
  622. private FullBodyBipedIK m_FullbodyIK;
  623. private Dictionary<FullBodyIKCtrl.IKBoneType, Transform> m_IKBoneDic = new Dictionary<FullBodyIKCtrl.IKBoneType, Transform>();
  624. [SerializeField]
  625. private BodyCtrlData m_BodyCtrlData;
  626. private Transform m_NippleL;
  627. private Transform m_NippleR;
  628. private Transform m_Mouth;
  629. private Dictionary<string, IKCtrlData> m_StrIKDataPair = new Dictionary<string, IKCtrlData>();
  630. private Dictionary<string, Transform> m_NameFlagObjpair = new Dictionary<string, Transform>();
  631. public bool IKActive = true;
  632. [HideInInspector]
  633. public bool IsUpdateLate;
  634. public Action PostSolverUpdate;
  635. public bool AllForceIK;
  636. public float BlendTime = 0.5f;
  637. private bool m_IsPelvisPull;
  638. public enum IKBoneType
  639. {
  640. TopFixed,
  641. Root,
  642. Spine0,
  643. Spine1,
  644. Spine2,
  645. Spine3,
  646. Neck,
  647. Head,
  648. Clavicle_R,
  649. UpperArm_R,
  650. Forearm_R,
  651. Hand_R,
  652. Clavicle_L,
  653. UpperArm_L,
  654. Forearm_L,
  655. Hand_L,
  656. Pelvis,
  657. Thigh_R,
  658. Calf_R,
  659. Foot_R,
  660. Thigh_L,
  661. Calf_L,
  662. Foot_L
  663. }
  664. }