AIKCtrl.cs 34 KB

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