FullBodyIKCtrl.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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.FullbodyIK.solver.spineStiffness = 0f;
  177. this.m_FullbodyIK.enabled = false;
  178. }
  179. private BodyCtrlData SafeAddBodyCtrlData(string key_str)
  180. {
  181. BodyCtrlData bodyCtrlData = new BodyCtrlData(this);
  182. if (this.m_StrIKDataPair.ContainsKey(key_str))
  183. {
  184. this.m_StrIKDataPair[key_str] = bodyCtrlData;
  185. }
  186. else
  187. {
  188. this.m_StrIKDataPair.Add(key_str, bodyCtrlData);
  189. }
  190. this.m_BodyCtrlData = bodyCtrlData;
  191. return (BodyCtrlData)this.m_StrIKDataPair[key_str];
  192. }
  193. 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)
  194. {
  195. IKSolverFullBodyBiped solver = this.FullbodyIK.solver;
  196. IKMappingLimb limbMapping = solver.GetLimbMapping(handfoot_effector);
  197. FBIKChain chain = solver.GetChain(handfoot_effector);
  198. ShoulderThighIKData shoulderThighIKData = new ShoulderThighIKData(solver.GetEffector(shoulderthigh_effector), chain, limbMapping, this, this.GetIKBone(shoulder_thigh));
  199. this.m_StrIKDataPair[FullBodyIKCtrl.IKBoneTypeStrDic[shoulder_thigh]] = shoulderThighIKData;
  200. ElbowKneeIKData elbowKneeIKData = new ElbowKneeIKData(chain, limbMapping, this, this.GetIKBone(elbow_knee));
  201. this.m_StrIKDataPair[FullBodyIKCtrl.IKBoneTypeStrDic[elbow_knee]] = elbowKneeIKData;
  202. HandFootIKData handFootIKData = new HandFootIKData(solver.GetEffector(handfoot_effector), chain, limbMapping, this, this.GetIKBone(hand_foot), use_old);
  203. this.m_StrIKDataPair[FullBodyIKCtrl.IKBoneTypeStrDic[hand_foot]] = handFootIKData;
  204. shoulderThighIKData.SetChainData(handFootIKData, elbowKneeIKData);
  205. elbowKneeIKData.SetChainData(handFootIKData, shoulderThighIKData);
  206. handFootIKData.SetChainData(elbowKneeIKData, shoulderThighIKData);
  207. return new LimbIKData[]
  208. {
  209. shoulderThighIKData,
  210. elbowKneeIKData,
  211. handFootIKData
  212. };
  213. }
  214. private void Update()
  215. {
  216. this.IsUpdateEnd = false;
  217. if (this.IKActive)
  218. {
  219. this.BodyCtrlData.CharaPosReset();
  220. }
  221. }
  222. private void OnDestroy()
  223. {
  224. if (this.m_IKTgtRoot)
  225. {
  226. UnityEngine.Object.Destroy(this.m_IKTgtRoot);
  227. }
  228. }
  229. public void IKUpdate()
  230. {
  231. if (!this.m_IsPelvisPull)
  232. {
  233. this.BodyEffector.positionWeight = 1f;
  234. }
  235. else
  236. {
  237. this.BodyEffector.positionWeight = 0f;
  238. }
  239. this.BodyTarget.position = this.BodyEffector.bone.position;
  240. this.IsUpdateLate = false;
  241. foreach (IKCtrlData ikctrlData in this.m_StrIKDataPair.Values)
  242. {
  243. ikctrlData.TagetTransCpy();
  244. }
  245. this.BodyCtrlData.ApplyIKSetting();
  246. if (this.IsUpdateLate)
  247. {
  248. return;
  249. }
  250. if (this.BodyCtrlData.IsIKExec)
  251. {
  252. this.BodyCtrlData.Update();
  253. }
  254. foreach (IKCtrlData ikctrlData2 in this.m_StrIKDataPair.Values)
  255. {
  256. if (!(ikctrlData2 is BodyCtrlData))
  257. {
  258. ikctrlData2.ApplyIKSetting();
  259. }
  260. }
  261. if (!this.IsUpdateLate)
  262. {
  263. if (this.IsIKExec || this.AllForceIK)
  264. {
  265. this.SolverUpdate();
  266. }
  267. else
  268. {
  269. foreach (IKCtrlData ikctrlData3 in this.m_StrIKDataPair.Values)
  270. {
  271. ikctrlData3.SaveLastBonePosRot();
  272. }
  273. }
  274. }
  275. }
  276. public void AttachPointTransCpy(Transform trans, string slot_name, string attach_name, bool scale_cpy = false)
  277. {
  278. int slotNo = this.TgtBody.GetSlotNo(slot_name);
  279. if (this.TgtBody.goSlot[slotNo].morph == null)
  280. {
  281. return;
  282. }
  283. Vector3 position;
  284. Quaternion rotation;
  285. Vector3 localScale;
  286. this.TgtBody.goSlot[slotNo].morph.GetAttachPoint(attach_name, out position, out rotation, out localScale, false);
  287. trans.position = position;
  288. trans.rotation = rotation;
  289. if (scale_cpy)
  290. {
  291. trans.localScale = localScale;
  292. }
  293. }
  294. public void SolverUpdate()
  295. {
  296. this.IsUpdateEnd = true;
  297. Action postSolverUpdate = this.PostSolverUpdate;
  298. this.PostSolverUpdate = null;
  299. if (this.IKActive)
  300. {
  301. bool flag = false;
  302. foreach (IKCtrlData ikctrlData in this.m_StrIKDataPair.Values)
  303. {
  304. if (!(ikctrlData is BodyCtrlData))
  305. {
  306. if (ikctrlData.NeedFullbodySolverUpdate)
  307. {
  308. flag = true;
  309. break;
  310. }
  311. }
  312. }
  313. if (flag)
  314. {
  315. Vector3 localPosition = this.m_FullbodyIK.references.spine[1].localPosition;
  316. this.m_FullbodyIK.solver.Update();
  317. this.m_FullbodyIK.references.spine[1].localPosition = localPosition;
  318. }
  319. foreach (IKCtrlData ikctrlData2 in this.m_StrIKDataPair.Values)
  320. {
  321. if (!(ikctrlData2 is BodyCtrlData))
  322. {
  323. if (ikctrlData2.IsIKExec)
  324. {
  325. ikctrlData2.Update();
  326. }
  327. }
  328. }
  329. }
  330. foreach (IKCtrlData ikctrlData3 in this.m_StrIKDataPair.Values)
  331. {
  332. ikctrlData3.LateUpdate();
  333. }
  334. if (this.IKActive && postSolverUpdate != null)
  335. {
  336. postSolverUpdate();
  337. }
  338. }
  339. public void LateIKUpdate()
  340. {
  341. this.IKUpdate();
  342. this.TgtBody.AutoTwist();
  343. this.TgtBody.SkinMeshUpdate();
  344. }
  345. public Transform GetIKBone(FullBodyIKCtrl.IKBoneType boneType)
  346. {
  347. return (!this.m_IKBoneDic.ContainsKey(boneType)) ? null : this.m_IKBoneDic[boneType];
  348. }
  349. public Transform[] GetChainBonesToInit(FullBodyIKCtrl.IKBoneType boneType)
  350. {
  351. Transform[] result = new Transform[0];
  352. switch (boneType)
  353. {
  354. case FullBodyIKCtrl.IKBoneType.UpperArm_R:
  355. case FullBodyIKCtrl.IKBoneType.Forearm_R:
  356. case FullBodyIKCtrl.IKBoneType.Hand_R:
  357. result = new Transform[]
  358. {
  359. this.GetIKBone(FullBodyIKCtrl.IKBoneType.UpperArm_R),
  360. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Forearm_R),
  361. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Hand_R)
  362. };
  363. break;
  364. case FullBodyIKCtrl.IKBoneType.UpperArm_L:
  365. case FullBodyIKCtrl.IKBoneType.Forearm_L:
  366. case FullBodyIKCtrl.IKBoneType.Hand_L:
  367. result = new Transform[]
  368. {
  369. this.GetIKBone(FullBodyIKCtrl.IKBoneType.UpperArm_L),
  370. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Forearm_L),
  371. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Hand_L)
  372. };
  373. break;
  374. case FullBodyIKCtrl.IKBoneType.Thigh_R:
  375. case FullBodyIKCtrl.IKBoneType.Calf_R:
  376. case FullBodyIKCtrl.IKBoneType.Foot_R:
  377. result = new Transform[]
  378. {
  379. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Thigh_R),
  380. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Calf_R),
  381. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Foot_R)
  382. };
  383. break;
  384. case FullBodyIKCtrl.IKBoneType.Thigh_L:
  385. case FullBodyIKCtrl.IKBoneType.Calf_L:
  386. case FullBodyIKCtrl.IKBoneType.Foot_L:
  387. result = new Transform[]
  388. {
  389. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Thigh_L),
  390. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Calf_L),
  391. this.GetIKBone(FullBodyIKCtrl.IKBoneType.Foot_L)
  392. };
  393. break;
  394. }
  395. return result;
  396. }
  397. public IKCtrlData GetIKData(string tag_name, bool flagcheck = false)
  398. {
  399. return this.GetIKData(tag_name);
  400. }
  401. public IKCtrlData GetIKData(string tag_name)
  402. {
  403. if (this.m_StrIKDataPair.ContainsKey(tag_name))
  404. {
  405. return this.m_StrIKDataPair[tag_name];
  406. }
  407. return null;
  408. }
  409. public T GetIKData<T>(string tag_name) where T : IKCtrlData
  410. {
  411. IKCtrlData ikdata = this.GetIKData(tag_name);
  412. if (ikdata != null && ikdata is T)
  413. {
  414. return ikdata as T;
  415. }
  416. return (T)((object)null);
  417. }
  418. public IKCtrlData GetIKData(FullBodyIKCtrl.IKBoneType bone_type)
  419. {
  420. if (FullBodyIKCtrl.IKBoneTypeStrDic.ContainsKey(bone_type))
  421. {
  422. return this.GetIKData(FullBodyIKCtrl.IKBoneTypeStrDic[bone_type]);
  423. }
  424. return null;
  425. }
  426. public T GetIKData<T>(FullBodyIKCtrl.IKBoneType bone_type) where T : IKCtrlData
  427. {
  428. IKCtrlData ikdata = this.GetIKData(bone_type);
  429. if (ikdata != null && ikdata is T)
  430. {
  431. return ikdata as T;
  432. }
  433. return (T)((object)null);
  434. }
  435. public Transform GetSTFlagObj(string name)
  436. {
  437. if (this.m_NameFlagObjpair.ContainsKey(name))
  438. {
  439. return this.m_NameFlagObjpair[name];
  440. }
  441. Transform transform = this.m_STRoot.Find(name);
  442. if (!transform)
  443. {
  444. transform = this.TgtBody.GetBone(name);
  445. if (!transform)
  446. {
  447. Debug.LogErrorFormat("{0}は存在しません", new object[]
  448. {
  449. name
  450. });
  451. return null;
  452. }
  453. }
  454. this.m_NameFlagObjpair.Add(name, transform);
  455. return transform;
  456. }
  457. public bool IsCharaIKAttach(Maid chara)
  458. {
  459. if (!this.IKActive || !this.IsIKExec)
  460. {
  461. return false;
  462. }
  463. foreach (IKCtrlData ikctrlData in this.strIKDataPair.Values)
  464. {
  465. if (ikctrlData.IsIKTargetChara(chara))
  466. {
  467. return true;
  468. }
  469. }
  470. return false;
  471. }
  472. public bool IsTargetIKAttachSelf(bool check_ikend = true)
  473. {
  474. if (!this.IKActive || !this.IsIKExec)
  475. {
  476. return false;
  477. }
  478. using (Dictionary<string, IKCtrlData>.ValueCollection.Enumerator enumerator = this.strIKDataPair.Values.GetEnumerator())
  479. {
  480. while (enumerator.MoveNext())
  481. {
  482. IKCtrlData ik_data = enumerator.Current;
  483. Func<IKCtrlData.IKAttachType, bool> func = delegate(IKCtrlData.IKAttachType attach_type)
  484. {
  485. IKCtrlData.IKSettingData iksettingData = ik_data.GetIKSettingData(attach_type);
  486. foreach (IKCtrlData.IKExecTiming exec_timing in (IKCtrlData.IKExecTiming[])Enum.GetValues(typeof(IKCtrlData.IKExecTiming)))
  487. {
  488. IKCtrlData.IKTargetData targetData = ik_data.GetTargetData(attach_type, exec_timing);
  489. if (targetData.TgtChara)
  490. {
  491. bool flag;
  492. if (check_ikend)
  493. {
  494. flag = (targetData.TgtChara.IKCtrl.IsCharaIKAttach(this.TgtChara) && !targetData.TgtChara.IKCtrl.IsUpdateEnd && !targetData.TgtChara.IKCtrl.IsUpdateLate);
  495. }
  496. else
  497. {
  498. flag = targetData.TgtChara.IKCtrl.IsCharaIKAttach(this.TgtChara);
  499. }
  500. if (flag)
  501. {
  502. return true;
  503. }
  504. }
  505. }
  506. return false;
  507. };
  508. if (func(IKCtrlData.IKAttachType.NewPoint) || func(IKCtrlData.IKAttachType.Rotate))
  509. {
  510. return true;
  511. }
  512. }
  513. }
  514. return false;
  515. }
  516. public void SetPelvisPull(bool pull_on)
  517. {
  518. this.m_IsPelvisPull = pull_on;
  519. }
  520. public static Dictionary<FullBodyIKCtrl.IKBoneType, Transform> GetAllIKBoneDic(Maid chara)
  521. {
  522. if (chara == null)
  523. {
  524. return null;
  525. }
  526. NDebug.Assert(chara.body0 != null, "[body0] it does not end load.");
  527. string text = (!chara.boMAN) ? "Bip01" : "ManBip";
  528. Dictionary<FullBodyIKCtrl.IKBoneType, Transform> dictionary = new Dictionary<FullBodyIKCtrl.IKBoneType, Transform>();
  529. dictionary.Add(FullBodyIKCtrl.IKBoneType.TopFixed, chara.body0.GetBone(text).parent);
  530. dictionary.Add(FullBodyIKCtrl.IKBoneType.Root, chara.body0.GetBone(text));
  531. dictionary.Add(FullBodyIKCtrl.IKBoneType.Pelvis, chara.body0.GetBone(text + " Pelvis"));
  532. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine0, chara.body0.GetBone(text + " Spine"));
  533. if (!chara.boMAN)
  534. {
  535. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine1, chara.body0.GetBone(text + " Spine0a"));
  536. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine2, chara.body0.GetBone(text + " Spine1"));
  537. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine3, chara.body0.GetBone(text + " Spine1a"));
  538. }
  539. else
  540. {
  541. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine1, chara.body0.GetBone(text + " Spine1"));
  542. dictionary.Add(FullBodyIKCtrl.IKBoneType.Spine2, chara.body0.GetBone(text + " Spine2"));
  543. }
  544. dictionary.Add(FullBodyIKCtrl.IKBoneType.Head, chara.body0.GetBone(text + " Head"));
  545. dictionary.Add(FullBodyIKCtrl.IKBoneType.Neck, chara.body0.GetBone(text + " Neck"));
  546. dictionary.Add(FullBodyIKCtrl.IKBoneType.UpperArm_R, chara.body0.GetBone(text + " R UpperArm"));
  547. dictionary.Add(FullBodyIKCtrl.IKBoneType.Forearm_R, chara.body0.GetBone(text + " R Forearm"));
  548. dictionary.Add(FullBodyIKCtrl.IKBoneType.Hand_R, chara.body0.GetBone(text + " R Hand"));
  549. dictionary.Add(FullBodyIKCtrl.IKBoneType.UpperArm_L, chara.body0.GetBone(text + " L UpperArm"));
  550. dictionary.Add(FullBodyIKCtrl.IKBoneType.Forearm_L, chara.body0.GetBone(text + " L Forearm"));
  551. dictionary.Add(FullBodyIKCtrl.IKBoneType.Hand_L, chara.body0.GetBone(text + " L Hand"));
  552. dictionary.Add(FullBodyIKCtrl.IKBoneType.Thigh_R, chara.body0.GetBone(text + " R Thigh"));
  553. dictionary.Add(FullBodyIKCtrl.IKBoneType.Calf_R, chara.body0.GetBone(text + " R Calf"));
  554. dictionary.Add(FullBodyIKCtrl.IKBoneType.Foot_R, chara.body0.GetBone(text + " R Foot"));
  555. dictionary.Add(FullBodyIKCtrl.IKBoneType.Thigh_L, chara.body0.GetBone(text + " L Thigh"));
  556. dictionary.Add(FullBodyIKCtrl.IKBoneType.Calf_L, chara.body0.GetBone(text + " L Calf"));
  557. dictionary.Add(FullBodyIKCtrl.IKBoneType.Foot_L, chara.body0.GetBone(text + " L Foot"));
  558. return dictionary;
  559. }
  560. public const float PULL_MIN_VALUE = 0.1f;
  561. public static readonly Dictionary<FullBodyIKCtrl.IKBoneType, string> IKBoneTypeStrDic = new Dictionary<FullBodyIKCtrl.IKBoneType, string>
  562. {
  563. {
  564. FullBodyIKCtrl.IKBoneType.Root,
  565. "体全体"
  566. },
  567. {
  568. FullBodyIKCtrl.IKBoneType.Hand_R,
  569. "右手"
  570. },
  571. {
  572. FullBodyIKCtrl.IKBoneType.Forearm_R,
  573. "右肘"
  574. },
  575. {
  576. FullBodyIKCtrl.IKBoneType.UpperArm_R,
  577. "右肩"
  578. },
  579. {
  580. FullBodyIKCtrl.IKBoneType.Hand_L,
  581. "左手"
  582. },
  583. {
  584. FullBodyIKCtrl.IKBoneType.Forearm_L,
  585. "左肘"
  586. },
  587. {
  588. FullBodyIKCtrl.IKBoneType.UpperArm_L,
  589. "左肩"
  590. },
  591. {
  592. FullBodyIKCtrl.IKBoneType.Foot_R,
  593. "右足"
  594. },
  595. {
  596. FullBodyIKCtrl.IKBoneType.Calf_R,
  597. "右膝"
  598. },
  599. {
  600. FullBodyIKCtrl.IKBoneType.Thigh_R,
  601. "右腿"
  602. },
  603. {
  604. FullBodyIKCtrl.IKBoneType.Foot_L,
  605. "左足"
  606. },
  607. {
  608. FullBodyIKCtrl.IKBoneType.Calf_L,
  609. "左膝"
  610. },
  611. {
  612. FullBodyIKCtrl.IKBoneType.Thigh_L,
  613. "左腿"
  614. }
  615. };
  616. [SerializeField]
  617. private TBody m_TgtBody;
  618. [SerializeField]
  619. private Transform m_IKTgtRoot;
  620. [SerializeField]
  621. private Transform m_STRoot;
  622. [SerializeField]
  623. private FullBodyBipedIK m_FullbodyIK;
  624. private Dictionary<FullBodyIKCtrl.IKBoneType, Transform> m_IKBoneDic = new Dictionary<FullBodyIKCtrl.IKBoneType, Transform>();
  625. [SerializeField]
  626. private BodyCtrlData m_BodyCtrlData;
  627. private Transform m_NippleL;
  628. private Transform m_NippleR;
  629. private Transform m_Mouth;
  630. private Dictionary<string, IKCtrlData> m_StrIKDataPair = new Dictionary<string, IKCtrlData>();
  631. private Dictionary<string, Transform> m_NameFlagObjpair = new Dictionary<string, Transform>();
  632. public bool IKActive = true;
  633. [HideInInspector]
  634. public bool IsUpdateLate;
  635. public Action PostSolverUpdate;
  636. public bool AllForceIK;
  637. public float BlendTime = 0.5f;
  638. private bool m_IsPelvisPull;
  639. public enum IKBoneType
  640. {
  641. TopFixed,
  642. Root,
  643. Spine0,
  644. Spine1,
  645. Spine2,
  646. Spine3,
  647. Neck,
  648. Head,
  649. Clavicle_R,
  650. UpperArm_R,
  651. Forearm_R,
  652. Hand_R,
  653. Clavicle_L,
  654. UpperArm_L,
  655. Forearm_L,
  656. Hand_L,
  657. Pelvis,
  658. Thigh_R,
  659. Calf_R,
  660. Foot_R,
  661. Thigh_L,
  662. Calf_L,
  663. Foot_L
  664. }
  665. }