VRTouchComm.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. public class VRTouchComm : MonoBehaviour
  7. {
  8. private bool m_AnyTalkVoice
  9. {
  10. get
  11. {
  12. return this.m_MaidTouchDataPair.Values.Any((VRTouchComm.VRTouchData e) => e.TgtMaid.AudioMan.isPlay());
  13. }
  14. }
  15. public void Touch_Operator(KagTagSupport tag_data)
  16. {
  17. if (tag_data.IsValid("file"))
  18. {
  19. this.Touch_Start(tag_data);
  20. }
  21. else if (tag_data.IsValid("end"))
  22. {
  23. this.Touch_End();
  24. }
  25. }
  26. public void Touch_Start(KagTagSupport tag_data)
  27. {
  28. if (this.m_VR_Kag_Mng_Fast == null)
  29. {
  30. ScriptManager scriptMgr = GameMain.Instance.ScriptMgr;
  31. if (this.m_Base_Kag_Mng == null)
  32. {
  33. this.m_Base_Kag_Mng = new BaseKagManager(scriptMgr.tjs, scriptMgr);
  34. this.m_Base_Kag_Mng.Initialize();
  35. this.m_Base_Kag_Mng.Exec();
  36. }
  37. ScriptManagerFast.KagParserFastCache kag_cache = new ScriptManagerFast.KagParserFastCache(this.m_Base_Kag_Mng);
  38. this.m_VR_Kag_Mng_Fast = new ScriptManagerFast.VRTouchKagManagerFast(this.m_Base_Kag_Mng, kag_cache, null);
  39. this.m_VR_Kag_Mng_Fast.Initialize();
  40. int num = 0;
  41. if (tag_data.IsValid("maid"))
  42. {
  43. num = tag_data.GetTagProperty("maid").AsInteger();
  44. }
  45. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(num);
  46. if (!maid)
  47. {
  48. Debug.LogErrorFormat("メイド{0}番が存在しません", new object[]
  49. {
  50. num
  51. });
  52. return;
  53. }
  54. VRTouchComm.VRTouchData vrtouchData = new VRTouchComm.VRTouchData(maid);
  55. vrtouchData.VoiceInterval = this.m_IntervalTime * (float)this.m_MaidTouchDataPair.Count;
  56. if (!this.m_MaidTouchDataPair.ContainsKey(maid))
  57. {
  58. this.m_MaidTouchDataPair.Add(maid, vrtouchData);
  59. }
  60. else
  61. {
  62. this.m_MaidTouchDataPair[maid] = vrtouchData;
  63. }
  64. this.m_CurSettingTouchData = vrtouchData;
  65. Maid maid2 = GameMain.Instance.CharacterMgr.GetMaid(num);
  66. this.m_VR_Kag_Mng_Fast.LoadScript(ScriptManager.ReplacePersonal(maid2, tag_data.GetTagProperty("file").AsString()));
  67. this.m_VR_Kag_Mng_Fast.Start();
  68. this.m_VR_Kag_Mng_Fast.Update();
  69. if (maid.IsCrcBody)
  70. {
  71. MaidColliderCollect.AddCollider(vrtouchData.TgtMaid, MaidColliderCollect.ColliderType.Crc);
  72. }
  73. else
  74. {
  75. MaidColliderCollect.AddCollider(vrtouchData.TgtMaid, MaidColliderCollect.ColliderType.Touch);
  76. }
  77. if (this.m_Touch_Mgr == null)
  78. {
  79. this.m_Touch_Mgr = new VRTouchMgr();
  80. }
  81. this.m_MaidTouchDataPair[maid].ActiveCroutine = this.Wait_Voice_Mng(vrtouchData);
  82. base.StartCoroutine(vrtouchData.ActiveCroutine);
  83. this.Script_End();
  84. this.m_CurSettingTouchData = null;
  85. }
  86. }
  87. private void Script_End()
  88. {
  89. if (this.m_VR_Kag_Mng_Fast != null)
  90. {
  91. this.m_VR_Kag_Mng_Fast.SelfDispose();
  92. this.m_VR_Kag_Mng_Fast = null;
  93. if (this.m_Base_Kag_Mng != null)
  94. {
  95. this.m_Base_Kag_Mng.Dispose();
  96. this.m_Base_Kag_Mng = null;
  97. }
  98. }
  99. }
  100. public void Touch_End()
  101. {
  102. this.Script_End();
  103. foreach (VRTouchComm.VRTouchData vrtouchData in this.m_MaidTouchDataPair.Values)
  104. {
  105. if (vrtouchData.TgtMaid)
  106. {
  107. MaidColliderCollect.RemoveColliderAll(vrtouchData.TgtMaid);
  108. vrtouchData.TgtMaid.AudioMan.Stop();
  109. vrtouchData.TgtMaid.FaceAnime(vrtouchData.FirstFace, 1f, 0);
  110. vrtouchData.TgtMaid.FaceBlend("無し");
  111. }
  112. if (vrtouchData.ActiveCroutine != null)
  113. {
  114. base.StopCoroutine(vrtouchData.ActiveCroutine);
  115. }
  116. vrtouchData.scriptDataList.Clear();
  117. }
  118. this.m_MaidTouchDataPair.Clear();
  119. this.m_Touch_Mgr = null;
  120. }
  121. private void OnDestory()
  122. {
  123. this.Touch_End();
  124. }
  125. public void Add_Touch(KagTagSupport tag_data)
  126. {
  127. this.m_CurSettingTouchData.scriptDataList.Add(this.Data_Parce(tag_data));
  128. }
  129. private VRTouchComm.Script_Data Data_Parce(KagTagSupport tag_data)
  130. {
  131. VRTouchComm.Script_Data result = default(VRTouchComm.Script_Data);
  132. if (tag_data.IsValid("maid"))
  133. {
  134. result.nMaidNo = tag_data.GetTagProperty("maid").AsInteger();
  135. if (result.nMaidNo != this.m_CurSettingTouchData.TgtMaid.ActiveSlotNo)
  136. {
  137. Debug.Log("@VRTouchScriptと@VRTouchでターゲットとなるメイドが異なります(@VRTouchScript側優先)");
  138. Debug.LogFormat("@VRTouchScript側:{0}番\u3000@VRTouch側:{1}番", new object[]
  139. {
  140. this.m_CurSettingTouchData.TgtMaid.ActiveSlotNo,
  141. result.nMaidNo
  142. });
  143. }
  144. }
  145. if (tag_data.IsValid("type"))
  146. {
  147. result.strType = tag_data.GetTagProperty("type").AsString();
  148. }
  149. if (tag_data.IsValid("voice"))
  150. {
  151. result.strVoice = tag_data.GetTagProperty("voice").AsString() + ".ogg";
  152. }
  153. if (tag_data.IsValid("num"))
  154. {
  155. result.nNum = tag_data.GetTagProperty("num").AsInteger();
  156. }
  157. if (tag_data.IsValid("region"))
  158. {
  159. result.strRegion = tag_data.GetTagProperty("region").AsString().Split(new char[]
  160. {
  161. ':'
  162. });
  163. }
  164. if (tag_data.IsValid("face"))
  165. {
  166. result.strFace = tag_data.GetTagProperty("face").AsString();
  167. }
  168. if (tag_data.IsValid("faceblend"))
  169. {
  170. result.strFaceBlend = tag_data.GetTagProperty("faceblend").AsString();
  171. }
  172. return result;
  173. }
  174. private IEnumerator Wait_Voice_Mng(VRTouchComm.VRTouchData touch_data)
  175. {
  176. float timer = 0f;
  177. float wait_time = 20f + touch_data.VoiceInterval;
  178. if (touch_data.scriptDataList.Count == 0)
  179. {
  180. timer += Time.deltaTime;
  181. yield return null;
  182. }
  183. List<VRTouchComm.Script_Data> data = touch_data.Get_Data(VRTouchComm.Type.WAIT);
  184. for (;;)
  185. {
  186. if (timer >= wait_time && !this.m_AnyTalkVoice)
  187. {
  188. timer = 0f;
  189. touch_data.VoiceInterval = 0f;
  190. if (data.Count<VRTouchComm.Script_Data>() != 0)
  191. {
  192. int index = 0;
  193. if (data.Count > 1)
  194. {
  195. index = UnityEngine.Random.Range(0, data.Count);
  196. }
  197. touch_data.TgtMaid.AudioMan.LoadPlay(data[index].strVoice, 0f, false, false);
  198. touch_data.TgtMaid.FaceAnime(data[index].strFace, 1f, 0);
  199. touch_data.TgtMaid.FaceBlend(data[index].strFaceBlend);
  200. }
  201. else
  202. {
  203. Debug.LogError("TouchComm Wait Voice is 0!!");
  204. }
  205. }
  206. else if (!touch_data.TgtMaid.AudioMan.isPlay())
  207. {
  208. timer += Time.deltaTime;
  209. }
  210. yield return null;
  211. }
  212. yield break;
  213. }
  214. private void Touch_Voice_Play(VRTouchMgr.ETouchPos touch_pos, VRTouchComm.VRTouchData touch_data)
  215. {
  216. List<VRTouchComm.Script_Data> list = touch_data.Get_Data(VRTouchComm.Type.TOUCH);
  217. list = (from e in list
  218. where e.nNum == touch_data.TouchCount
  219. select e).ToList<VRTouchComm.Script_Data>();
  220. if (list.Count == 0)
  221. {
  222. int n_count = -1;
  223. List<VRTouchComm.Script_Data> list2 = touch_data.Get_Data(VRTouchComm.Type.TOUCH);
  224. foreach (VRTouchComm.Script_Data script_Data in list2)
  225. {
  226. if (n_count == -1 || n_count < script_Data.nNum)
  227. {
  228. n_count = script_Data.nNum;
  229. }
  230. }
  231. list = (from e in list2
  232. where e.nNum == n_count
  233. select e).ToList<VRTouchComm.Script_Data>();
  234. }
  235. List<VRTouchComm.Script_Data> list3 = new List<VRTouchComm.Script_Data>(list);
  236. list.Clear();
  237. VRTouchComm.Region region = this.m_TouchPosPair.SingleOrDefault((KeyValuePair<VRTouchMgr.ETouchPos, VRTouchComm.Region> e) => e.Key == touch_pos).Value;
  238. foreach (VRTouchComm.Script_Data item in list3)
  239. {
  240. foreach (string a in item.strRegion)
  241. {
  242. if (a == this.m_RegionPair.SingleOrDefault((KeyValuePair<string, VRTouchComm.Region> e) => e.Value == region).Key)
  243. {
  244. list.Add(item);
  245. break;
  246. }
  247. }
  248. }
  249. if (list.Count > 0)
  250. {
  251. int index = 0;
  252. if (list.Count > 1)
  253. {
  254. index = UnityEngine.Random.Range(0, list.Count);
  255. }
  256. touch_data.TgtMaid.AudioMan.LoadPlay(list[index].strVoice, 0f, false, false);
  257. touch_data.TgtMaid.FaceAnime(list[index].strFace, 1f, 0);
  258. touch_data.TgtMaid.FaceBlend(list[index].strFaceBlend);
  259. }
  260. touch_data.ActiveCroutine = this.After_To_Wait(touch_data);
  261. base.StartCoroutine(touch_data.ActiveCroutine);
  262. }
  263. private IEnumerator After_To_Wait(VRTouchComm.VRTouchData touch_data)
  264. {
  265. while (touch_data.TgtMaid.AudioMan.isPlay())
  266. {
  267. yield return null;
  268. }
  269. List<VRTouchComm.Script_Data> bace_data = touch_data.Get_Data(VRTouchComm.Type.AFTER);
  270. bace_data = (from e in bace_data
  271. where e.nNum == touch_data.TouchCount
  272. select e).ToList<VRTouchComm.Script_Data>();
  273. if (bace_data.Count == 0)
  274. {
  275. int n_count = -1;
  276. List<VRTouchComm.Script_Data> list = touch_data.Get_Data(VRTouchComm.Type.AFTER);
  277. foreach (VRTouchComm.Script_Data script_Data in list)
  278. {
  279. if (n_count == -1 || n_count < script_Data.nNum)
  280. {
  281. n_count = script_Data.nNum;
  282. }
  283. }
  284. bace_data = (from e in list
  285. where e.nNum == n_count
  286. select e).ToList<VRTouchComm.Script_Data>();
  287. }
  288. int rand = 0;
  289. if (bace_data.Count > 1)
  290. {
  291. rand = UnityEngine.Random.Range(0, bace_data.Count);
  292. }
  293. touch_data.TgtMaid.FaceAnime(bace_data[rand].strFace, 1f, 0);
  294. touch_data.TgtMaid.FaceBlend(bace_data[rand].strFaceBlend);
  295. touch_data.ActiveCroutine = this.Wait_Voice_Mng(touch_data);
  296. base.StartCoroutine(touch_data.ActiveCroutine);
  297. yield break;
  298. }
  299. private void Update()
  300. {
  301. if (this.m_Touch_Mgr == null)
  302. {
  303. return;
  304. }
  305. this.m_Touch_Mgr.FrameStart();
  306. foreach (VRTouchComm.VRTouchData vrtouchData in this.m_MaidTouchDataPair.Values)
  307. {
  308. bool flag = false;
  309. VRTouchMgr.ETouchPos touch_pos = VRTouchMgr.ETouchPos.無し;
  310. int i;
  311. for (i = 0; i < this.m_RegionPair.Length; i++)
  312. {
  313. VRTouchMgr.ETouchPos key = this.m_TouchPosPair.Single((KeyValuePair<VRTouchMgr.ETouchPos, VRTouchComm.Region> e) => e.Value == this.m_RegionPair[i].Value).Key;
  314. for (int j = 0; j <= 1; j++)
  315. {
  316. if (this.m_Touch_Mgr.GetBehaviorTouch((VRTouchMgr.EHand)j, key, VRTouchMgr.ETouchBehavior.触る, vrtouchData.TgtMaid.ActiveSlotNo))
  317. {
  318. flag = true;
  319. touch_pos = key;
  320. this.m_Touch_Mgr.FrameEnd();
  321. break;
  322. }
  323. }
  324. if (flag)
  325. {
  326. break;
  327. }
  328. }
  329. if (flag)
  330. {
  331. if (!vrtouchData.IsTouch)
  332. {
  333. if (vrtouchData.ActiveCroutine != null)
  334. {
  335. base.StopCoroutine(vrtouchData.ActiveCroutine);
  336. }
  337. this.Touch_Voice_Play(touch_pos, vrtouchData);
  338. vrtouchData.TouchCount++;
  339. }
  340. vrtouchData.IsTouch = true;
  341. }
  342. else
  343. {
  344. vrtouchData.IsTouch = false;
  345. }
  346. }
  347. this.m_Touch_Mgr.FrameEnd();
  348. }
  349. private ScriptManagerFast.VRTouchKagManagerFast m_VR_Kag_Mng_Fast;
  350. private BaseKagManager m_Base_Kag_Mng;
  351. private KeyValuePair<string, VRTouchComm.Region>[] m_RegionPair = new KeyValuePair<string, VRTouchComm.Region>[]
  352. {
  353. new KeyValuePair<string, VRTouchComm.Region>("頭", VRTouchComm.Region.Head),
  354. new KeyValuePair<string, VRTouchComm.Region>("胸", VRTouchComm.Region.Bust),
  355. new KeyValuePair<string, VRTouchComm.Region>("尻", VRTouchComm.Region.Hip),
  356. new KeyValuePair<string, VRTouchComm.Region>("手", VRTouchComm.Region.Hand)
  357. };
  358. private List<KeyValuePair<VRTouchMgr.ETouchPos, VRTouchComm.Region>> m_TouchPosPair = new List<KeyValuePair<VRTouchMgr.ETouchPos, VRTouchComm.Region>>
  359. {
  360. new KeyValuePair<VRTouchMgr.ETouchPos, VRTouchComm.Region>(VRTouchMgr.ETouchPos.頭頂部, VRTouchComm.Region.Head),
  361. new KeyValuePair<VRTouchMgr.ETouchPos, VRTouchComm.Region>(VRTouchMgr.ETouchPos.胸, VRTouchComm.Region.Bust),
  362. new KeyValuePair<VRTouchMgr.ETouchPos, VRTouchComm.Region>(VRTouchMgr.ETouchPos.お尻, VRTouchComm.Region.Hip),
  363. new KeyValuePair<VRTouchMgr.ETouchPos, VRTouchComm.Region>(VRTouchMgr.ETouchPos.手, VRTouchComm.Region.Hand)
  364. };
  365. private Dictionary<Maid, VRTouchComm.VRTouchData> m_MaidTouchDataPair = new Dictionary<Maid, VRTouchComm.VRTouchData>();
  366. private VRTouchMgr m_Touch_Mgr;
  367. private VRTouchComm.VRTouchData m_CurSettingTouchData;
  368. [SerializeField]
  369. [Header("ボイス再生時のインターバル")]
  370. private float m_IntervalTime = 20f;
  371. public enum Type
  372. {
  373. WAIT,
  374. TOUCH,
  375. AFTER
  376. }
  377. public enum Region
  378. {
  379. Non,
  380. Head,
  381. Bust,
  382. Hip = 4,
  383. Hand = 8
  384. }
  385. private struct Script_Data
  386. {
  387. public int nMaidNo;
  388. public string strType;
  389. public int nNum;
  390. public string strVoice;
  391. public string[] strRegion;
  392. public string strFace;
  393. public string strFaceBlend;
  394. }
  395. private class VRTouchData
  396. {
  397. public VRTouchData(Maid maid)
  398. {
  399. this.TgtMaid = maid;
  400. this.FirstFace = maid.ActiveFace;
  401. }
  402. public List<VRTouchComm.Script_Data> Get_Data(VRTouchComm.Type type)
  403. {
  404. List<VRTouchComm.Script_Data> result = new List<VRTouchComm.Script_Data>();
  405. switch (type)
  406. {
  407. case VRTouchComm.Type.WAIT:
  408. result = (from e in this.scriptDataList
  409. where e.strType == "wait"
  410. select e).ToList<VRTouchComm.Script_Data>();
  411. break;
  412. case VRTouchComm.Type.TOUCH:
  413. result = (from e in this.scriptDataList
  414. where e.strType == "touch"
  415. select e).ToList<VRTouchComm.Script_Data>();
  416. break;
  417. case VRTouchComm.Type.AFTER:
  418. result = (from e in this.scriptDataList
  419. where e.strType == "after"
  420. select e).ToList<VRTouchComm.Script_Data>();
  421. break;
  422. }
  423. return result;
  424. }
  425. public List<VRTouchComm.Script_Data> scriptDataList = new List<VRTouchComm.Script_Data>();
  426. public bool IsTouch;
  427. public string FirstFace = string.Empty;
  428. public int TouchCount;
  429. public Maid TgtMaid;
  430. public IEnumerator ActiveCroutine;
  431. public float VoiceInterval;
  432. }
  433. }