OvrIK.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using RootMotion.FinalIK;
  7. using UnityEngine;
  8. using wf;
  9. public class OvrIK : MonoBehaviour
  10. {
  11. public OvrIK()
  12. {
  13. Quaternion[,] array = new Quaternion[4, 15];
  14. array[0, 0] = new Quaternion(1.379457E-08f, -1.907173E-10f, -0.1001217f, 0.9949752f);
  15. array[0, 1] = new Quaternion(-3.348364E-08f, -2.288052E-09f, -0.05697599f, 0.9983756f);
  16. array[0, 2] = new Quaternion(0.4853954f, -0.1902075f, 0.1155978f, 0.8454878f);
  17. array[0, 3] = new Quaternion(-2.555888E-09f, 1.190041E-09f, -0.08838178f, 0.9960867f);
  18. array[0, 4] = new Quaternion(-3.708266E-09f, -4.232382E-11f, -0.1423017f, 0.9898233f);
  19. array[0, 5] = new Quaternion(0.005196964f, -0.009313619f, -0.07643344f, 0.9970177f);
  20. array[0, 6] = new Quaternion(1.469708E-09f, -2.337872E-09f, -0.08838177f, 0.9960867f);
  21. array[0, 7] = new Quaternion(-4.677417E-09f, -1.311283E-08f, -0.1086997f, 0.9940746f);
  22. array[0, 8] = new Quaternion(-0.001879324f, -0.005337666f, -0.0991221f, 0.9950592f);
  23. array[0, 9] = new Quaternion(-8.490085E-09f, -1.805363E-09f, -0.0796621f, 0.9968219f);
  24. array[0, 10] = new Quaternion(2.300491E-09f, 3.334659E-09f, -0.1239805f, 0.9922847f);
  25. array[0, 11] = new Quaternion(-0.006921342f, 0.001893361f, -0.09829046f, 0.9951319f);
  26. array[0, 12] = new Quaternion(-5.701029E-09f, -1.521331E-09f, -0.05449884f, 0.9985139f);
  27. array[0, 13] = new Quaternion(3.803335E-09f, -5.725684E-09f, -0.1423017f, 0.9898233f);
  28. array[0, 14] = new Quaternion(-0.01357147f, 0.02850812f, -0.08513741f, 0.9958689f);
  29. array[1, 0] = new Quaternion(6.932151E-09f, -2.730647E-09f, -0.3665012f, 0.9304176f);
  30. array[1, 1] = new Quaternion(-1.952852E-08f, -2.699741E-08f, -0.1618618f, 0.9868135f);
  31. array[1, 2] = new Quaternion(0.7708589f, -0.2672266f, 0.03713043f, 0.577051f);
  32. array[1, 3] = new Quaternion(9.870518E-10f, 1.579613E-09f, -0.5299194f, 0.8480481f);
  33. array[1, 4] = new Quaternion(-5.034789E-09f, -5.799267E-09f, -0.8191521f, 0.5735765f);
  34. array[1, 5] = new Quaternion(0.0478053f, -0.01974053f, -0.5880075f, 0.8072003f);
  35. array[1, 6] = new Quaternion(8.812074E-09f, -1.401741E-08f, -0.5299194f, 0.8480481f);
  36. array[1, 7] = new Quaternion(-1.043265E-08f, 1.477225E-09f, -0.7992581f, 0.6009881f);
  37. array[1, 8] = new Quaternion(-0.009090314f, -0.01649067f, -0.6061373f, 0.7951371f);
  38. array[1, 9] = new Quaternion(-2.784401E-08f, 1.160059E-08f, -0.5224781f, 0.8526527f);
  39. array[1, 10] = new Quaternion(1.204624E-08f, 8.771129E-09f, -0.8084095f, 0.5886205f);
  40. array[1, 11] = new Quaternion(-0.04368013f, 0.007996441f, -0.6048046f, 0.7951349f);
  41. array[1, 12] = new Quaternion(-3.325827E-08f, 2.027481E-09f, -0.5008097f, 0.8655574f);
  42. array[1, 13] = new Quaternion(4.887594E-09f, -3.295959E-08f, -0.8191521f, 0.5735765f);
  43. array[1, 14] = new Quaternion(-0.09800828f, 0.05454942f, -0.591058f, 0.7987924f);
  44. array[2, 0] = new Quaternion(-1.299039E-08f, 7.939377E-10f, -0.08632442f, 0.9962671f);
  45. array[2, 1] = new Quaternion(-1.412307E-08f, -4.882294E-09f, -0.05340298f, 0.9985731f);
  46. array[2, 2] = new Quaternion(-0.4710969f, 0.1764064f, 0.1206711f, 0.8557962f);
  47. array[2, 3] = new Quaternion(-1.785701E-09f, -1.246846E-08f, -0.06366991f, 0.9979711f);
  48. array[2, 4] = new Quaternion(-5.778726E-11f, -1.242248E-08f, -0.1014653f, 0.9948391f);
  49. array[2, 5] = new Quaternion(-0.002611603f, 0.001185287f, -0.04763259f, 0.9988608f);
  50. array[2, 6] = new Quaternion(1.790176E-09f, -1.245129E-08f, -0.0636699f, 0.9979711f);
  51. array[2, 7] = new Quaternion(5.652268E-09f, 1.780454E-09f, -0.06771687f, 0.9977046f);
  52. array[2, 8] = new Quaternion(0.001466242f, 0.004677885f, -0.07036161f, 0.9975095f);
  53. array[2, 9] = new Quaternion(7.64029E-09f, 7.058498E-09f, -0.05493468f, 0.99849f);
  54. array[2, 10] = new Quaternion(-2.104634E-09f, -7.598384E-09f, -0.08305829f, 0.9965447f);
  55. array[2, 11] = new Quaternion(0.004817214f, 0.003811401f, -0.0695642f, 0.9975586f);
  56. array[2, 12] = new Quaternion(2.864904E-09f, -1.440215E-08f, -0.02973721f, 0.9995578f);
  57. array[2, 13] = new Quaternion(-7.071282E-10f, -5.241497E-09f, -0.1014653f, 0.9948391f);
  58. array[2, 14] = new Quaternion(0.00861063f, -0.01516612f, -0.05657673f, 0.998246f);
  59. array[3, 0] = new Quaternion(7.66758E-09f, -1.102812E-08f, -0.3665012f, 0.9304176f);
  60. array[3, 1] = new Quaternion(-8.709043E-09f, -7.065411E-09f, -0.1618618f, 0.9868135f);
  61. array[3, 2] = new Quaternion(-0.7708589f, 0.2672265f, 0.03713048f, 0.577051f);
  62. array[3, 3] = new Quaternion(-8.292553E-09f, 7.889813E-10f, -0.5299194f, 0.8480481f);
  63. array[3, 4] = new Quaternion(6.103158E-09f, 4.273478E-09f, -0.8191521f, 0.5735765f);
  64. array[3, 5] = new Quaternion(-0.0478053f, 0.01974053f, -0.5880075f, 0.8072003f);
  65. array[3, 6] = new Quaternion(-1.288366E-08f, 7.501511E-09f, -0.5299194f, 0.8480481f);
  66. array[3, 7] = new Quaternion(1.786481E-08f, 1.343313E-08f, -0.7992581f, 0.6009881f);
  67. array[3, 8] = new Quaternion(0.009090304f, 0.01649068f, -0.6061373f, 0.7951371f);
  68. array[3, 9] = new Quaternion(1.513849E-08f, -3.815058E-09f, -0.5224782f, 0.8526527f);
  69. array[3, 10] = new Quaternion(-1.643181E-08f, -2.748009E-09f, -0.8084095f, 0.5886205f);
  70. array[3, 11] = new Quaternion(0.04368011f, -0.007996418f, -0.6048046f, 0.7951349f);
  71. array[3, 12] = new Quaternion(1.196498E-08f, -9.074872E-09f, -0.5008097f, 0.8655574f);
  72. array[3, 13] = new Quaternion(-4.887593E-09f, 3.295959E-08f, -0.8191521f, 0.5735765f);
  73. array[3, 14] = new Quaternion(0.09800829f, -0.0545494f, -0.5910579f, 0.7987924f);
  74. this.m_aryHandRot = array;
  75. this.m_listDefaultPose = new List<KeyValuePair<Transform, Transform>>();
  76. this.m_vPelvisPosOffs = Vector3.zero;
  77. this.m_vPelvisRotOffs = Vector3.zero;
  78. this.m_listTrackerMeshRnder = new List<MeshRenderer>();
  79. this.m_fEyeToCamThresholdAngle = -0.9f;
  80. this.m_bEyeTocam = true;
  81. this.offsy = -0.06f;
  82. this.m_nShincho = -1;
  83. this.m_nDouPer = -1;
  84. this.m_nKubiScl = -1;
  85. base..ctor();
  86. }
  87. public static OvrIK Instance
  88. {
  89. get
  90. {
  91. return OvrIK.m_this;
  92. }
  93. }
  94. public static bool IsVRIKMode
  95. {
  96. get
  97. {
  98. return OvrIK.m_this != null && (OvrIK.IsModeVRIK || OvrIK.m_coCalibrate != null);
  99. }
  100. }
  101. public static bool IsModeVRIK { get; set; }
  102. private void DefaultPose()
  103. {
  104. string[] array = new string[]
  105. {
  106. "Bip01",
  107. "Bip01 Pelvis",
  108. "Bip01 Spine",
  109. "Bip01 Spine0a",
  110. "Bip01 Spine1",
  111. "Bip01 Spine1a",
  112. "Bip01 Neck",
  113. "Bip01 Head",
  114. "Bip01 L Clavicle",
  115. "Bip01 L UpperArm",
  116. "Bip01 L Forearm",
  117. "Bip01 L Hand",
  118. "Bip01 L Finger0",
  119. "Bip01 L Finger01",
  120. "Bip01 L Finger02",
  121. "Bip01 L Finger1",
  122. "Bip01 L Finger11",
  123. "Bip01 L Finger12",
  124. "Bip01 L Finger2",
  125. "Bip01 L Finger21",
  126. "Bip01 L Finger22",
  127. "Bip01 L Finger3",
  128. "Bip01 L Finger31",
  129. "Bip01 L Finger32",
  130. "Bip01 L Finger4",
  131. "Bip01 L Finger41",
  132. "Bip01 L Finger42",
  133. "Bip01 R Clavicle",
  134. "Bip01 R UpperArm",
  135. "Bip01 R Forearm",
  136. "Bip01 R Hand",
  137. "Bip01 R Finger0",
  138. "Bip01 R Finger01",
  139. "Bip01 R Finger02",
  140. "Bip01 R Finger1",
  141. "Bip01 R Finger11",
  142. "Bip01 R Finger12",
  143. "Bip01 R Finger2",
  144. "Bip01 R Finger21",
  145. "Bip01 R Finger22",
  146. "Bip01 R Finger3",
  147. "Bip01 R Finger31",
  148. "Bip01 R Finger32",
  149. "Bip01 R Finger4",
  150. "Bip01 R Finger41",
  151. "Bip01 R Finger42",
  152. "Bip01 L Thigh",
  153. "Bip01 L Calf",
  154. "Bip01 L Foot",
  155. "Bip01 L Toe2",
  156. "Bip01 L Toe21",
  157. "Bip01 L Toe1",
  158. "Bip01 L Toe11",
  159. "Bip01 L Toe0",
  160. "Bip01 L Toe01",
  161. "Bip01 R Thigh",
  162. "Bip01 R Calf",
  163. "Bip01 R Foot",
  164. "Bip01 R Toe2",
  165. "Bip01 R Toe21",
  166. "Bip01 R Toe1",
  167. "Bip01 R Toe11",
  168. "Bip01 R Toe0",
  169. "Bip01 R Toe01"
  170. };
  171. this.m_maid.body0.m_Bones.transform.position = Vector3.zero;
  172. this.m_maid.body0.m_Bones.transform.rotation = Quaternion.identity;
  173. foreach (string text in array)
  174. {
  175. Transform transform = CMT.SearchObjName(this.m_maid.body0.m_Bones2.transform, text, true);
  176. Transform transform2 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, text, true);
  177. if (transform != null && transform2 != null)
  178. {
  179. transform2.localRotation = transform.localRotation;
  180. if (text == "Bip01")
  181. {
  182. transform2.localPosition = transform.localPosition;
  183. }
  184. }
  185. }
  186. Transform transform3 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Thigh", true);
  187. transform3.localRotation = Quaternion.Euler(4.194572f, 175.3248f, -30.72415f);
  188. Transform transform4 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Calf", true);
  189. transform4.localRotation = Quaternion.Euler(-4.30072f, -1.857178f, 27.6982f);
  190. Transform transform5 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Thigh", true);
  191. transform5.localRotation = Quaternion.Euler(2.152464f, -178.752f, -30.914f);
  192. Transform transform6 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Calf", true);
  193. transform6.localRotation = Quaternion.Euler(-4.30072f, 1.857178f, 27.6982f);
  194. }
  195. public Maid NowMaid
  196. {
  197. get
  198. {
  199. return this.m_maid;
  200. }
  201. }
  202. public Transform EyeTargetTrs
  203. {
  204. get
  205. {
  206. return this.m_trEyeTarget;
  207. }
  208. }
  209. public bool EyeToCam
  210. {
  211. get
  212. {
  213. return this.m_bEyeTocam;
  214. }
  215. set
  216. {
  217. this.m_bEyeTocam = value;
  218. }
  219. }
  220. public static ControllerShortcutWindow CreateUI()
  221. {
  222. if (OvrIK.m_goVRIKConfigUI == null)
  223. {
  224. UnityEngine.Object original = Resources.Load("OVR/CircleCommandUI/Parent Controller Shortcut Setter Window");
  225. OvrIK.m_goVRIKConfigUI = (UnityEngine.Object.Instantiate(original) as GameObject);
  226. GameObject gameObject = GameObject.Find("SystemUI Root");
  227. OvrIK.m_goVRIKConfigUI.transform.SetParent(gameObject.transform, false);
  228. }
  229. if (OvrIK.m_VRIKConfigCompo == null)
  230. {
  231. OvrIK.m_VRIKConfigCompo = OvrIK.m_goVRIKConfigUI.GetComponent<ControllerShortcutWindow>();
  232. }
  233. return OvrIK.m_VRIKConfigCompo;
  234. }
  235. public static void InitStart()
  236. {
  237. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  238. if (maid != null)
  239. {
  240. OvrIK.m_this = maid.gameObject.GetComponent<OvrIK>();
  241. if (OvrIK.m_this == null)
  242. {
  243. OvrIK.m_this = maid.gameObject.AddComponent<OvrIK>();
  244. }
  245. if (!OvrIK.IsVRIKMode)
  246. {
  247. OvrIK.m_this.CalibrationStart();
  248. }
  249. }
  250. }
  251. public static void UninitEnd()
  252. {
  253. if (OvrIK.m_this != null)
  254. {
  255. OvrIK.m_this.Finish();
  256. }
  257. }
  258. public void CalibrationStart()
  259. {
  260. if (OvrIK.m_coCalibrate == null)
  261. {
  262. if (!this.Init())
  263. {
  264. return;
  265. }
  266. OvrIK.m_coCalibrate = base.StartCoroutine(this.CoCalibrate());
  267. }
  268. }
  269. private IEnumerator CoCalibrate()
  270. {
  271. yield return new WaitForSeconds(5f);
  272. this.Calibration();
  273. OvrIK.m_coCalibrate = null;
  274. yield break;
  275. }
  276. public void Finish()
  277. {
  278. if (OvrIK.m_coCalibrate != null)
  279. {
  280. base.StopCoroutine(OvrIK.m_coCalibrate);
  281. OvrIK.m_coCalibrate = null;
  282. }
  283. this.Uninit(true);
  284. }
  285. public void SelfShotCam()
  286. {
  287. if (this.m_coSelfShotCam != null)
  288. {
  289. this.m_coSelfShotCam.StartCountSnap();
  290. }
  291. }
  292. private void Uninit(bool bDestroyVRIKConfigUI = true)
  293. {
  294. OvrIK.IsModeVRIK = false;
  295. if (this.m_maid != null)
  296. {
  297. this.m_ik = this.m_maid.gameObject.GetComponent<VRIK>();
  298. if (this.m_ik != null)
  299. {
  300. UnityEngine.Object.Destroy(this.m_ik);
  301. Vector3 vector = GameMain.Instance.OvrMgr.OvrCamera.GetPos();
  302. vector += this.m_maid.transform.forward;
  303. GameMain.Instance.OvrMgr.OvrCamera.SetPos(vector);
  304. }
  305. this.m_ik = null;
  306. GameMain.Instance.OvrMgr.OvrCamera.HandVRIKMode = false;
  307. GameObject obj = this.m_maid.body0.GetSlot(1).obj;
  308. this.LayerCheck(obj, LayerMask.NameToLayer("Charactor"));
  309. GameObject obj2 = this.m_maid.body0.GetSlot(45).obj;
  310. this.LayerCheck(obj2, LayerMask.NameToLayer("Charactor"));
  311. GameObject obj3 = this.m_maid.body0.GetSlot(22).obj;
  312. this.LayerCheck(obj3, LayerMask.NameToLayer("Charactor"));
  313. Animation componentInChildren = this.m_maid.GetComponentInChildren<Animation>();
  314. if (componentInChildren != null)
  315. {
  316. componentInChildren.enabled = true;
  317. }
  318. if (this.m_aryBackAMTween != null)
  319. {
  320. foreach (AMTween amtween in this.m_aryBackAMTween)
  321. {
  322. if (amtween != null)
  323. {
  324. amtween.enabled = true;
  325. }
  326. }
  327. this.m_aryBackAMTween = null;
  328. }
  329. this.m_maid.boOffsetY = true;
  330. this.m_maid.SetMicLipSync(false);
  331. this.m_maid.SetPos(this.m_vBackPos);
  332. this.m_maid.SetRot(this.m_vBackRot);
  333. this.m_maid.body0.m_Bones.transform.localPosition = this.m_vBackRootPos;
  334. this.m_maid.body0.m_Bones.transform.localRotation = this.m_qBackRootRot;
  335. this.m_maid.SetAutoTwist(Maid.AutoTwist.ShoulderL, this.m_bBackAutoTwistShoulderL);
  336. this.m_maid.SetAutoTwist(Maid.AutoTwist.ShoulderR, this.m_bBackAutoTwistShoulderR);
  337. this.m_maid.SetAutoTwist(Maid.AutoTwist.WristL, this.m_bBackAutoTwistWristL);
  338. this.m_maid.SetAutoTwist(Maid.AutoTwist.WristR, this.m_bBackAutoTwistWristR);
  339. this.m_maid.SetAutoTwist(Maid.AutoTwist.ThighL, this.m_bBackAutoTwistThighL);
  340. this.m_maid.SetAutoTwist(Maid.AutoTwist.ThighR, this.m_bBackAutoTwistThighR);
  341. MaidColliderCollect.SuspendColliderAll(this.m_maid, true);
  342. this.m_maid.EyeToCamera(Maid.EyeMoveType.目と顔を向ける, 0f);
  343. this.m_maid = null;
  344. }
  345. for (int j = 0; j < this.m_listTrackerMeshRnder.Count; j++)
  346. {
  347. if (this.m_listTrackerMeshRnder[j] != null)
  348. {
  349. this.m_listTrackerMeshRnder[j].enabled = true;
  350. }
  351. }
  352. this.m_listTrackerMeshRnder.Clear();
  353. this.m_listDefaultPose.Clear();
  354. if (this.m_goDefaultPoseParent != null)
  355. {
  356. UnityEngine.Object.Destroy(this.m_goDefaultPoseParent);
  357. }
  358. if (this.m_goIKTargetParent != null)
  359. {
  360. UnityEngine.Object.Destroy(this.m_goIKTargetParent);
  361. }
  362. if (this.m_trTargetOffsHead != null)
  363. {
  364. UnityEngine.Object.Destroy(this.m_trTargetOffsHead.gameObject);
  365. }
  366. if (this.m_trTargetOffsPelvis != null)
  367. {
  368. UnityEngine.Object.Destroy(this.m_trTargetOffsPelvis.gameObject);
  369. }
  370. if (this.m_trTargetOffsHandL != null)
  371. {
  372. UnityEngine.Object.Destroy(this.m_trTargetOffsHandL.gameObject);
  373. }
  374. if (this.m_trTargetOffsHandR != null)
  375. {
  376. UnityEngine.Object.Destroy(this.m_trTargetOffsHandR.gameObject);
  377. }
  378. if (this.m_trTargetOffsFootL != null)
  379. {
  380. UnityEngine.Object.Destroy(this.m_trTargetOffsFootL.gameObject);
  381. }
  382. if (this.m_trTargetOffsFootR != null)
  383. {
  384. UnityEngine.Object.Destroy(this.m_trTargetOffsFootR.gameObject);
  385. }
  386. if (this.m_trTargetOffsBendGoalKneeL != null)
  387. {
  388. UnityEngine.Object.Destroy(this.m_trTargetOffsBendGoalKneeL.gameObject);
  389. }
  390. if (this.m_trTargetOffsBendGoalKneeR != null)
  391. {
  392. UnityEngine.Object.Destroy(this.m_trTargetOffsBendGoalKneeR.gameObject);
  393. }
  394. if (this.m_trTargetOffsBendGoalElbowL != null)
  395. {
  396. UnityEngine.Object.Destroy(this.m_trTargetOffsBendGoalElbowL.gameObject);
  397. }
  398. if (this.m_trTargetOffsBendGoalElbowR != null)
  399. {
  400. UnityEngine.Object.Destroy(this.m_trTargetOffsBendGoalElbowR.gameObject);
  401. }
  402. if (this.m_trTargetOffsHeadTracker != null)
  403. {
  404. UnityEngine.Object.Destroy(this.m_trTargetOffsHeadTracker.gameObject);
  405. }
  406. if (this.m_self_shot_cam != null)
  407. {
  408. UnityEngine.Object.Destroy(this.m_self_shot_cam);
  409. }
  410. if (this.m_goMoni != null)
  411. {
  412. UnityEngine.Object.Destroy(this.m_goMoni);
  413. }
  414. if (this.m_FaceCompoL != null)
  415. {
  416. UnityEngine.Object.Destroy(this.m_FaceCompoL);
  417. }
  418. if (this.m_FaceCompoR != null)
  419. {
  420. UnityEngine.Object.Destroy(this.m_FaceCompoR);
  421. }
  422. if (this.m_coHandSignL != null)
  423. {
  424. UnityEngine.Object.Destroy(this.m_coHandSignL);
  425. }
  426. if (this.m_coHandSignR != null)
  427. {
  428. UnityEngine.Object.Destroy(this.m_coHandSignR);
  429. }
  430. if (this.m_coOtherCmdL != null)
  431. {
  432. UnityEngine.Object.Destroy(this.m_coOtherCmdL);
  433. }
  434. if (this.m_coOtherCmdR != null)
  435. {
  436. UnityEngine.Object.Destroy(this.m_coOtherCmdR);
  437. }
  438. if (bDestroyVRIKConfigUI && OvrIK.m_goVRIKConfigUI != null)
  439. {
  440. UnityEngine.Object.Destroy(OvrIK.m_goVRIKConfigUI);
  441. }
  442. GameMain.Instance.OvrMgr.OvrCamera.HandModelVisible = true;
  443. GameMain.Instance.OvrMgr.OvrCamera.SetCameraMask(CameraMain.CameraMask.OvrTouchLookObj, false);
  444. }
  445. private bool Init()
  446. {
  447. this.Uninit(false);
  448. this.m_maid = base.GetComponent<Maid>();
  449. NDebug.Assert(this.m_maid != null, "メイドが居ません。");
  450. if (!this.m_maid.Visible || this.m_maid.IsBusy || !this.m_maid.body0.isLoadedBody)
  451. {
  452. Debug.Log("OVRIK 未だメイドの準備ができていません。");
  453. return false;
  454. }
  455. Animation componentInChildren = this.m_maid.GetComponentInChildren<Animation>();
  456. componentInChildren.enabled = false;
  457. this.m_aryBackAMTween = this.m_maid.GetComponentsInChildren<AMTween>(true);
  458. if (this.m_aryBackAMTween != null)
  459. {
  460. foreach (AMTween amtween in this.m_aryBackAMTween)
  461. {
  462. if (amtween != null)
  463. {
  464. amtween.enabled = false;
  465. }
  466. }
  467. }
  468. this.m_bBackAutoTwistShoulderL = this.m_maid.body0.boAutoTwistShoulderL;
  469. this.m_bBackAutoTwistShoulderR = this.m_maid.body0.boAutoTwistShoulderR;
  470. this.m_bBackAutoTwistWristL = this.m_maid.body0.boAutoTwistWristL;
  471. this.m_bBackAutoTwistWristR = this.m_maid.body0.boAutoTwistWristR;
  472. this.m_bBackAutoTwistThighL = this.m_maid.body0.boAutoTwistThighL;
  473. this.m_bBackAutoTwistThighR = this.m_maid.body0.boAutoTwistThighR;
  474. this.m_maid.SetAutoTwistAll(true);
  475. this.m_vBackPos = this.m_maid.GetPos();
  476. this.m_vBackRot = this.m_maid.GetRot();
  477. this.m_vBackRootPos = this.m_maid.body0.m_Bones.transform.localPosition;
  478. this.m_qBackRootRot = this.m_maid.body0.m_Bones.transform.localRotation;
  479. this.m_maid.EyeToCamera(Maid.EyeMoveType.無し, 0f);
  480. this.m_maid.boOffsetY = false;
  481. this.DefaultPose();
  482. this.m_maid.SetPos(Vector3.zero);
  483. this.m_maid.SetRot(Vector3.zero);
  484. this.m_maid.SetMicLipSync(true);
  485. Transform transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Thigh", true);
  486. Quaternion localRotation = transform.localRotation;
  487. transform.localRotation = Quaternion.Euler(5.025288f, -179.97f, -9.849731f);
  488. Transform transform2 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Calf", true);
  489. Quaternion localRotation2 = transform2.localRotation;
  490. transform2.localRotation = Quaternion.Euler(-4.30072f, -1.857178f, 2.579935f);
  491. Transform transform3 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Thigh", true);
  492. Quaternion localRotation3 = transform3.localRotation;
  493. transform3.localRotation = Quaternion.Euler(5.025289f, -179.97f, -9.849731f);
  494. Transform transform4 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Calf", true);
  495. Quaternion localRotation4 = transform4.localRotation;
  496. transform4.localRotation = Quaternion.Euler(-4.30072f, 1.857178f, 2.579935f);
  497. Transform transform5 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Foot", true);
  498. this.m_maid.transform.position = new Vector3(0f, this.m_maid.transform.position.y - transform5.position.y + 0.13f, 0f);
  499. transform.localRotation = localRotation;
  500. transform2.localRotation = localRotation2;
  501. transform3.localRotation = localRotation3;
  502. transform4.localRotation = localRotation4;
  503. Transform t = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Hand", true);
  504. Transform t2 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Hand", true);
  505. this.m_trHandL = new Transform[this.m_strHandBoneNameL.Length];
  506. this.m_trHandR = new Transform[this.m_strHandBoneNameR.Length];
  507. for (int j = 0; j < this.m_strHandBoneNameL.Length; j++)
  508. {
  509. this.m_trHandL[j] = CMT.SearchObjName(t, this.m_strHandBoneNameL[j], true);
  510. this.m_trHandR[j] = CMT.SearchObjName(t2, this.m_strHandBoneNameR[j], true);
  511. }
  512. return true;
  513. }
  514. private void FindAndAddParent(Transform trChild, string f_strStopBone, bool f_bParentConnect = false)
  515. {
  516. if (trChild.name == f_strStopBone)
  517. {
  518. return;
  519. }
  520. GameObject gameObject = new GameObject(trChild.name);
  521. gameObject.transform.position = trChild.position;
  522. gameObject.transform.rotation = trChild.rotation;
  523. if (this.m_listDefaultPose.Count != 0 && f_bParentConnect)
  524. {
  525. this.m_listDefaultPose[this.m_listDefaultPose.Count - 1].Value.SetParent(gameObject.transform);
  526. }
  527. this.m_listDefaultPose.Add(new KeyValuePair<Transform, Transform>(trChild, gameObject.transform));
  528. if (trChild.parent != null)
  529. {
  530. this.FindAndAddParent(trChild.parent, f_strStopBone, true);
  531. }
  532. }
  533. private void LayerCheck(GameObject goParent, int nLayer)
  534. {
  535. if (goParent == null)
  536. {
  537. return;
  538. }
  539. try
  540. {
  541. for (int i = 0; i < goParent.transform.childCount; i++)
  542. {
  543. this.LayerCheck(goParent.transform.GetChild(i).gameObject, nLayer);
  544. }
  545. goParent.layer = nLayer;
  546. }
  547. catch (Exception message)
  548. {
  549. Debug.LogError(message);
  550. }
  551. }
  552. private void Calibration()
  553. {
  554. OvrIK.IsModeVRIK = true;
  555. MaidColliderCollect.SuspendColliderAll(this.m_maid, false);
  556. this.m_ik = this.m_maid.gameObject.GetComponent<VRIK>();
  557. if (this.m_ik == null)
  558. {
  559. this.m_ik = this.m_maid.gameObject.AddComponent<VRIK>();
  560. }
  561. OvrIK.m_conf = OvrIK.m_conf.Read();
  562. OvrIK.m_conf.Update(this.m_ik);
  563. this.m_fEyeToCamThresholdAngle = OvrIK.m_conf.m_fEyeToCamThresholdAngle;
  564. VRIK.References references = this.m_ik.references;
  565. string text = "Bip01";
  566. if (this.m_maid.boMAN)
  567. {
  568. text = "ManBip";
  569. }
  570. references.root = this.m_maid.body0.m_Bones.transform;
  571. references.pelvis = references.root.Find(text);
  572. references.spine = this.m_maid.body0.Spine;
  573. references.chest = this.m_maid.body0.Spine1a;
  574. references.neck = this.m_maid.body0.trsNeck;
  575. references.head = this.m_maid.body0.trsHead;
  576. references.leftShoulder = this.m_maid.body0.ClavicleL;
  577. references.leftUpperArm = this.m_maid.body0.UpperArmL;
  578. references.leftForearm = references.leftUpperArm.Find(text + " L Forearm");
  579. references.leftHand = references.leftForearm.Find(text + " L Hand");
  580. references.rightShoulder = this.m_maid.body0.ClavicleR;
  581. references.rightUpperArm = this.m_maid.body0.UpperArmR;
  582. references.rightForearm = references.rightUpperArm.Find(text + " R Forearm");
  583. references.rightHand = references.rightForearm.Find(text + " R Hand");
  584. references.leftThigh = this.m_maid.body0.Thigh_L;
  585. references.leftCalf = this.m_maid.body0.Calf_L;
  586. references.leftFoot = references.leftCalf.Find(text + " L Foot");
  587. references.rightThigh = this.m_maid.body0.Thigh_R;
  588. references.rightCalf = this.m_maid.body0.Calf_R;
  589. references.rightFoot = references.rightCalf.Find(text + " R Foot");
  590. this.m_ik.solver.leftLeg.positionWeight = 1f;
  591. this.m_ik.solver.leftLeg.rotationWeight = 1f;
  592. this.m_ik.solver.leftLeg.bendGoalWeight = 1f;
  593. this.m_ik.solver.rightLeg.positionWeight = 1f;
  594. this.m_ik.solver.rightLeg.rotationWeight = 1f;
  595. this.m_ik.solver.rightLeg.bendGoalWeight = 1f;
  596. this.m_ik.solver.plantFeet = false;
  597. if (this.m_goIKTargetParent != null)
  598. {
  599. UnityEngine.Object.Destroy(this.m_goIKTargetParent);
  600. }
  601. this.m_goIKTargetParent = new GameObject("VRIK Dummy Targets");
  602. Transform transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 Head", true);
  603. this.m_trTargetOffsHead = new GameObject("VRIK Target Offs Head").transform;
  604. this.m_trTargetOffsHead.position = transform.position;
  605. this.m_trTargetOffsHead.rotation = transform.rotation;
  606. this.m_trTargetOffsHead.SetParent(this.m_goIKTargetParent.transform, true);
  607. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01", true);
  608. this.m_trTargetOffsPelvis = new GameObject("VRIK Target Offs Pelvis").transform;
  609. this.m_trTargetOffsPelvis.position = transform.position;
  610. this.m_trTargetOffsPelvis.rotation = transform.rotation;
  611. this.m_trTargetOffsPelvis.SetParent(this.m_goIKTargetParent.transform, true);
  612. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Hand", true);
  613. this.m_trTargetOffsHandL = new GameObject("VRIK Target Offs Hand L").transform;
  614. this.m_trTargetOffsHandL.position = transform.position;
  615. this.m_trTargetOffsHandL.rotation = transform.rotation;
  616. this.m_trTargetOffsHandL.SetParent(this.m_goIKTargetParent.transform, true);
  617. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Hand", true);
  618. this.m_trTargetOffsHandR = new GameObject("VRIK Target Offs Hand R").transform;
  619. this.m_trTargetOffsHandR.position = transform.position;
  620. this.m_trTargetOffsHandR.rotation = transform.rotation;
  621. this.m_trTargetOffsHandR.SetParent(this.m_goIKTargetParent.transform, true);
  622. this.m_ik.solver.spine.headTarget = this.m_trTargetOffsHead;
  623. this.m_ik.solver.spine.pelvisTarget = this.m_trTargetOffsPelvis;
  624. this.m_ik.solver.leftArm.target = this.m_trTargetOffsHandL;
  625. this.m_ik.solver.rightArm.target = this.m_trTargetOffsHandR;
  626. this.m_ik.solver.spine.pelvisPositionOffset = this.m_vPelvisPosOffs;
  627. this.m_ik.solver.spine.pelvisRotationOffset = Quaternion.Euler(this.m_vPelvisRotOffs);
  628. this.m_ik.solver.spine.pelvisPositionWeight = 0f;
  629. this.m_ik.solver.spine.headClampWeight = 0f;
  630. this.m_ik.solver.spine.chestRotationWeight = 0.3f;
  631. this.m_ik.solver.spine.chestClampWeight = 0.5f;
  632. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Foot", true);
  633. this.m_trTargetOffsFootL = new GameObject("VRIK Target Offs Foot L").transform;
  634. this.m_trTargetOffsFootL.position = transform.position;
  635. this.m_trTargetOffsFootL.rotation = transform.rotation;
  636. this.m_trTargetOffsFootL.SetParent(this.m_goIKTargetParent.transform, true);
  637. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Foot", true);
  638. this.m_trTargetOffsFootR = new GameObject("VRIK Target Offs Foot R").transform;
  639. this.m_trTargetOffsFootR.position = transform.position;
  640. this.m_trTargetOffsFootR.rotation = transform.rotation;
  641. this.m_trTargetOffsFootR.SetParent(this.m_goIKTargetParent.transform, true);
  642. this.m_ik.solver.leftLeg.target = this.m_trTargetOffsFootL;
  643. this.m_ik.solver.rightLeg.target = this.m_trTargetOffsFootR;
  644. this.m_ik.UpdateSolverExternal();
  645. Transform transform2 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Thigh", true);
  646. transform2.localRotation = Quaternion.Euler(5.025288f, -179.97f, -9.849731f);
  647. Transform transform3 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Calf", true);
  648. transform3.localRotation = Quaternion.Euler(-4.30072f, -1.857178f, 2.579935f);
  649. Transform transform4 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Thigh", true);
  650. transform4.localRotation = Quaternion.Euler(5.025289f, -179.97f, -9.849731f);
  651. Transform transform5 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Calf", true);
  652. transform5.localRotation = Quaternion.Euler(-4.30072f, 1.857178f, 2.579935f);
  653. this.m_listDefaultPose.Clear();
  654. if (this.m_goDefaultPoseParent != null)
  655. {
  656. UnityEngine.Object.Destroy(this.m_goDefaultPoseParent);
  657. }
  658. this.m_goDefaultPoseParent = new GameObject("VRIK Default Pose Parent");
  659. Transform transform6 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01", true).transform;
  660. this.FindAndAddParent(CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Foot", true).transform, "Bip01", false);
  661. GameObject gameObject = new GameObject(transform6.name);
  662. gameObject.transform.SetParent(this.m_goDefaultPoseParent.transform, false);
  663. gameObject.transform.position = transform6.position;
  664. gameObject.transform.rotation = transform6.rotation;
  665. this.m_listDefaultPose[this.m_listDefaultPose.Count - 1].Value.SetParent(gameObject.transform, true);
  666. this.m_listDefaultPose.Add(new KeyValuePair<Transform, Transform>(transform6, gameObject.transform));
  667. this.FindAndAddParent(CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Eyepos_R", false).transform, "Bip01", false);
  668. this.m_listDefaultPose[this.m_listDefaultPose.Count - 1].Value.SetParent(gameObject.transform, true);
  669. this.m_trMaidDefaultPoseEyeR = this.m_listDefaultPose.Find((KeyValuePair<Transform, Transform> a) => a.Key.name == "Eyepos_R").Value;
  670. this.m_trMaidDefaultPoseFootR = this.m_listDefaultPose.Find((KeyValuePair<Transform, Transform> a) => a.Key.name == "Bip01 R Foot").Value;
  671. GameMain.Instance.OvrMgr.OvrCamera.HandModelVisible = false;
  672. Transform hand_trans = GameMain.Instance.OvrMgr.ovr_obj.left_controller.hand_trans;
  673. Transform hand_trans2 = GameMain.Instance.OvrMgr.ovr_obj.right_controller.hand_trans;
  674. this.m_FaceCompoL = hand_trans.gameObject.GetComponent<PhotoFaceDataShortcutParent>();
  675. if (this.m_FaceCompoL == null)
  676. {
  677. this.m_FaceCompoL = hand_trans.gameObject.AddComponent<PhotoFaceDataShortcutParent>();
  678. }
  679. this.m_FaceCompoL.Init(true);
  680. this.m_FaceCompoL.isEnableHandUI = false;
  681. this.m_FaceCompoR = hand_trans2.gameObject.GetComponent<PhotoFaceDataShortcutParent>();
  682. if (this.m_FaceCompoR == null)
  683. {
  684. this.m_FaceCompoR = hand_trans2.gameObject.AddComponent<PhotoFaceDataShortcutParent>();
  685. }
  686. this.m_FaceCompoR.Init(false);
  687. this.m_FaceCompoR.isEnableHandUI = false;
  688. this.m_coHandSignL = hand_trans.gameObject.GetComponent<HandSignShortcut>();
  689. if (this.m_coHandSignL == null)
  690. {
  691. this.m_coHandSignL = hand_trans.gameObject.AddComponent<HandSignShortcut>();
  692. }
  693. this.m_coHandSignL.Init(true);
  694. this.m_coHandSignL.isEnableHandUI = false;
  695. this.m_coHandSignR = hand_trans2.gameObject.GetComponent<HandSignShortcut>();
  696. if (this.m_coHandSignR == null)
  697. {
  698. this.m_coHandSignR = hand_trans2.gameObject.AddComponent<HandSignShortcut>();
  699. }
  700. this.m_coHandSignR.Init(false);
  701. this.m_coHandSignR.isEnableHandUI = false;
  702. this.m_coOtherCmdL = hand_trans.gameObject.GetComponent<OtherCommandShortcut>();
  703. if (this.m_coOtherCmdL == null)
  704. {
  705. this.m_coOtherCmdL = hand_trans.gameObject.AddComponent<OtherCommandShortcut>();
  706. }
  707. this.m_coOtherCmdL.Init(true);
  708. this.m_coOtherCmdL.isEnableHandUI = false;
  709. this.m_coOtherCmdR = hand_trans2.gameObject.GetComponent<OtherCommandShortcut>();
  710. if (this.m_coOtherCmdR == null)
  711. {
  712. this.m_coOtherCmdR = hand_trans2.gameObject.AddComponent<OtherCommandShortcut>();
  713. }
  714. this.m_coOtherCmdR.Init(false);
  715. this.m_coOtherCmdR.isEnableHandUI = false;
  716. if (OvrIK.m_goVRIKConfigUI == null)
  717. {
  718. UnityEngine.Object original = Resources.Load("OVR/CircleCommandUI/Parent Controller Shortcut Setter Window");
  719. OvrIK.m_goVRIKConfigUI = (UnityEngine.Object.Instantiate(original) as GameObject);
  720. GameObject gameObject2 = GameObject.Find("SystemUI Root");
  721. OvrIK.m_goVRIKConfigUI.transform.SetParent(gameObject2.transform, false);
  722. }
  723. if (OvrIK.m_VRIKConfigCompo == null)
  724. {
  725. OvrIK.m_VRIKConfigCompo = OvrIK.m_goVRIKConfigUI.GetComponent<ControllerShortcutWindow>();
  726. }
  727. OvrIK.m_VRIKConfigCompo.Init(this.m_FaceCompoR, this.m_FaceCompoL);
  728. OvrIK.m_VRIKConfigCompo.Open();
  729. GameMain.Instance.OvrMgr.OvrCamera.HandVRIKMode = true;
  730. if (this.m_ik == null)
  731. {
  732. Debug.LogError("未だVRIKが付いていません。");
  733. return;
  734. }
  735. this.m_maid = base.GetComponent<Maid>();
  736. NDebug.Assert(this.m_maid != null, "メイドが居ません。");
  737. this.m_maid.boOffsetY = false;
  738. GameObject obj = this.m_maid.body0.GetSlot(1).obj;
  739. this.LayerCheck(obj, LayerMask.NameToLayer("Face"));
  740. GameObject obj2 = this.m_maid.body0.GetSlot(45).obj;
  741. this.LayerCheck(obj2, LayerMask.NameToLayer("Face"));
  742. GameObject obj3 = this.m_maid.body0.GetSlot(22).obj;
  743. this.LayerCheck(obj3, LayerMask.NameToLayer("Face"));
  744. GameMain.Instance.OvrMgr.OvrCamera.SetCameraMask((CameraMain.CameraMask)LayerMask.NameToLayer("Face"), false);
  745. Transform transform7 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Eyepos_L", false);
  746. Transform transform8 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Eyepos_R", false);
  747. Vector3 vector = transform8.position + (transform7.position - transform8.position) * 0.5f;
  748. this.m_trPlayerDefaultPoseEye = new GameObject("Pair Player Eye").transform;
  749. this.m_trPlayerDefaultPoseEye.SetParent(this.m_goDefaultPoseParent.transform, false);
  750. this.m_trPlayerDefaultPoseEye.position = vector;
  751. GameMain.Instance.OvrMgr.OvrCamera.SetRealHeadPos(vector, false);
  752. GameMain.Instance.OvrMgr.OvrCamera.SetRealHeadRot(new Vector3(0f, 0f, 0f), true);
  753. Transform realHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  754. Transform hand_trans3 = GameMain.Instance.OvrMgr.ovr_obj.left_controller.hand_trans;
  755. Transform hand_trans4 = GameMain.Instance.OvrMgr.ovr_obj.right_controller.hand_trans;
  756. this.m_trTargetOffsHead.SetParent(realHeadTransform, false);
  757. this.m_trTargetOffsHead.localPosition = new Vector3(0f, -0.03f, -0.05f);
  758. this.m_trTargetOffsHead.localRotation = Quaternion.Euler(0f, -90f, -90f);
  759. this.m_trTargetOffsHandL.SetParent(hand_trans3, false);
  760. this.m_trTargetOffsHandL.localPosition = new Vector3(-0.014f, -0.032f, -0.106f);
  761. this.m_trTargetOffsHandL.localRotation = Quaternion.Euler(74.50851f, -128.3506f, 135.9052f);
  762. this.m_trTargetOffsHandR.SetParent(hand_trans4, false);
  763. this.m_trTargetOffsHandR.localPosition = new Vector3(0.014f, -0.032f, -0.106f);
  764. this.m_trTargetOffsHandR.localRotation = Quaternion.Euler(-83.64291f, 34.33916f, 46.03844f);
  765. this.m_ik.solver.spine.headTarget = this.m_trTargetOffsHead;
  766. this.m_ik.solver.leftArm.target = this.m_trTargetOffsHandL;
  767. this.m_ik.solver.rightArm.target = this.m_trTargetOffsHandR;
  768. AVRTrackingObjectsMgr trackingObjectsMgr = GameMain.Instance.OvrMgr.TrackingObjectsMgr;
  769. if (trackingObjectsMgr != null)
  770. {
  771. trackingObjectsMgr.Refresh();
  772. List<Transform> trackingObjects = trackingObjectsMgr.TrackingObjects;
  773. for (int i = 0; i < trackingObjects.Count; i++)
  774. {
  775. MeshRenderer[] componentsInChildren = trackingObjects[i].GetComponentsInChildren<MeshRenderer>();
  776. for (int j = 0; j < componentsInChildren.Length; j++)
  777. {
  778. this.m_listTrackerMeshRnder.Add(componentsInChildren[j]);
  779. }
  780. }
  781. bool use1TrackerForHead = ControllerShortcutSettingData.config.use1TrackerForHead;
  782. if (use1TrackerForHead && 1 <= trackingObjects.Count)
  783. {
  784. Debug.Log("OvrIK トラッカーが1つ見つかりました。ヘッドトラッキングに使えます。");
  785. trackingObjects.Sort((Transform a, Transform b) => (b.transform.position.y - a.transform.position.y >= 0f) ? 1 : -1);
  786. Transform parent = trackingObjects[0];
  787. Transform transform9 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 Head", true);
  788. this.m_trTargetOffsHeadTracker = new GameObject("VRIK Target Offs Head Tracker").transform;
  789. this.m_trTargetOffsHeadTracker.position = transform9.position;
  790. this.m_trTargetOffsHeadTracker.rotation = transform9.rotation;
  791. this.m_trTargetOffsHeadTracker.SetParent(parent, true);
  792. this.m_ik.solver.spine.headTarget = this.m_trTargetOffsHeadTracker;
  793. trackingObjects.Remove(transform);
  794. this.CheckHeadIsTracker();
  795. }
  796. Transform transform10 = null;
  797. Transform transform11 = null;
  798. Transform transform12 = null;
  799. Transform transform13 = null;
  800. Transform transform14 = null;
  801. Transform transform15 = null;
  802. Transform transform16 = null;
  803. Func<Transform, Transform, Vector3> func = (Transform trA, Transform trB) => trA.position - trB.position;
  804. Func<Transform, Transform, Transform, bool> func2 = (Transform trBase, Transform trA, Transform trB) => (trBase.position - trA.position).sqrMagnitude < (trBase.position - trB.position).sqrMagnitude;
  805. trackingObjects.Sort((Transform a, Transform b) => (a.transform.position.y - b.transform.position.y <= 0f) ? 1 : -1);
  806. if (2 <= trackingObjects.Count)
  807. {
  808. Transform transform17 = trackingObjects[0];
  809. Transform transform18 = trackingObjects[1];
  810. if (Mathf.Abs(func(transform17, hand_trans3).y) <= 0.5f && Mathf.Abs(func(transform18, hand_trans3).y) <= 0.5f)
  811. {
  812. if (func2(hand_trans3, transform17, transform18))
  813. {
  814. transform14 = transform17;
  815. transform15 = transform18;
  816. }
  817. else
  818. {
  819. transform14 = transform18;
  820. transform15 = transform17;
  821. }
  822. trackingObjects.Remove(transform17);
  823. trackingObjects.Remove(transform18);
  824. Debug.Log("肘");
  825. }
  826. }
  827. trackingObjects.Sort((Transform a, Transform b) => (a.transform.position.y - b.transform.position.y >= 0f) ? 1 : -1);
  828. if (2 <= trackingObjects.Count)
  829. {
  830. Transform transform19 = trackingObjects[0];
  831. Transform transform20 = trackingObjects[1];
  832. if (Mathf.Abs(func(transform19, transform20).y) <= 0.1f && func(hand_trans3, transform19).y > 0f)
  833. {
  834. if (func2(hand_trans3, transform19, transform20))
  835. {
  836. transform10 = transform19;
  837. transform11 = transform20;
  838. }
  839. else
  840. {
  841. transform10 = transform20;
  842. transform11 = transform19;
  843. }
  844. trackingObjects.Remove(transform19);
  845. trackingObjects.Remove(transform20);
  846. Debug.Log("足");
  847. }
  848. }
  849. if (2 <= trackingObjects.Count)
  850. {
  851. Transform transform21 = trackingObjects[0];
  852. Transform transform22 = trackingObjects[1];
  853. if (Mathf.Abs(func(transform21, transform22).y) <= 0.1f && func(hand_trans3, transform21).y > 0f)
  854. {
  855. if (func2(hand_trans3, transform21, transform22))
  856. {
  857. transform12 = transform21;
  858. transform13 = transform22;
  859. }
  860. else
  861. {
  862. transform12 = transform22;
  863. transform13 = transform21;
  864. }
  865. trackingObjects.Remove(transform21);
  866. trackingObjects.Remove(transform22);
  867. Debug.Log("膝");
  868. }
  869. }
  870. if (1 <= trackingObjects.Count)
  871. {
  872. Transform transform23 = trackingObjects[0];
  873. if (func(hand_trans3, transform23).y > 0f)
  874. {
  875. transform16 = transform23;
  876. Debug.Log("腰");
  877. }
  878. }
  879. if (!false)
  880. {
  881. this.m_trTargetOffsBendGoalKneeL = new GameObject("VRIK BEND GOAL KNEE L").transform;
  882. this.m_trTargetOffsBendGoalKneeR = new GameObject("VRIK BEND GOAL KNEE R").transform;
  883. this.m_trTargetOffsBendGoalElbowL = new GameObject("VRIK BEND GOAL ELBOW L").transform;
  884. this.m_trTargetOffsBendGoalElbowR = new GameObject("VRIK BEND GOAL ELBOW R").transform;
  885. }
  886. else
  887. {
  888. this.m_trTargetOffsBendGoalKneeL = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
  889. this.m_trTargetOffsBendGoalKneeR = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
  890. this.m_trTargetOffsBendGoalElbowL = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
  891. this.m_trTargetOffsBendGoalElbowR = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
  892. this.m_trTargetOffsBendGoalKneeL.gameObject.name = "VRIK BEND GOAL KNEE L";
  893. this.m_trTargetOffsBendGoalKneeR.gameObject.name = "VRIK BEND GOAL KNEE R";
  894. this.m_trTargetOffsBendGoalElbowL.gameObject.name = "VRIK BEND GOAL ELBOW L";
  895. this.m_trTargetOffsBendGoalElbowR.gameObject.name = "VRIK BEND GOAL ELBOW R";
  896. this.m_trTargetOffsBendGoalKneeL.transform.localScale = Vector3.one * 0.03f;
  897. this.m_trTargetOffsBendGoalKneeR.transform.localScale = Vector3.one * 0.03f;
  898. this.m_trTargetOffsBendGoalElbowL.transform.localScale = Vector3.one * 0.03f;
  899. this.m_trTargetOffsBendGoalElbowR.transform.localScale = Vector3.one * 0.03f;
  900. }
  901. this.m_trTargetOffsBendGoalKneeL.SetParent(this.m_goIKTargetParent.transform, true);
  902. this.m_trTargetOffsBendGoalKneeR.SetParent(this.m_goIKTargetParent.transform, true);
  903. this.m_trTargetOffsBendGoalElbowL.SetParent(this.m_goIKTargetParent.transform, true);
  904. this.m_trTargetOffsBendGoalElbowR.SetParent(this.m_goIKTargetParent.transform, true);
  905. Action<Transform, Transform> action = delegate(Transform trA, Transform trB)
  906. {
  907. if (trA != null && trB != null)
  908. {
  909. trB.position = trA.position;
  910. trB.rotation = trA.rotation;
  911. }
  912. };
  913. if (transform10 != null && transform11 != null)
  914. {
  915. this.m_ik.solver.spine.pelvisPositionOffset = this.m_vPelvisPosOffs;
  916. this.m_ik.solver.spine.pelvisRotationOffset = Quaternion.Euler(this.m_vPelvisRotOffs);
  917. this.m_ik.solver.spine.pelvisPositionWeight = 0f;
  918. this.m_ik.solver.spine.headClampWeight = 0f;
  919. this.m_ik.solver.spine.chestRotationWeight = 0.3f;
  920. this.m_ik.solver.spine.chestClampWeight = 0.5f;
  921. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Foot", true);
  922. this.m_trTargetOffsFootL.position = transform.position;
  923. this.m_trTargetOffsFootL.rotation = transform.rotation;
  924. this.m_trTargetOffsFootL.SetParent(transform10, true);
  925. this.m_vFootDefOffsLocalL = this.m_trTargetOffsFootL.localPosition;
  926. this.m_trTargetOffsFootLVecY = new GameObject("Y Vec").transform;
  927. this.m_trTargetOffsFootLVecY.SetParent(this.m_trTargetOffsFootL, false);
  928. this.m_trTargetOffsFootLVecY.localPosition = Vector3.zero;
  929. this.m_trTargetOffsFootLVecY.position += new Vector3(0f, -1f, 0f);
  930. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Foot", true);
  931. this.m_trTargetOffsFootR.position = transform.position;
  932. this.m_trTargetOffsFootR.rotation = transform.rotation;
  933. this.m_trTargetOffsFootR.SetParent(transform11, true);
  934. this.m_vFootDefOffsLocalR = this.m_trTargetOffsFootR.localPosition;
  935. this.m_trTargetOffsFootRVecY = new GameObject("Y Vec").transform;
  936. this.m_trTargetOffsFootRVecY.SetParent(this.m_trTargetOffsFootR, false);
  937. this.m_trTargetOffsFootRVecY.localPosition = Vector3.zero;
  938. this.m_trTargetOffsFootRVecY.position += new Vector3(0f, -1f, 0f);
  939. this.m_ik.solver.leftLeg.target = this.m_trTargetOffsFootL;
  940. this.m_ik.solver.rightLeg.target = this.m_trTargetOffsFootR;
  941. this.m_bLegTracking = true;
  942. }
  943. if (transform12 != null && transform13 != null)
  944. {
  945. action(CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Calf", true), this.m_trTargetOffsBendGoalKneeL);
  946. action(CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Calf", true), this.m_trTargetOffsBendGoalKneeR);
  947. this.m_trTargetOffsBendGoalKneeL.position += realHeadTransform.forward * 0.4f;
  948. this.m_trTargetOffsBendGoalKneeR.position += realHeadTransform.forward * 0.4f;
  949. this.m_trTargetOffsBendGoalKneeL.SetParent(transform12, true);
  950. this.m_trTargetOffsBendGoalKneeR.SetParent(transform13, true);
  951. this.m_ik.solver.leftLeg.bendGoal = this.m_trTargetOffsBendGoalKneeL;
  952. this.m_ik.solver.rightLeg.bendGoal = this.m_trTargetOffsBendGoalKneeR;
  953. this.m_ik.solver.leftLeg.bendGoalWeight = (this.m_ik.solver.rightLeg.bendGoalWeight = 1f);
  954. }
  955. if (transform14 != null && transform15 != null)
  956. {
  957. action(CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Forearm", true), this.m_trTargetOffsBendGoalElbowL);
  958. action(CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Forearm", true), this.m_trTargetOffsBendGoalElbowR);
  959. this.m_trTargetOffsBendGoalElbowL.SetParent(transform14, true);
  960. this.m_trTargetOffsBendGoalElbowR.SetParent(transform15, true);
  961. this.m_ik.solver.leftArm.bendGoal = this.m_trTargetOffsBendGoalElbowL;
  962. this.m_ik.solver.rightArm.bendGoal = this.m_trTargetOffsBendGoalElbowR;
  963. this.m_ik.solver.leftArm.bendGoalWeight = (this.m_ik.solver.rightArm.bendGoalWeight = 1f);
  964. }
  965. if (transform16 != null)
  966. {
  967. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01", true);
  968. this.m_trTargetOffsPelvis.position = transform.position;
  969. this.m_trTargetOffsPelvis.rotation = transform.rotation;
  970. this.m_trTargetOffsPelvis.SetParent(transform16, true);
  971. float num = realHeadTransform.transform.position.y - (transform16.position.y - 0.2f);
  972. Transform transform24 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 Pelvis", true);
  973. float num2 = vector.y - transform24.transform.position.y;
  974. float num3 = num2 - num;
  975. this.m_ik.solver.spine.pelvisTarget = this.m_trTargetOffsPelvis;
  976. this.m_ik.solver.spine.pelvisPositionWeight = 1f;
  977. }
  978. }
  979. if (!this.m_bLegTracking)
  980. {
  981. this.m_ik.solver.leftLeg.rotationWeight = (this.m_ik.solver.rightLeg.rotationWeight = OvrIK.m_conf.leg_no_tracker_rot_weight);
  982. this.m_ik.solver.leftLeg.positionWeight = (this.m_ik.solver.rightLeg.positionWeight = OvrIK.m_conf.leg_no_tracker_pos_weight);
  983. }
  984. this.m_self_shot_cam = GameObject.Find("OvrSelfShotCamera");
  985. if (this.m_self_shot_cam == null)
  986. {
  987. this.m_coSelfShotCam = OvrSelfShotCamera.Create();
  988. this.m_self_shot_cam = this.m_coSelfShotCam.gameObject;
  989. this.m_trEyeTarget = this.m_coSelfShotCam.EyeTarget;
  990. this.m_rtMoniPlaneTex = this.m_coSelfShotCam.CamTex;
  991. }
  992. this.m_goMoni = GameObject.Find("OvrIKPlaneCamera");
  993. if (!this.m_goMoni)
  994. {
  995. this.m_goMoni = Utility.CreatePrefab(null, "OVR/OvrIKPlaneCamera", false);
  996. this.m_goMoni.name = "OvrIKPlaneCamera";
  997. this.m_trMoniPlane = this.m_goMoni.transform.Find("Plane").transform;
  998. }
  999. this.m_maid.EyeToCamera(Maid.EyeMoveType.目だけ向ける, 0f);
  1000. }
  1001. private void ReCalcShincho()
  1002. {
  1003. if (this.m_trMaidDefaultPoseEyeR == null || this.m_trPlayerDefaultPoseEye == null || this.m_trMaidDefaultPoseFootR == null || this.m_trPlayerDefaultPoseFoot == null || this.m_trTargetOffsFootL == null || this.m_trTargetOffsFootR == null)
  1004. {
  1005. return;
  1006. }
  1007. float num = this.m_trMaidDefaultPoseEyeR.position.y - this.m_trMaidDefaultPoseFootR.position.y;
  1008. float num2 = this.m_trPlayerDefaultPoseEye.position.y - this.m_trPlayerDefaultPoseFoot.position.y;
  1009. float d = num - num2 + this.offsy;
  1010. this.m_trTargetOffsFootL.localPosition = this.m_vFootDefOffsLocalL;
  1011. this.m_trTargetOffsFootR.localPosition = this.m_vFootDefOffsLocalR;
  1012. this.m_trTargetOffsFootL.position += (this.m_trTargetOffsFootLVecY.position - this.m_trTargetOffsFootL.position).normalized * d;
  1013. this.m_trTargetOffsFootR.position += (this.m_trTargetOffsFootRVecY.position - this.m_trTargetOffsFootR.position).normalized * d;
  1014. }
  1015. private void CheckHeadIsTracker()
  1016. {
  1017. bool flag = this.m_ik.solver.spine.headTarget == this.m_trTargetOffsHeadTracker;
  1018. if (flag != this.m_isHeadIsTracker)
  1019. {
  1020. if (flag)
  1021. {
  1022. GameObject obj = this.m_maid.body0.GetSlot(1).obj;
  1023. this.LayerCheck(obj, LayerMask.NameToLayer("Charactor"));
  1024. GameObject obj2 = this.m_maid.body0.GetSlot(45).obj;
  1025. this.LayerCheck(obj2, LayerMask.NameToLayer("Charactor"));
  1026. GameObject obj3 = this.m_maid.body0.GetSlot(22).obj;
  1027. this.LayerCheck(obj3, LayerMask.NameToLayer("Charactor"));
  1028. }
  1029. else
  1030. {
  1031. GameObject obj4 = this.m_maid.body0.GetSlot(1).obj;
  1032. this.LayerCheck(obj4, LayerMask.NameToLayer("Face"));
  1033. GameObject obj5 = this.m_maid.body0.GetSlot(45).obj;
  1034. this.LayerCheck(obj5, LayerMask.NameToLayer("Face"));
  1035. GameObject obj6 = this.m_maid.body0.GetSlot(22).obj;
  1036. this.LayerCheck(obj6, LayerMask.NameToLayer("Face"));
  1037. }
  1038. this.m_isHeadIsTracker = flag;
  1039. }
  1040. }
  1041. private void OnDisable()
  1042. {
  1043. this.Finish();
  1044. }
  1045. private void OnDestroy()
  1046. {
  1047. this.Finish();
  1048. }
  1049. private void Update()
  1050. {
  1051. if (Input.GetKeyUp(KeyCode.F9))
  1052. {
  1053. GameObject gameObject = GameObject.Find("TestMonitor");
  1054. GameObject gameObject2 = GameObject.Find("TestMonitorR");
  1055. if (gameObject != null)
  1056. {
  1057. UnityEngine.Object.Destroy(gameObject);
  1058. UnityEngine.Object @object = Resources.Load("OVR/TestMonitorR");
  1059. GameObject gameObject3 = UnityEngine.Object.Instantiate<GameObject>(@object as GameObject);
  1060. gameObject3.name = @object.name;
  1061. }
  1062. if (gameObject2 != null)
  1063. {
  1064. UnityEngine.Object.Destroy(gameObject2);
  1065. UnityEngine.Object object2 = Resources.Load("OVR/TestMonitor");
  1066. GameObject gameObject4 = UnityEngine.Object.Instantiate<GameObject>(object2 as GameObject);
  1067. gameObject4.name = object2.name;
  1068. }
  1069. }
  1070. if (OvrIK.IsModeVRIK && (this.m_maid == null || !this.m_maid.Visible || !this.m_maid.body0.isLoadedBody))
  1071. {
  1072. this.Finish();
  1073. }
  1074. if (this.m_ik != null)
  1075. {
  1076. if (this.m_maid != null && !this.m_maid.IsBusy)
  1077. {
  1078. for (int i = 0; i < this.m_listDefaultPose.Count; i++)
  1079. {
  1080. KeyValuePair<Transform, Transform> item = this.m_listDefaultPose[i];
  1081. if (item.Key == null)
  1082. {
  1083. Transform transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, item.Value.name, false);
  1084. if (transform != null)
  1085. {
  1086. this.m_listDefaultPose[i] = new KeyValuePair<Transform, Transform>(transform, item.Value);
  1087. }
  1088. else
  1089. {
  1090. this.m_listDefaultPose.Remove(item);
  1091. }
  1092. }
  1093. if (this.m_trMaidDefaultPoseEyeR == null)
  1094. {
  1095. Debug.Log("m_trMaidDefaultPoseEyeR");
  1096. this.m_trMaidDefaultPoseEyeR = this.m_listDefaultPose.Find((KeyValuePair<Transform, Transform> a) => a.Key.name == "Eyepos_R").Value;
  1097. }
  1098. if (item.Key != null)
  1099. {
  1100. item.Value.localPosition = item.Key.localPosition;
  1101. }
  1102. }
  1103. int value = this.m_maid.GetProp(MPN.sintyou).value;
  1104. int value2 = this.m_maid.GetProp(MPN.DouPer).value;
  1105. int value3 = this.m_maid.GetProp(MPN.KubiScl).value;
  1106. if (this.m_nShincho != value || this.m_nDouPer != value2 || this.m_nKubiScl != value3)
  1107. {
  1108. this.m_nShincho = value;
  1109. this.m_nDouPer = value2;
  1110. this.m_nKubiScl = value3;
  1111. }
  1112. if (!this.m_bLegTracking)
  1113. {
  1114. Vector3 position = this.m_trTargetOffsHead.position;
  1115. Vector3 floorPos = GameMain.Instance.OvrMgr.OvrCamera.GetFloorPos(position);
  1116. Transform trTargetOffsFootR = this.m_trTargetOffsFootR;
  1117. Vector3 position2 = new Vector3(position.x, floorPos.y, position.z);
  1118. this.m_trTargetOffsFootL.position = position2;
  1119. trTargetOffsFootR.position = position2;
  1120. }
  1121. }
  1122. this.m_ik.solver.spine.maintainPelvisPosition = ControllerShortcutSettingData.config.maintainPelvisPosition;
  1123. this.m_ik.solver.spine.bodyPosStiffness = ControllerShortcutSettingData.config.bodyPosStiffness;
  1124. this.m_ik.solver.spine.bodyRotStiffness = ControllerShortcutSettingData.config.bodyRotStiffness;
  1125. this.m_ik.solver.spine.chestRotationWeight = ControllerShortcutSettingData.config.chestRotationWeight;
  1126. this.m_ik.solver.spine.pelvisPositionOffset = this.m_vPelvisPosOffs;
  1127. this.m_ik.solver.spine.pelvisRotationOffset = Quaternion.Euler(this.m_vPelvisRotOffs);
  1128. if (this.m_ik.fixTransforms && this.m_ik.GetIKSolver().initiated)
  1129. {
  1130. this.m_ik.GetIKSolver().FixTransforms();
  1131. }
  1132. this.m_ik.UpdateSolverExternal();
  1133. if (this.m_goMoni != null)
  1134. {
  1135. if (this.m_trMoniPlane != null && this.m_rtMoniPlaneTex != null)
  1136. {
  1137. this.m_trMoniPlane.localScale = new Vector3((float)this.m_rtMoniPlaneTex.width / (float)this.m_rtMoniPlaneTex.height, 1f, 1f);
  1138. }
  1139. if (Input.GetKeyDown(KeyCode.Space))
  1140. {
  1141. this.m_goMoni.SetActive(!this.m_goMoni.activeSelf);
  1142. }
  1143. }
  1144. this.CheckHeadIsTracker();
  1145. if (this.m_trEyeTarget != null && this.m_maid != null)
  1146. {
  1147. Transform realHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  1148. float num = Vector3.Dot(this.m_trEyeTarget.forward, realHeadTransform.forward);
  1149. if (this.m_ik.solver.spine.headTarget == this.m_trTargetOffsHeadTracker)
  1150. {
  1151. num = Vector3.Dot(this.m_trEyeTarget.forward, this.m_trTargetOffsHeadTracker.up);
  1152. }
  1153. if (num < this.m_fEyeToCamThresholdAngle && this.m_bEyeTocam)
  1154. {
  1155. this.m_maid.EyeToCamera(Maid.EyeMoveType.目だけ向ける, 0f);
  1156. }
  1157. else
  1158. {
  1159. this.m_maid.EyeToCamera(Maid.EyeMoveType.無し, 0f);
  1160. }
  1161. }
  1162. for (int j = 0; j < this.m_listTrackerMeshRnder.Count; j++)
  1163. {
  1164. if (this.m_listTrackerMeshRnder[j] != null)
  1165. {
  1166. this.m_listTrackerMeshRnder[j].enabled = false;
  1167. }
  1168. }
  1169. if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyUp(KeyCode.F8))
  1170. {
  1171. if (this.m_trTargetOffsHeadTracker != null)
  1172. {
  1173. if (this.m_ik.solver.spine.headTarget == this.m_trTargetOffsHeadTracker)
  1174. {
  1175. this.m_ik.solver.spine.headTarget = this.m_trTargetOffsHead;
  1176. }
  1177. else
  1178. {
  1179. this.m_ik.solver.spine.headTarget = this.m_trTargetOffsHeadTracker;
  1180. }
  1181. }
  1182. else
  1183. {
  1184. Debug.Log("VRIK トラッカーがありませんので頭ターゲットに。");
  1185. }
  1186. }
  1187. }
  1188. }
  1189. public static List<string> UpdateGeneralModelFileList()
  1190. {
  1191. OvrIK.m_listFileList.Clear();
  1192. string str = UTY.gameProjectPath + "\\";
  1193. string path = str + "Model";
  1194. if (!Directory.Exists(path))
  1195. {
  1196. return OvrIK.m_listFileList;
  1197. }
  1198. string[] exts = new string[]
  1199. {
  1200. ".obj",
  1201. ".fbx",
  1202. ".dae",
  1203. ".stl",
  1204. ".x",
  1205. ".3ds"
  1206. };
  1207. string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
  1208. IEnumerable<string> source = from file in files
  1209. where exts.Any((string ext) => file.ToLower().EndsWith(ext))
  1210. select file;
  1211. OvrIK.m_listFileList = source.ToList<string>();
  1212. return OvrIK.m_listFileList;
  1213. }
  1214. public static void LoadGeneralModelFile(string f_strRead)
  1215. {
  1216. OvrIK.m_listGeneralModel.RemoveAll((GameObject o) => o == null);
  1217. GameObject gameObject = ImportCM.LoadGeneralModelFile(f_strRead);
  1218. if (gameObject != null)
  1219. {
  1220. MeshRenderer componentInChildren = gameObject.GetComponentInChildren<MeshRenderer>(true);
  1221. if (componentInChildren != null)
  1222. {
  1223. OvrGrabObj ovrGrabObj = gameObject.AddComponent<OvrGrabObj>();
  1224. Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>();
  1225. rigidbody.useGravity = false;
  1226. rigidbody.isKinematic = true;
  1227. ovrGrabObj.m_trTarget = gameObject.transform;
  1228. string text = Path.GetFileName(f_strRead).ToLower();
  1229. if (text.Contains("_useg"))
  1230. {
  1231. rigidbody.useGravity = true;
  1232. rigidbody.isKinematic = false;
  1233. rigidbody.mass = 0.1f;
  1234. gameObject.layer = LayerMask.NameToLayer("OvrTouchLookObj");
  1235. GameMain.Instance.OvrMgr.OvrCamera.SetCameraMask(CameraMain.CameraMask.OvrTouchLookObj, true);
  1236. ovrGrabObj.m_bGrabToKinematic = true;
  1237. ovrGrabObj.m_fEaseRate = 60f;
  1238. ovrGrabObj.m_fGrabThrowRate = 1f;
  1239. }
  1240. if (text.Contains("_sphere"))
  1241. {
  1242. OvrIK.ColliderAutoAdjust(gameObject.AddComponent<SphereCollider>(), OvrIK.GetChildenMeshCombinedBounds(gameObject));
  1243. }
  1244. else if (text.Contains("_capsule"))
  1245. {
  1246. OvrIK.ColliderAutoAdjust(gameObject.AddComponent<CapsuleCollider>(), OvrIK.GetChildenMeshCombinedBounds(gameObject));
  1247. }
  1248. else if (text.Contains("_box"))
  1249. {
  1250. OvrIK.ColliderAutoAdjust(gameObject.AddComponent<BoxCollider>(), OvrIK.GetChildenMeshCombinedBounds(gameObject));
  1251. }
  1252. else if (text.Contains("_mesh"))
  1253. {
  1254. MeshCollider meshCollider = componentInChildren.gameObject.AddComponent<MeshCollider>();
  1255. meshCollider.inflateMesh = true;
  1256. meshCollider.skinWidth = 0.03f;
  1257. meshCollider.convex = true;
  1258. }
  1259. else if (text.Contains("_useg"))
  1260. {
  1261. OvrIK.ColliderAutoAdjust(gameObject.AddComponent<BoxCollider>(), OvrIK.GetChildenMeshCombinedBounds(gameObject));
  1262. }
  1263. else
  1264. {
  1265. MeshCollider meshCollider2 = componentInChildren.gameObject.AddComponent<MeshCollider>();
  1266. meshCollider2.inflateMesh = true;
  1267. meshCollider2.skinWidth = 0.03f;
  1268. meshCollider2.convex = true;
  1269. }
  1270. if (text.Contains("_trans"))
  1271. {
  1272. componentInChildren.sharedMaterial.shader = Shader.Find("CM3D2/Lighted_Trans");
  1273. }
  1274. else
  1275. {
  1276. componentInChildren.sharedMaterial.shader = Shader.Find("CM3D2/Lighted");
  1277. }
  1278. OvrObjAutoDestory ovrObjAutoDestory = gameObject.AddComponent<OvrObjAutoDestory>();
  1279. ovrObjAutoDestory.m_goTarget = gameObject;
  1280. OvrIK.m_listGeneralModel.Add(gameObject);
  1281. }
  1282. Transform realHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  1283. Vector3 position = new Vector3(realHeadTransform.forward.x, 0f, realHeadTransform.forward.z) * 2f + realHeadTransform.position;
  1284. gameObject.transform.position = position;
  1285. }
  1286. }
  1287. private static Bounds GetChildenMeshCombinedBounds(GameObject obj)
  1288. {
  1289. NDebug.AssertNull(obj);
  1290. Bounds result = default(Bounds);
  1291. MeshRenderer[] componentsInChildren = obj.GetComponentsInChildren<MeshRenderer>();
  1292. if (componentsInChildren == null || componentsInChildren.Length <= 0)
  1293. {
  1294. return result;
  1295. }
  1296. result = componentsInChildren[0].bounds;
  1297. for (int i = 1; i < componentsInChildren.Length; i++)
  1298. {
  1299. result.Encapsulate(componentsInChildren[i].bounds);
  1300. }
  1301. return result;
  1302. }
  1303. private static void ColliderAutoAdjust(SphereCollider col, Bounds bounds)
  1304. {
  1305. col.center = bounds.center;
  1306. col.radius = bounds.extents.x;
  1307. if (col.radius < bounds.extents.y)
  1308. {
  1309. col.radius = bounds.extents.y;
  1310. }
  1311. if (col.radius < bounds.extents.z)
  1312. {
  1313. col.radius = bounds.extents.z;
  1314. }
  1315. }
  1316. private static void ColliderAutoAdjust(BoxCollider col, Bounds bounds)
  1317. {
  1318. col.center = bounds.center;
  1319. col.size = bounds.size;
  1320. }
  1321. private static void ColliderAutoAdjust(CapsuleCollider col, Bounds bounds)
  1322. {
  1323. col.center = bounds.center;
  1324. int index = 0;
  1325. int num = 2;
  1326. if (bounds.extents[index] > bounds.extents[1])
  1327. {
  1328. index = 1;
  1329. }
  1330. if (bounds.extents[index] > bounds.extents[2])
  1331. {
  1332. index = 2;
  1333. }
  1334. if (bounds.extents[num] < bounds.extents[1])
  1335. {
  1336. num = 1;
  1337. }
  1338. if (bounds.extents[num] < bounds.extents[2])
  1339. {
  1340. num = 2;
  1341. }
  1342. col.radius = bounds.extents[index];
  1343. col.height = bounds.size[num];
  1344. col.direction = num;
  1345. }
  1346. public static void DestroyGeneralModelAll()
  1347. {
  1348. foreach (GameObject gameObject in OvrIK.m_listGeneralModel)
  1349. {
  1350. if (gameObject != null)
  1351. {
  1352. UnityEngine.Object.Destroy(gameObject);
  1353. }
  1354. }
  1355. OvrIK.m_listGeneralModel.Clear();
  1356. }
  1357. private static OvrIK m_this;
  1358. private VRIK m_ik;
  1359. private static OvrIK.OvrIkConfig m_conf = new OvrIK.OvrIkConfig();
  1360. private readonly string[] m_strHandBoneNameL = new string[]
  1361. {
  1362. "Bip01 L Finger02",
  1363. "Bip01 L Finger01",
  1364. "Bip01 L Finger0",
  1365. "Bip01 L Finger12",
  1366. "Bip01 L Finger11",
  1367. "Bip01 L Finger1",
  1368. "Bip01 L Finger22",
  1369. "Bip01 L Finger21",
  1370. "Bip01 L Finger2",
  1371. "Bip01 L Finger32",
  1372. "Bip01 L Finger31",
  1373. "Bip01 L Finger3",
  1374. "Bip01 L Finger42",
  1375. "Bip01 L Finger41",
  1376. "Bip01 L Finger4"
  1377. };
  1378. private readonly string[] m_strHandBoneNameR = new string[]
  1379. {
  1380. "Bip01 R Finger02",
  1381. "Bip01 R Finger01",
  1382. "Bip01 R Finger0",
  1383. "Bip01 R Finger12",
  1384. "Bip01 R Finger11",
  1385. "Bip01 R Finger1",
  1386. "Bip01 R Finger22",
  1387. "Bip01 R Finger21",
  1388. "Bip01 R Finger2",
  1389. "Bip01 R Finger32",
  1390. "Bip01 R Finger31",
  1391. "Bip01 R Finger3",
  1392. "Bip01 R Finger42",
  1393. "Bip01 R Finger41",
  1394. "Bip01 R Finger4"
  1395. };
  1396. private readonly Quaternion[,] m_aryHandRot;
  1397. private Maid m_maid;
  1398. private Transform m_trTargetOffsHead;
  1399. private Transform m_trTargetOffsPelvis;
  1400. private Transform m_trTargetOffsHandL;
  1401. private Transform m_trTargetOffsHandR;
  1402. private Transform m_trTargetOffsFootL;
  1403. private Transform m_trTargetOffsFootR;
  1404. private Transform m_trTargetOffsBendGoalKneeL;
  1405. private Transform m_trTargetOffsBendGoalKneeR;
  1406. private Transform m_trTargetOffsBendGoalElbowL;
  1407. private Transform m_trTargetOffsBendGoalElbowR;
  1408. private Transform m_trTargetOffsHeadTracker;
  1409. private Transform m_trTargetOffsFootLVecY;
  1410. private Transform m_trTargetOffsFootRVecY;
  1411. private GameObject m_goDefaultPoseParent;
  1412. private List<KeyValuePair<Transform, Transform>> m_listDefaultPose;
  1413. private Transform m_trMaidDefaultPoseEyeR;
  1414. private Transform m_trMaidDefaultPoseFootR;
  1415. private Transform m_trPlayerDefaultPoseEye;
  1416. private Transform m_trPlayerDefaultPoseFoot;
  1417. private Transform[] m_trHandL;
  1418. private Transform[] m_trHandR;
  1419. public Vector3 m_vPelvisPosOffs;
  1420. public Vector3 m_vPelvisRotOffs;
  1421. private GameObject m_goIKTargetParent;
  1422. private int m_nCensorNum;
  1423. public bool m_bLegTracking;
  1424. private static Coroutine m_coCalibrate = null;
  1425. private GameObject m_self_shot_cam;
  1426. private OvrSelfShotCamera m_coSelfShotCam;
  1427. private GameObject m_goMoni;
  1428. private Transform m_trMoniPlane;
  1429. private RenderTexture m_rtMoniPlaneTex;
  1430. private Transform m_trEyeTarget;
  1431. private PhotoFaceDataShortcutParent m_FaceCompoL;
  1432. private PhotoFaceDataShortcutParent m_FaceCompoR;
  1433. private HandSignShortcut m_coHandSignL;
  1434. private HandSignShortcut m_coHandSignR;
  1435. private OtherCommandShortcut m_coOtherCmdL;
  1436. private OtherCommandShortcut m_coOtherCmdR;
  1437. private static GameObject m_goVRIKConfigUI;
  1438. private static ControllerShortcutWindow m_VRIKConfigCompo;
  1439. private Vector3 m_vBackPos;
  1440. private Vector3 m_vBackRot;
  1441. private Vector3 m_vBackRootPos;
  1442. private Quaternion m_qBackRootRot;
  1443. private List<MeshRenderer> m_listTrackerMeshRnder;
  1444. public float m_fEyeToCamThresholdAngle;
  1445. private bool m_bEyeTocam;
  1446. private bool m_bBackAutoTwistShoulderL;
  1447. private bool m_bBackAutoTwistShoulderR;
  1448. private bool m_bBackAutoTwistWristL;
  1449. private bool m_bBackAutoTwistWristR;
  1450. private bool m_bBackAutoTwistThighL;
  1451. private bool m_bBackAutoTwistThighR;
  1452. private AMTween[] m_aryBackAMTween;
  1453. private bool m_isHeadIsTracker;
  1454. private Vector3 m_vFootDefOffsLocalL;
  1455. private Vector3 m_vFootDefOffsLocalR;
  1456. public float offsy;
  1457. private int m_nShincho;
  1458. private int m_nDouPer;
  1459. private int m_nKubiScl;
  1460. private static List<string> m_listFileList = new List<string>();
  1461. private static List<GameObject> m_listGeneralModel = new List<GameObject>();
  1462. [Serializable]
  1463. public class OvrIkConfig : ISerializationCallbackReceiver
  1464. {
  1465. public void OnBeforeSerialize()
  1466. {
  1467. this.m_nVersion = 1570;
  1468. }
  1469. public void OnAfterDeserialize()
  1470. {
  1471. }
  1472. public bool Write()
  1473. {
  1474. string contents = JsonUtility.ToJson(this, true);
  1475. string path = Path.Combine(GameMain.Instance.SerializeStorageManager.StoreDirectoryPath, "OvrIK.json");
  1476. try
  1477. {
  1478. File.WriteAllText(path, contents);
  1479. }
  1480. catch
  1481. {
  1482. Debug.LogError("OvrIK.json の書き込みに失敗。");
  1483. return false;
  1484. }
  1485. return true;
  1486. }
  1487. public OvrIK.OvrIkConfig Read()
  1488. {
  1489. string path = Path.Combine(GameMain.Instance.SerializeStorageManager.StoreDirectoryPath, "OvrIK.json");
  1490. if (!File.Exists(path))
  1491. {
  1492. this.Write();
  1493. }
  1494. string json;
  1495. try
  1496. {
  1497. json = File.ReadAllText(path);
  1498. }
  1499. catch
  1500. {
  1501. Debug.LogError("OvrIK.json の読込に失敗。");
  1502. return this;
  1503. }
  1504. return JsonUtility.FromJson<OvrIK.OvrIkConfig>(json);
  1505. }
  1506. public void Update(VRIK f_vrik)
  1507. {
  1508. f_vrik.solver.locomotion.weight = this.solver_locomotion_weight;
  1509. f_vrik.solver.locomotion.footDistance = this.solver_locomotion_footDistance;
  1510. f_vrik.solver.locomotion.stepThreshold = this.solver_locomotion_stepThreshold;
  1511. f_vrik.solver.locomotion.angleThreshold = this.solver_locomotion_angleThreshold;
  1512. f_vrik.solver.locomotion.comAngleMlp = this.solver_locomotion_comAngleMlp;
  1513. f_vrik.solver.locomotion.maxVelocity = this.solver_locomotion_maxVelocity;
  1514. f_vrik.solver.locomotion.velocityFactor = this.solver_locomotion_velocityFactor;
  1515. f_vrik.solver.locomotion.maxLegStretch = this.solver_locomotion_maxLegStretch;
  1516. f_vrik.solver.locomotion.rootSpeed = this.solver_locomotion_rootSpeed;
  1517. f_vrik.solver.locomotion.stepSpeed = this.solver_locomotion_stepSpeed;
  1518. }
  1519. private const string CONF_NAME = "OvrIK.json";
  1520. [SerializeField]
  1521. private int m_nVersion = 1570;
  1522. [SerializeField]
  1523. private float solver_locomotion_weight = 1f;
  1524. [SerializeField]
  1525. private float solver_locomotion_footDistance = 0.1f;
  1526. [SerializeField]
  1527. private float solver_locomotion_stepThreshold = 0.28f;
  1528. [SerializeField]
  1529. private float solver_locomotion_angleThreshold = 60f;
  1530. [SerializeField]
  1531. private float solver_locomotion_comAngleMlp = 1f;
  1532. [SerializeField]
  1533. private float solver_locomotion_maxVelocity = 0.4f;
  1534. [SerializeField]
  1535. private float solver_locomotion_velocityFactor = 0.4f;
  1536. [SerializeField]
  1537. private float solver_locomotion_maxLegStretch = 1f;
  1538. [SerializeField]
  1539. private float solver_locomotion_rootSpeed = 20f;
  1540. [SerializeField]
  1541. private float solver_locomotion_stepSpeed = 3f;
  1542. [SerializeField]
  1543. private bool m_bHeadIsTracker;
  1544. [SerializeField]
  1545. public float m_fEyeToCamThresholdAngle = -0.9f;
  1546. [SerializeField]
  1547. public float leg_no_tracker_pos_weight = 0.3f;
  1548. [SerializeField]
  1549. public float leg_no_tracker_rot_weight = 0.3f;
  1550. }
  1551. }