VRTouchComm.cs 13 KB

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