IKManager.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using RootMotion.FinalIK;
  5. using UnityEngine;
  6. using wf;
  7. public class IKManager : MonoBehaviour
  8. {
  9. public static Dictionary<IKManager.BoneType, KeyValuePair<IKManager.BoneSetType, GameObject>> CreateBoneDic(Maid maid)
  10. {
  11. if (maid == null)
  12. {
  13. return null;
  14. }
  15. NDebug.Assert(maid.body0 != null, "[body0] it does not end load.");
  16. return new Dictionary<IKManager.BoneType, KeyValuePair<IKManager.BoneSetType, GameObject>>
  17. {
  18. {
  19. IKManager.BoneType.TopFixed,
  20. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01").parent.gameObject)
  21. },
  22. {
  23. IKManager.BoneType.Root,
  24. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01").gameObject)
  25. },
  26. {
  27. IKManager.BoneType.Head,
  28. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 Head").gameObject)
  29. },
  30. {
  31. IKManager.BoneType.Neck,
  32. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 Neck").gameObject)
  33. },
  34. {
  35. IKManager.BoneType.Pelvis,
  36. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 Pelvis").gameObject)
  37. },
  38. {
  39. IKManager.BoneType.Spine0,
  40. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 Spine").gameObject)
  41. },
  42. {
  43. IKManager.BoneType.Spine1,
  44. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 Spine0a").gameObject)
  45. },
  46. {
  47. IKManager.BoneType.Spine2,
  48. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 Spine1").gameObject)
  49. },
  50. {
  51. IKManager.BoneType.Spine3,
  52. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 Spine1a").gameObject)
  53. },
  54. {
  55. IKManager.BoneType.Bust_R,
  56. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Mune_R").gameObject)
  57. },
  58. {
  59. IKManager.BoneType.Clavicle_R,
  60. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 R Clavicle").gameObject)
  61. },
  62. {
  63. IKManager.BoneType.UpperArm_R,
  64. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 R UpperArm").gameObject)
  65. },
  66. {
  67. IKManager.BoneType.Forearm_R,
  68. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 R Forearm").gameObject)
  69. },
  70. {
  71. IKManager.BoneType.Hand_R,
  72. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 R Hand").gameObject)
  73. },
  74. {
  75. IKManager.BoneType.Bust_L,
  76. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Mune_L").gameObject)
  77. },
  78. {
  79. IKManager.BoneType.Clavicle_L,
  80. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 L Clavicle").gameObject)
  81. },
  82. {
  83. IKManager.BoneType.UpperArm_L,
  84. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 L UpperArm").gameObject)
  85. },
  86. {
  87. IKManager.BoneType.Forearm_L,
  88. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 L Forearm").gameObject)
  89. },
  90. {
  91. IKManager.BoneType.Hand_L,
  92. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 L Hand").gameObject)
  93. },
  94. {
  95. IKManager.BoneType.Hip_R,
  96. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Hip_R").gameObject)
  97. },
  98. {
  99. IKManager.BoneType.Thigh_R,
  100. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 R Thigh").gameObject)
  101. },
  102. {
  103. IKManager.BoneType.Calf_R,
  104. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 R Calf").gameObject)
  105. },
  106. {
  107. IKManager.BoneType.Foot_R,
  108. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 R Foot").gameObject)
  109. },
  110. {
  111. IKManager.BoneType.Hip_L,
  112. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Hip_L").gameObject)
  113. },
  114. {
  115. IKManager.BoneType.Thigh_L,
  116. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 L Thigh").gameObject)
  117. },
  118. {
  119. IKManager.BoneType.Calf_L,
  120. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 L Calf").gameObject)
  121. },
  122. {
  123. IKManager.BoneType.Foot_L,
  124. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.Body, maid.body0.GetBone("Bip01 L Foot").gameObject)
  125. },
  126. {
  127. IKManager.BoneType.Finger0_Root_R,
  128. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger0").gameObject)
  129. },
  130. {
  131. IKManager.BoneType.Finger0_0_R,
  132. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger01").gameObject)
  133. },
  134. {
  135. IKManager.BoneType.Finger0_1_R,
  136. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger02").gameObject)
  137. },
  138. {
  139. IKManager.BoneType.Finger1_Root_R,
  140. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger1").gameObject)
  141. },
  142. {
  143. IKManager.BoneType.Finger1_0_R,
  144. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger11").gameObject)
  145. },
  146. {
  147. IKManager.BoneType.Finger1_1_R,
  148. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger12").gameObject)
  149. },
  150. {
  151. IKManager.BoneType.Finger2_Root_R,
  152. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger2").gameObject)
  153. },
  154. {
  155. IKManager.BoneType.Finger2_0_R,
  156. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger21").gameObject)
  157. },
  158. {
  159. IKManager.BoneType.Finger2_1_R,
  160. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger22").gameObject)
  161. },
  162. {
  163. IKManager.BoneType.Finger3_Root_R,
  164. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger3").gameObject)
  165. },
  166. {
  167. IKManager.BoneType.Finger3_0_R,
  168. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger31").gameObject)
  169. },
  170. {
  171. IKManager.BoneType.Finger3_1_R,
  172. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger32").gameObject)
  173. },
  174. {
  175. IKManager.BoneType.Finger4_Root_R,
  176. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger4").gameObject)
  177. },
  178. {
  179. IKManager.BoneType.Finger4_0_R,
  180. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger41").gameObject)
  181. },
  182. {
  183. IKManager.BoneType.Finger4_1_R,
  184. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightArmFinger, maid.body0.GetBone("Bip01 R Finger42").gameObject)
  185. },
  186. {
  187. IKManager.BoneType.Finger0_Root_L,
  188. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger0").gameObject)
  189. },
  190. {
  191. IKManager.BoneType.Finger0_0_L,
  192. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger01").gameObject)
  193. },
  194. {
  195. IKManager.BoneType.Finger0_1_L,
  196. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger02").gameObject)
  197. },
  198. {
  199. IKManager.BoneType.Finger1_Root_L,
  200. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger1").gameObject)
  201. },
  202. {
  203. IKManager.BoneType.Finger1_0_L,
  204. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger11").gameObject)
  205. },
  206. {
  207. IKManager.BoneType.Finger1_1_L,
  208. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger12").gameObject)
  209. },
  210. {
  211. IKManager.BoneType.Finger2_Root_L,
  212. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger2").gameObject)
  213. },
  214. {
  215. IKManager.BoneType.Finger2_0_L,
  216. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger21").gameObject)
  217. },
  218. {
  219. IKManager.BoneType.Finger2_1_L,
  220. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger22").gameObject)
  221. },
  222. {
  223. IKManager.BoneType.Finger3_Root_L,
  224. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger3").gameObject)
  225. },
  226. {
  227. IKManager.BoneType.Finger3_0_L,
  228. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger31").gameObject)
  229. },
  230. {
  231. IKManager.BoneType.Finger3_1_L,
  232. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger32").gameObject)
  233. },
  234. {
  235. IKManager.BoneType.Finger4_Root_L,
  236. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger4").gameObject)
  237. },
  238. {
  239. IKManager.BoneType.Finger4_0_L,
  240. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger41").gameObject)
  241. },
  242. {
  243. IKManager.BoneType.Finger4_1_L,
  244. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftArmFinger, maid.body0.GetBone("Bip01 L Finger42").gameObject)
  245. },
  246. {
  247. IKManager.BoneType.Toe0_Root_R,
  248. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightLegFinger, maid.body0.GetBone("Bip01 R Toe2").gameObject)
  249. },
  250. {
  251. IKManager.BoneType.Toe0_0_R,
  252. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightLegFinger, maid.body0.GetBone("Bip01 R Toe21").gameObject)
  253. },
  254. {
  255. IKManager.BoneType.Toe1_Root_R,
  256. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightLegFinger, maid.body0.GetBone("Bip01 R Toe1").gameObject)
  257. },
  258. {
  259. IKManager.BoneType.Toe1_0_R,
  260. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightLegFinger, maid.body0.GetBone("Bip01 R Toe11").gameObject)
  261. },
  262. {
  263. IKManager.BoneType.Toe2_Root_R,
  264. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightLegFinger, maid.body0.GetBone("Bip01 R Toe0").gameObject)
  265. },
  266. {
  267. IKManager.BoneType.Toe2_0_R,
  268. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightLegFinger, maid.body0.GetBone("Bip01 R Toe01").gameObject)
  269. },
  270. {
  271. IKManager.BoneType.Toe0_Root_L,
  272. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.RightLegFinger, maid.body0.GetBone("Bip01 L Toe2").gameObject)
  273. },
  274. {
  275. IKManager.BoneType.Toe0_0_L,
  276. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftLegFinger, maid.body0.GetBone("Bip01 L Toe21").gameObject)
  277. },
  278. {
  279. IKManager.BoneType.Toe1_Root_L,
  280. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftLegFinger, maid.body0.GetBone("Bip01 L Toe1").gameObject)
  281. },
  282. {
  283. IKManager.BoneType.Toe1_0_L,
  284. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftLegFinger, maid.body0.GetBone("Bip01 L Toe11").gameObject)
  285. },
  286. {
  287. IKManager.BoneType.Toe2_Root_L,
  288. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftLegFinger, maid.body0.GetBone("Bip01 L Toe0").gameObject)
  289. },
  290. {
  291. IKManager.BoneType.Toe2_0_L,
  292. new KeyValuePair<IKManager.BoneSetType, GameObject>(IKManager.BoneSetType.LeftLegFinger, maid.body0.GetBone("Bip01 L Toe01").gameObject)
  293. }
  294. };
  295. }
  296. public void Awake()
  297. {
  298. }
  299. public void SetMaid(Maid target_maid)
  300. {
  301. if (this.bone_dic_.Count != 0)
  302. {
  303. return;
  304. }
  305. StopWatch stopWatch = new StopWatch();
  306. this.maid = target_maid;
  307. if (this.maid == null)
  308. {
  309. return;
  310. }
  311. NDebug.Assert(this.maid.body0 != null, "[body0] it does not end load.");
  312. this.cache_bone_data_ = this.maid.gameObject.GetComponent<CacheBoneDataArray>();
  313. if (this.cache_bone_data_ == null)
  314. {
  315. this.cache_bone_data_ = this.maid.gameObject.AddComponent<CacheBoneDataArray>();
  316. this.cache_bone_data_.CreateCache(this.maid.body0.GetBone("Bip01"));
  317. }
  318. this.bone_dic_ = IKManager.CreateBoneDic(this.maid);
  319. List<KeyValuePair<int, IKManager.BoneType>> list = new List<KeyValuePair<int, IKManager.BoneType>>();
  320. Transform transform = this.bone_dic_[IKManager.BoneType.TopFixed].Value.transform;
  321. foreach (KeyValuePair<IKManager.BoneType, KeyValuePair<IKManager.BoneSetType, GameObject>> keyValuePair in this.bone_dic_)
  322. {
  323. Transform transform2 = keyValuePair.Value.Value.transform;
  324. int num = 0;
  325. while (!(transform2 == transform))
  326. {
  327. transform2 = transform2.parent;
  328. num++;
  329. }
  330. list.Add(new KeyValuePair<int, IKManager.BoneType>(num, keyValuePair.Key));
  331. }
  332. list.Sort((KeyValuePair<int, IKManager.BoneType> a, KeyValuePair<int, IKManager.BoneType> b) => a.Key - b.Key);
  333. this.sort_bone_list_ = new List<KeyValuePair<IKManager.BoneType, GameObject>>();
  334. foreach (KeyValuePair<int, IKManager.BoneType> keyValuePair2 in list)
  335. {
  336. this.sort_bone_list_.Add(new KeyValuePair<IKManager.BoneType, GameObject>(keyValuePair2.Value, this.bone_dic_[keyValuePair2.Value].Value));
  337. }
  338. this.limb_control_list_ = new List<LimbControl>();
  339. IEnumerator enumerator3 = Enum.GetValues(typeof(LimbControl.Type)).GetEnumerator();
  340. try
  341. {
  342. while (enumerator3.MoveNext())
  343. {
  344. object obj = enumerator3.Current;
  345. LimbControl.Type type = (LimbControl.Type)obj;
  346. LimbControl limbControl = base.gameObject.AddComponent<LimbControl>();
  347. limbControl.Initialize(this, type);
  348. this.limb_control_list_.Add(limbControl);
  349. }
  350. }
  351. finally
  352. {
  353. IDisposable disposable;
  354. if ((disposable = (enumerator3 as IDisposable)) != null)
  355. {
  356. disposable.Dispose();
  357. }
  358. }
  359. this.root_drag_point_ = IKManager.CreateIKDragPoint(this.GetBone(IKManager.BoneType.Root), this.maid);
  360. this.root_drag_point_.PositonCorrectionEnabled = false;
  361. this.root_drag_point_.cur_drag_event = delegate
  362. {
  363. this.root_drag_point_.target_ik_point_trans.position = this.root_drag_point_.transform.position;
  364. };
  365. this.root_drag_point_.drag_end_event = delegate
  366. {
  367. this.HistoryPush();
  368. };
  369. this.AddLimitComponen();
  370. this.gizmo_render_list_ = new List<GizmoRenderTarget>();
  371. this.gizmo_render_dic_ = new Dictionary<IKManager.BoneType, GizmoRenderTarget>();
  372. foreach (KeyValuePair<IKManager.BoneType, KeyValuePair<IKManager.BoneSetType, GameObject>> keyValuePair3 in this.bone_dic_)
  373. {
  374. GameObject gameObject = new GameObject();
  375. gameObject.transform.SetParent(base.transform, false);
  376. gameObject.name = keyValuePair3.Value.ToString();
  377. GizmoRenderTarget gizmoRenderTarget = gameObject.AddComponent<GizmoRenderTarget>();
  378. gizmoRenderTarget.ik_mgr = this;
  379. this.gizmo_render_list_.Add(gizmoRenderTarget);
  380. this.gizmo_render_dic_.Add(keyValuePair3.Key, gizmoRenderTarget);
  381. gizmoRenderTarget.target_trans = keyValuePair3.Value.Value.transform;
  382. gizmoRenderTarget.offsetScale = 0.2f;
  383. gizmoRenderTarget.lineRSelectedThick = 0.2f;
  384. RotationLimitHinge component = keyValuePair3.Value.Value.GetComponent<RotationLimitHinge>();
  385. if (component != null)
  386. {
  387. Vector3 axis = component.axis;
  388. if (axis.x != 0f && axis.y == 0f && axis.z == 0f)
  389. {
  390. gizmoRenderTarget.VisibleRotateY = (gizmoRenderTarget.VisibleRotateZ = false);
  391. }
  392. else if (axis.x == 0f && axis.y != 0f && axis.z == 0f)
  393. {
  394. gizmoRenderTarget.VisibleRotateX = (gizmoRenderTarget.VisibleRotateZ = false);
  395. }
  396. else if (axis.x == 0f && axis.y == 0f && axis.z != 0f)
  397. {
  398. gizmoRenderTarget.VisibleRotateX = (gizmoRenderTarget.VisibleRotateY = false);
  399. }
  400. }
  401. }
  402. this.finger_blend_ = base.gameObject.AddComponent<FingerBlend>();
  403. this.finger_blend_.SetIKManager(this);
  404. FingerBlend.BaseFinger right_arm_finger = this.finger_blend_.right_arm_finger;
  405. bool enabled = false;
  406. this.finger_blend_.left_arm_finger.enabled = enabled;
  407. right_arm_finger.enabled = enabled;
  408. FingerBlend.BaseFinger right_leg_finger = this.finger_blend_.right_leg_finger;
  409. enabled = false;
  410. this.finger_blend_.left_leg_finger.enabled = enabled;
  411. right_leg_finger.enabled = enabled;
  412. }
  413. public void Flip()
  414. {
  415. if (IKManager.notFlipTypes == null || IKManager.notFlipTypes.Count <= 0)
  416. {
  417. IKManager.notFlipTypes.Add(IKManager.BoneType.TopFixed);
  418. IKManager.notFlipTypes.Add(IKManager.BoneType.Head);
  419. IKManager.notFlipTypes.Add(IKManager.BoneType.Bust_R);
  420. IKManager.notFlipTypes.Add(IKManager.BoneType.Bust_L);
  421. for (int i = 27; i <= 68; i++)
  422. {
  423. IKManager.notFlipTypes.Add((IKManager.BoneType)i);
  424. }
  425. }
  426. if (IKManager.swapFlipDic == null || IKManager.swapFlipDic.Count <= 0)
  427. {
  428. IKManager.swapFlipDic.Add(IKManager.BoneType.Clavicle_R, IKManager.BoneType.Clavicle_L);
  429. IKManager.swapFlipDic.Add(IKManager.BoneType.UpperArm_R, IKManager.BoneType.UpperArm_L);
  430. IKManager.swapFlipDic.Add(IKManager.BoneType.Forearm_R, IKManager.BoneType.Forearm_L);
  431. IKManager.swapFlipDic.Add(IKManager.BoneType.Thigh_R, IKManager.BoneType.Thigh_L);
  432. IKManager.swapFlipDic.Add(IKManager.BoneType.Calf_R, IKManager.BoneType.Calf_L);
  433. IKManager.swapFlipDic.Add(IKManager.BoneType.Hand_R, IKManager.BoneType.Hand_L);
  434. IKManager.swapFlipDic.Add(IKManager.BoneType.Foot_R, IKManager.BoneType.Foot_L);
  435. List<KeyValuePair<IKManager.BoneType, IKManager.BoneType>> list = new List<KeyValuePair<IKManager.BoneType, IKManager.BoneType>>();
  436. foreach (KeyValuePair<IKManager.BoneType, IKManager.BoneType> keyValuePair in IKManager.swapFlipDic)
  437. {
  438. list.Add(new KeyValuePair<IKManager.BoneType, IKManager.BoneType>(keyValuePair.Value, keyValuePair.Key));
  439. }
  440. foreach (KeyValuePair<IKManager.BoneType, IKManager.BoneType> keyValuePair2 in list)
  441. {
  442. IKManager.swapFlipDic.Add(keyValuePair2.Key, keyValuePair2.Value);
  443. }
  444. }
  445. Dictionary<IKManager.BoneType, Vector3> dictionary = new Dictionary<IKManager.BoneType, Vector3>();
  446. for (int j = 0; j <= 68; j++)
  447. {
  448. IKManager.BoneType boneType = (IKManager.BoneType)j;
  449. if (!IKManager.notFlipTypes.Contains(boneType))
  450. {
  451. Transform transform = this.bone_dic_[boneType].Value.transform;
  452. dictionary.Add(boneType, transform.rotation.eulerAngles);
  453. }
  454. }
  455. Quaternion rotation = Quaternion.identity;
  456. Vector3 vector = Vector3.zero;
  457. for (int k = 0; k < this.sort_bone_list_.Count; k++)
  458. {
  459. IKManager.BoneType key = this.sort_bone_list_[k].Key;
  460. if (!IKManager.notFlipTypes.Contains(key))
  461. {
  462. vector = dictionary[key];
  463. if (key == IKManager.BoneType.Root)
  464. {
  465. rotation = Quaternion.Euler(360f - (vector.x + 270f) - 270f, 360f - (vector.y + 90f) - 90f, 360f - vector.z);
  466. }
  467. else
  468. {
  469. if (IKManager.swapFlipDic.ContainsKey(key))
  470. {
  471. vector = dictionary[IKManager.swapFlipDic[key]];
  472. }
  473. rotation = Quaternion.Euler(360f - vector.x, 360f - (vector.y + 90f) - 90f, vector.z);
  474. }
  475. this.bone_dic_[key].Value.transform.rotation = rotation;
  476. }
  477. }
  478. byte[] binary = this.finger_blend_.right_arm_finger.GetBinary();
  479. byte[] binary2 = this.finger_blend_.left_arm_finger.GetBinary();
  480. this.finger_blend_.right_arm_finger.SetBinary(binary2, true);
  481. this.finger_blend_.left_arm_finger.SetBinary(binary, true);
  482. binary = this.finger_blend_.right_leg_finger.GetBinary();
  483. binary2 = this.finger_blend_.left_leg_finger.GetBinary();
  484. this.finger_blend_.right_leg_finger.SetBinary(binary2, true);
  485. this.finger_blend_.left_leg_finger.SetBinary(binary, true);
  486. }
  487. public void SetRotateVisibleBone(IKManager.BoneType bone_type, bool visible)
  488. {
  489. this.gizmo_render_dic_[bone_type].Visible = visible;
  490. }
  491. public void SetRotateVisibleBoneSet(IKManager.BoneSetType bone_set_type, bool visible)
  492. {
  493. HashSet<Transform> hashSet = new HashSet<Transform>();
  494. foreach (KeyValuePair<IKManager.BoneType, KeyValuePair<IKManager.BoneSetType, GameObject>> keyValuePair in this.bone_dic_)
  495. {
  496. KeyValuePair<IKManager.BoneSetType, GameObject> value = keyValuePair.Value;
  497. if (value.Key == bone_set_type)
  498. {
  499. hashSet.Add(value.Value.transform);
  500. }
  501. }
  502. for (int i = 0; i < this.gizmo_render_list_.Count; i++)
  503. {
  504. if (hashSet.Contains(this.gizmo_render_list_[i].target_trans))
  505. {
  506. this.gizmo_render_list_[i].Visible = visible;
  507. }
  508. }
  509. }
  510. public void SetTransAxisVisibleBoneSet(IKManager.BoneSetType bone_set_type, bool visible)
  511. {
  512. HashSet<LimbControl.Type> hashSet = new HashSet<LimbControl.Type>();
  513. switch (bone_set_type)
  514. {
  515. case IKManager.BoneSetType.Body:
  516. hashSet.Add(LimbControl.Type.Arm_L);
  517. hashSet.Add(LimbControl.Type.Arm_R);
  518. hashSet.Add(LimbControl.Type.Foot_L);
  519. hashSet.Add(LimbControl.Type.Foot_R);
  520. break;
  521. case IKManager.BoneSetType.RightArmFinger:
  522. for (int i = 2; i <= 6; i++)
  523. {
  524. hashSet.Add((LimbControl.Type)i);
  525. }
  526. break;
  527. case IKManager.BoneSetType.LeftArmFinger:
  528. for (int j = 12; j <= 16; j++)
  529. {
  530. hashSet.Add((LimbControl.Type)j);
  531. }
  532. break;
  533. case IKManager.BoneSetType.RightLegFinger:
  534. for (int k = 7; k <= 9; k++)
  535. {
  536. hashSet.Add((LimbControl.Type)k);
  537. }
  538. break;
  539. case IKManager.BoneSetType.LeftLegFinger:
  540. for (int l = 17; l <= 19; l++)
  541. {
  542. hashSet.Add((LimbControl.Type)l);
  543. }
  544. break;
  545. }
  546. foreach (LimbControl limbControl in this.limb_control_list_)
  547. {
  548. if (hashSet.Contains(limbControl.type))
  549. {
  550. limbControl.visible = visible;
  551. }
  552. }
  553. }
  554. public void SetTransAxisVisibleRoot(bool visible)
  555. {
  556. this.root_drag_point_.visible = visible;
  557. }
  558. public void OnDestroy()
  559. {
  560. if (this.root_drag_point_ != null)
  561. {
  562. UnityEngine.Object.Destroy(this.root_drag_point_.gameObject);
  563. }
  564. foreach (LimbControl obj in this.limb_control_list_)
  565. {
  566. UnityEngine.Object.Destroy(obj);
  567. }
  568. foreach (GizmoRenderTarget gizmoRenderTarget in this.gizmo_render_list_)
  569. {
  570. UnityEngine.Object.Destroy(gizmoRenderTarget.gameObject);
  571. }
  572. this.gizmo_render_dic_.Clear();
  573. if (this.maid != null)
  574. {
  575. UnityEngine.Object.Destroy(this.cache_bone_data_);
  576. GameObject gameObject = GameObject.Find("IKDragPointParent/" + this.maid.status.guid);
  577. if (gameObject != null)
  578. {
  579. UnityEngine.Object.Destroy(gameObject.gameObject);
  580. }
  581. }
  582. if (this.finger_blend_ != null)
  583. {
  584. UnityEngine.Object.Destroy(this.finger_blend_);
  585. }
  586. }
  587. public void HistoryNew()
  588. {
  589. if (this.undo_backup_list_.Count == 0)
  590. {
  591. this.HistoryClear();
  592. this.HistoryPush();
  593. }
  594. }
  595. public void HistoryClear()
  596. {
  597. this.undo_backup_list_.Clear();
  598. this.history_point = 0;
  599. }
  600. public void HistoryPush()
  601. {
  602. if (this.maid == null)
  603. {
  604. return;
  605. }
  606. byte[] frameBinary = this.cache_bone_data.GetFrameBinary(true, true);
  607. if (this.undo_backup_list_.Count == 0 || frameBinary != this.undo_backup_list_[this.undo_backup_list_.Count - 1])
  608. {
  609. if (this.history_point < this.undo_backup_list_.Count)
  610. {
  611. this.undo_backup_list_.RemoveRange(this.history_point, this.undo_backup_list_.Count - this.history_point);
  612. }
  613. this.undo_backup_list_.Add(frameBinary);
  614. this.history_point++;
  615. if (200 <= this.undo_backup_list_.Count)
  616. {
  617. this.undo_backup_list_.RemoveAt(0);
  618. this.history_point--;
  619. }
  620. }
  621. }
  622. public bool HistoryUndo()
  623. {
  624. if (this.history_point <= 1)
  625. {
  626. return false;
  627. }
  628. this.history_point--;
  629. this.cache_bone_data.SetFrameBinary(this.undo_backup_list_[this.history_point - 1]);
  630. return true;
  631. }
  632. public bool HistoryRedo()
  633. {
  634. if (this.undo_backup_list_.Count <= this.history_point)
  635. {
  636. return false;
  637. }
  638. this.history_point++;
  639. this.cache_bone_data.SetFrameBinary(this.undo_backup_list_[this.history_point - 1]);
  640. return true;
  641. }
  642. public GameObject GetBone(IKManager.BoneType bone_type)
  643. {
  644. return (!this.bone_dic_.ContainsKey(bone_type)) ? null : this.bone_dic_[bone_type].Value;
  645. }
  646. public CacheBoneDataArray cache_bone_data
  647. {
  648. get
  649. {
  650. return this.cache_bone_data_;
  651. }
  652. }
  653. public Maid maid { get; private set; }
  654. public FingerBlend finger_blend
  655. {
  656. get
  657. {
  658. return this.finger_blend_;
  659. }
  660. }
  661. private void AddLimitComponen()
  662. {
  663. Action<IKManager.BoneType, Vector3, float, float> action = delegate(IKManager.BoneType target_bone, Vector3 axis, float limit, float twist_limit)
  664. {
  665. Transform transform = this.GetBone(target_bone).gameObject.transform;
  666. Quaternion localRotation = transform.localRotation;
  667. transform.localRotation = Quaternion.identity;
  668. RotationLimitAngle rotationLimitAngle = transform.gameObject.AddComponent<RotationLimitAngle>();
  669. rotationLimitAngle.axis = axis;
  670. rotationLimitAngle.limit = limit;
  671. rotationLimitAngle.twistLimit = twist_limit;
  672. transform.localRotation = localRotation;
  673. rotationLimitAngle.enabled = false;
  674. };
  675. Action<IKManager.BoneType, Vector3, Vector2> action2 = delegate(IKManager.BoneType target_bone, Vector3 axis, Vector2 min_max)
  676. {
  677. Transform transform = this.GetBone(target_bone).gameObject.transform;
  678. Quaternion localRotation = transform.localRotation;
  679. transform.localRotation = Quaternion.identity;
  680. RotationLimitHinge rotationLimitHinge = transform.gameObject.AddComponent<RotationLimitHinge>();
  681. rotationLimitHinge.axis = axis;
  682. rotationLimitHinge.min = min_max.x;
  683. rotationLimitHinge.max = min_max.y;
  684. transform.localRotation = localRotation;
  685. rotationLimitHinge.enabled = false;
  686. };
  687. action(IKManager.BoneType.Neck, new Vector3(-1f, 0f, 0f), 85f, 80f);
  688. action2(IKManager.BoneType.Forearm_L, new Vector3(0f, 0f, 1f), new Vector2(0f, 170f));
  689. action2(IKManager.BoneType.Forearm_R, new Vector3(0f, 0f, 1f), new Vector2(0f, 170f));
  690. action2(IKManager.BoneType.Calf_L, new Vector3(0f, 0f, 1f), new Vector2(0f, 170f));
  691. action2(IKManager.BoneType.Calf_R, new Vector3(0f, 0f, 1f), new Vector2(0f, 170f));
  692. action2(IKManager.BoneType.Finger0_0_L, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  693. action2(IKManager.BoneType.Finger1_0_L, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  694. action2(IKManager.BoneType.Finger2_0_L, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  695. action2(IKManager.BoneType.Finger3_0_L, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  696. action2(IKManager.BoneType.Finger4_0_L, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  697. action2(IKManager.BoneType.Finger0_0_R, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  698. action2(IKManager.BoneType.Finger1_0_R, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  699. action2(IKManager.BoneType.Finger2_0_R, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  700. action2(IKManager.BoneType.Finger3_0_R, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  701. action2(IKManager.BoneType.Finger4_0_R, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  702. action2(IKManager.BoneType.Finger0_1_L, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  703. action2(IKManager.BoneType.Finger1_1_L, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  704. action2(IKManager.BoneType.Finger2_1_L, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  705. action2(IKManager.BoneType.Finger3_1_L, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  706. action2(IKManager.BoneType.Finger4_1_L, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  707. action2(IKManager.BoneType.Finger0_1_R, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  708. action2(IKManager.BoneType.Finger1_1_R, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  709. action2(IKManager.BoneType.Finger2_1_R, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  710. action2(IKManager.BoneType.Finger3_1_R, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  711. action2(IKManager.BoneType.Finger4_1_R, new Vector3(0f, 0f, -1f), new Vector2(0f, 170f));
  712. action2(IKManager.BoneType.Toe0_0_L, new Vector3(0f, 0f, 1f), new Vector2(0f, 170f));
  713. action2(IKManager.BoneType.Toe0_0_R, new Vector3(0f, 0f, 1f), new Vector2(0f, 170f));
  714. action2(IKManager.BoneType.Toe1_0_L, new Vector3(0f, 0f, 1f), new Vector2(0f, 170f));
  715. action2(IKManager.BoneType.Toe1_0_R, new Vector3(0f, 0f, 1f), new Vector2(0f, 170f));
  716. action2(IKManager.BoneType.Toe2_0_L, new Vector3(0f, 0f, 1f), new Vector2(0f, 170f));
  717. action2(IKManager.BoneType.Toe2_0_R, new Vector3(0f, 0f, 1f), new Vector2(0f, 170f));
  718. }
  719. public static IKDragPoint CreateIKDragPoint(GameObject obj, Maid maid)
  720. {
  721. GameObject gameObject = GameObject.Find("IKDragPointParent");
  722. if (gameObject == null)
  723. {
  724. gameObject = new GameObject("IKDragPointParent");
  725. }
  726. List<GameObject> list = new List<GameObject>();
  727. for (int i = 0; i < gameObject.transform.childCount; i++)
  728. {
  729. if (gameObject.transform.GetChild(i).childCount == 0 && gameObject.transform.GetChild(i).name != maid.status.guid)
  730. {
  731. list.Add(gameObject.transform.GetChild(i).gameObject);
  732. }
  733. }
  734. foreach (GameObject obj2 in list)
  735. {
  736. UnityEngine.Object.DestroyImmediate(obj2);
  737. }
  738. GameObject gameObject2 = GameObject.Find("IKDragPointParent/" + maid.status.guid);
  739. if (gameObject2 == null)
  740. {
  741. GameObject gameObject3 = new GameObject(maid.status.guid);
  742. gameObject3.transform.SetParent(gameObject.transform, false);
  743. gameObject = gameObject3;
  744. }
  745. else
  746. {
  747. gameObject = gameObject2;
  748. }
  749. GameObject gameObject4 = GameObject.Find("IKDragPointParent/" + maid.status.guid + "/IKDragPoint_" + obj.name);
  750. if (gameObject4 != null)
  751. {
  752. return gameObject4.GetComponent<IKDragPoint>();
  753. }
  754. GameObject gameObject5 = new GameObject("IKDragPoint_" + obj.name);
  755. gameObject5.transform.parent = gameObject.transform;
  756. IKDragPoint ikdragPoint = gameObject5.AddComponent<IKDragPoint>();
  757. ikdragPoint.SetTargetIKPoint(obj);
  758. WorldTransformAxis worldTransformAxis = PhotoWindowManager.CreateWorldTransformAxis(gameObject5, true, true);
  759. ikdragPoint.SetWorldTransformAxis(worldTransformAxis);
  760. return ikdragPoint;
  761. }
  762. private static HashSet<IKManager.BoneType> notFlipTypes = new HashSet<IKManager.BoneType>();
  763. private static Dictionary<IKManager.BoneType, IKManager.BoneType> swapFlipDic = new Dictionary<IKManager.BoneType, IKManager.BoneType>();
  764. private Dictionary<IKManager.BoneType, KeyValuePair<IKManager.BoneSetType, GameObject>> bone_dic_ = new Dictionary<IKManager.BoneType, KeyValuePair<IKManager.BoneSetType, GameObject>>();
  765. private List<KeyValuePair<IKManager.BoneType, GameObject>> sort_bone_list_ = new List<KeyValuePair<IKManager.BoneType, GameObject>>();
  766. private CacheBoneDataArray cache_bone_data_;
  767. private List<LimbControl> limb_control_list_;
  768. private List<GizmoRenderTarget> gizmo_render_list_;
  769. private Dictionary<IKManager.BoneType, GizmoRenderTarget> gizmo_render_dic_;
  770. private FingerBlend finger_blend_;
  771. private IKDragPoint root_drag_point_;
  772. private List<byte[]> undo_backup_list_ = new List<byte[]>();
  773. private int history_point;
  774. public enum BoneType
  775. {
  776. TopFixed,
  777. Root,
  778. Head,
  779. Neck,
  780. Pelvis,
  781. Spine0,
  782. Spine1,
  783. Spine2,
  784. Spine3,
  785. Bust_R,
  786. Clavicle_R,
  787. UpperArm_R,
  788. Forearm_R,
  789. Hand_R,
  790. Hip_R,
  791. Thigh_R,
  792. Calf_R,
  793. Foot_R,
  794. Bust_L,
  795. Clavicle_L,
  796. UpperArm_L,
  797. Forearm_L,
  798. Hand_L,
  799. Hip_L,
  800. Thigh_L,
  801. Calf_L,
  802. Foot_L,
  803. Finger0_Root_R,
  804. Finger0_0_R,
  805. Finger0_1_R,
  806. Finger1_Root_R,
  807. Finger1_0_R,
  808. Finger1_1_R,
  809. Finger2_Root_R,
  810. Finger2_0_R,
  811. Finger2_1_R,
  812. Finger3_Root_R,
  813. Finger3_0_R,
  814. Finger3_1_R,
  815. Finger4_Root_R,
  816. Finger4_0_R,
  817. Finger4_1_R,
  818. Finger0_Root_L,
  819. Finger0_0_L,
  820. Finger0_1_L,
  821. Finger1_Root_L,
  822. Finger1_0_L,
  823. Finger1_1_L,
  824. Finger2_Root_L,
  825. Finger2_0_L,
  826. Finger2_1_L,
  827. Finger3_Root_L,
  828. Finger3_0_L,
  829. Finger3_1_L,
  830. Finger4_Root_L,
  831. Finger4_0_L,
  832. Finger4_1_L,
  833. Toe0_Root_R,
  834. Toe0_0_R,
  835. Toe1_Root_R,
  836. Toe1_0_R,
  837. Toe2_Root_R,
  838. Toe2_0_R,
  839. Toe0_Root_L,
  840. Toe0_0_L,
  841. Toe1_Root_L,
  842. Toe1_0_L,
  843. Toe2_Root_L,
  844. Toe2_0_L
  845. }
  846. public enum BoneSetType
  847. {
  848. Body,
  849. RightArmFinger,
  850. LeftArmFinger,
  851. RightLegFinger,
  852. LeftLegFinger
  853. }
  854. }