VRExternalFileLoader.cs 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using RenderHeads.Media.AVProVideo;
  6. using UnityEngine;
  7. using UnityEngine.Events;
  8. using UnityEngine.UI;
  9. public class VRExternalFileLoader : MonoBehaviour
  10. {
  11. private void Update()
  12. {
  13. if (SceneVRCommunication.Instance == null)
  14. {
  15. return;
  16. }
  17. bool isFreeMode = SceneVRCommunication.Instance.IsFreeMode;
  18. if (!isFreeMode && this.m_BeforeFreeMode)
  19. {
  20. VRExternalFileLoader.Event_CloseMovie();
  21. if (SceneVRCommunication.Instance.GetNowTime() == SceneVRCommunication.VR_TIME.NIGHT)
  22. {
  23. GameMain.Instance.SoundMgr.PlayBGM("BGM_vr0001.ogg", 1f, true);
  24. }
  25. else
  26. {
  27. GameMain.Instance.SoundMgr.PlayBGM("BGM007.ogg", 1f, true);
  28. }
  29. }
  30. this.m_BeforeFreeMode = isFreeMode;
  31. }
  32. public void LoadAllMovieFile(string dataPath, params string[] extensions)
  33. {
  34. this.m_MediaPlayer.m_VideoPath = dataPath;
  35. DirectoryInfo directoryInfo = new DirectoryInfo(dataPath);
  36. if (!directoryInfo.Exists)
  37. {
  38. Directory.CreateDirectory(dataPath);
  39. }
  40. foreach (string searchPattern in extensions)
  41. {
  42. FileInfo[] files = directoryInfo.GetFiles(searchPattern);
  43. foreach (FileInfo fileInfo in files)
  44. {
  45. this.CreateMediaInfoButton(this.m_UIPrefabMovieButton.gameObject, fileInfo.Name, fileInfo.FullName, 0, MediaPlayerEvent.EventType.FirstFrameReady);
  46. VRExternalFileLoader.m_LoadingCount++;
  47. }
  48. }
  49. }
  50. public void LoadAllMusicFile(string dataPath, params string[] extensions)
  51. {
  52. this.m_MediaPlayer.m_VideoPath = dataPath;
  53. DirectoryInfo directoryInfo = new DirectoryInfo(dataPath);
  54. if (!directoryInfo.Exists)
  55. {
  56. Directory.CreateDirectory(dataPath);
  57. }
  58. foreach (string searchPattern in extensions)
  59. {
  60. FileInfo[] files = directoryInfo.GetFiles(searchPattern);
  61. foreach (FileInfo fileInfo in files)
  62. {
  63. this.CreateMediaInfoButton(this.m_UIPrefabMusicButton.gameObject, fileInfo.Name, fileInfo.FullName, 0, MediaPlayerEvent.EventType.ReadyToPlay);
  64. VRExternalFileLoader.m_LoadingCount++;
  65. }
  66. }
  67. }
  68. private IEnumerator Coroutine_GetMovieThumbnail(UIButtonElement element, string moviePath, GameObject elementObject)
  69. {
  70. while (!VRExternalFileLoader.m_IsEndLoad)
  71. {
  72. yield return null;
  73. }
  74. VRExternalFileLoader.m_IsEndLoad = false;
  75. if (this.m_MovieOutputer)
  76. {
  77. this.m_MovieOutputer.enabled = false;
  78. }
  79. if (!File.Exists(moviePath))
  80. {
  81. VRExternalFileLoader.m_IsEndLoad = true;
  82. VRExternalFileLoader.m_LoadingCount--;
  83. this.m_MediaPlayer.CloseVideo();
  84. this.m_MovieOutputer.enabled = true;
  85. yield break;
  86. }
  87. this.m_MediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, moviePath, false);
  88. int isOpenReady = 1;
  89. this.m_MediaPlayer.Events.AddListener(delegate(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
  90. {
  91. if (et != MediaPlayerEvent.EventType.Error)
  92. {
  93. if (et == MediaPlayerEvent.EventType.FirstFrameReady)
  94. {
  95. isOpenReady = 0;
  96. }
  97. }
  98. else
  99. {
  100. isOpenReady = -1;
  101. }
  102. });
  103. while (isOpenReady == 1)
  104. {
  105. yield return null;
  106. }
  107. if (isOpenReady == -1)
  108. {
  109. UnityEngine.Object.Destroy(elementObject);
  110. yield return null;
  111. VRExternalFileLoader.m_IsEndLoad = true;
  112. VRExternalFileLoader.m_LoadingCount--;
  113. this.m_MediaPlayer.CloseVideo();
  114. this.m_MovieOutputer.enabled = true;
  115. yield break;
  116. }
  117. IMediaInfo info = this.m_MediaPlayer.Info;
  118. Texture2D tex2D = new Texture2D(info.GetVideoWidth(), info.GetVideoHeight(), TextureFormat.ARGB32, false);
  119. this.m_MediaPlayer.ExtractFrame(tex2D, 0.5f, false, 50);
  120. if (tex2D)
  121. {
  122. Rect rect = new Rect(0f, 0f, (float)tex2D.width, (float)tex2D.height);
  123. element.imageThumbnail.sprite = Sprite.Create(tex2D, rect, Vector2.zero, 100f, 0U, SpriteMeshType.FullRect);
  124. }
  125. yield return null;
  126. float tim = info.GetDurationMs();
  127. tim *= 0.001f;
  128. string str = "再生時間 " + Mathf.Floor(tim / 60f).ToString("00") + ":" + Mathf.Repeat(tim, 60f).ToString("00");
  129. element.textContentTime.text = str;
  130. VRExternalFileLoader.m_IsEndLoad = true;
  131. VRExternalFileLoader.m_LoadingCount--;
  132. this.m_MediaPlayer.CloseVideo();
  133. this.m_MovieOutputer.enabled = true;
  134. yield break;
  135. }
  136. private IEnumerator Coroutine_GetMovieInfo(string moviePath, MediaPlayerEvent.EventType successType, UnityAction<bool, IMediaInfo> callback)
  137. {
  138. while (!VRExternalFileLoader.m_IsEndLoad)
  139. {
  140. yield return null;
  141. }
  142. VRExternalFileLoader.m_IsEndLoad = false;
  143. if (this.m_MovieOutputer)
  144. {
  145. this.m_MovieOutputer.enabled = false;
  146. }
  147. if (!File.Exists(moviePath))
  148. {
  149. VRExternalFileLoader.m_IsEndLoad = true;
  150. VRExternalFileLoader.m_LoadingCount--;
  151. this.m_MediaPlayer.CloseVideo();
  152. this.m_MovieOutputer.enabled = true;
  153. callback(false, null);
  154. yield break;
  155. }
  156. this.m_MediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, moviePath, false);
  157. int isOpenReady = 1;
  158. this.m_MediaPlayer.Events.AddListener(delegate(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
  159. {
  160. if (et == MediaPlayerEvent.EventType.Error)
  161. {
  162. isOpenReady = -1;
  163. }
  164. else if (et == successType)
  165. {
  166. isOpenReady = 0;
  167. }
  168. });
  169. while (isOpenReady == 1)
  170. {
  171. yield return null;
  172. }
  173. if (isOpenReady == -1)
  174. {
  175. VRExternalFileLoader.m_IsEndLoad = true;
  176. VRExternalFileLoader.m_LoadingCount--;
  177. this.m_MediaPlayer.CloseVideo();
  178. this.m_MovieOutputer.enabled = true;
  179. callback(false, null);
  180. yield break;
  181. }
  182. IMediaInfo info = this.m_MediaPlayer.Info;
  183. callback(true, info);
  184. yield break;
  185. }
  186. private IEnumerator Coroutine_GetMusicPlaybackTime(UIButtonElement element, string musicPath)
  187. {
  188. while (!VRExternalFileLoader.m_IsEndLoad)
  189. {
  190. yield return null;
  191. }
  192. VRExternalFileLoader.m_IsEndLoad = false;
  193. this.m_MediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, musicPath, false);
  194. bool isOpenReady = false;
  195. this.m_MediaPlayer.Events.AddListener(delegate(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
  196. {
  197. if (et == MediaPlayerEvent.EventType.ReadyToPlay)
  198. {
  199. isOpenReady = true;
  200. }
  201. });
  202. while (!isOpenReady)
  203. {
  204. yield return null;
  205. }
  206. IMediaInfo info = this.m_MediaPlayer.Info;
  207. float tim = info.GetDurationMs();
  208. tim *= 0.001f;
  209. for (int i = 0; i < 3; i++)
  210. {
  211. yield return null;
  212. }
  213. string str = "再生時間 " + Mathf.Floor(tim / 60f).ToString("00") + ":" + Mathf.Repeat(tim, 60f).ToString("00");
  214. element.textContentTime.text = str;
  215. VRExternalFileLoader.m_IsEndLoad = true;
  216. VRExternalFileLoader.m_LoadingCount--;
  217. this.m_MediaPlayer.CloseVideo();
  218. yield break;
  219. }
  220. private IEnumerator Coroutine_LoadMovieAsset(string LocalFilePath, string FileName, string AssetBundleURL)
  221. {
  222. string FullPath = LocalFilePath + FileName;
  223. if (File.Exists(FullPath))
  224. {
  225. yield break;
  226. }
  227. WWW www = new WWW(AssetBundleURL);
  228. yield return www;
  229. AssetBundle assetbundle = www.assetBundle;
  230. AssetBundleRequest resultObject = assetbundle.LoadAssetAsync<TextAsset>(FileName);
  231. yield return new WaitWhile(() => !resultObject.isDone);
  232. TextAsset movie = resultObject.asset as TextAsset;
  233. byte[] byteData = movie.bytes;
  234. File.WriteAllBytes(FullPath, byteData);
  235. assetbundle.Unload(false);
  236. yield break;
  237. }
  238. private IEnumerator Coroutine_Refresh()
  239. {
  240. VRExternalFileLoader.m_LoadingCount = 0;
  241. VRExternalFileLoader.m_IsEndLoad = true;
  242. this.m_MediaFilePath = UTY.gameProjectPath + "\\";
  243. if (VRExternalFileLoader.m_PtrMediaPlayerObject == null)
  244. {
  245. VRExternalFileLoader.m_PtrMediaPlayerObject = (UnityEngine.Object.Instantiate(Resources.Load("SceneVRCommunication\\Tablet\\Media Outputer (Music And Movie)")) as GameObject);
  246. }
  247. GameObject[] MediaPlayers = GameObject.FindGameObjectsWithTag("MediaPlayerObj");
  248. for (int i = 0; i < MediaPlayers.Length; i++)
  249. {
  250. if (this.m_MediaPlayer != null && this.m_MovieOutputer != null)
  251. {
  252. break;
  253. }
  254. if (this.m_MediaPlayer == null)
  255. {
  256. this.m_MediaPlayer = MediaPlayers[i].GetComponent<MediaPlayer>();
  257. }
  258. if (this.m_MovieOutputer == null)
  259. {
  260. this.m_MovieOutputer = MediaPlayers[i].GetComponent<ApplyToMaterial>();
  261. }
  262. }
  263. this.m_MediaPlayer.m_AutoOpen = false;
  264. this.m_MediaPlayer.m_AutoStart = false;
  265. this.m_MovieOutputer.GetComponent<MeshRenderer>().enabled = false;
  266. this.m_UIContent.anchoredPosition = Vector2.zero;
  267. for (int j = 0; j < this.m_UIContent.childCount; j++)
  268. {
  269. this.m_UIContent.GetChild(j).gameObject.SetActive(false);
  270. }
  271. if (this.m_TypeMedia == VRExternalFileLoader.TYPE_MEDIA.Movie)
  272. {
  273. string fileName = "vrcom_movie.nei";
  274. if (!GameUty.FileSystem.IsExistentFile(fileName))
  275. {
  276. NDebug.Assert("表がありません。" + fileName, false);
  277. }
  278. using (AFileBase file = GameUty.FileSystem.FileOpen(fileName))
  279. {
  280. using (CsvParser csv = new CsvParser())
  281. {
  282. bool result = csv.Open(file);
  283. NDebug.Assert(result, fileName + "\nopen failed.");
  284. for (int y = 1; y < csv.max_cell_y; y++)
  285. {
  286. if (csv.IsCellToExistData(0, y))
  287. {
  288. int x = 0;
  289. ACsvParser acsvParser = csv;
  290. int cell_x;
  291. x = (cell_x = x) + 1;
  292. int id = acsvParser.GetCellAsInteger(cell_x, y);
  293. ACsvParser acsvParser2 = csv;
  294. x = (cell_x = x) + 1;
  295. string thumbnailPath = acsvParser2.GetCellAsString(cell_x, y);
  296. ACsvParser acsvParser3 = csv;
  297. x = (cell_x = x) + 1;
  298. string movieName = acsvParser3.GetCellAsString(cell_x, y);
  299. ACsvParser acsvParser4 = csv;
  300. x = (cell_x = x) + 1;
  301. string movieTitle = acsvParser4.GetCellAsString(cell_x, y);
  302. ACsvParser acsvParser5 = csv;
  303. x = (cell_x = x) + 1;
  304. string getFlag = acsvParser5.GetCellAsString(cell_x, y);
  305. ACsvParser acsvParser6 = csv;
  306. x = (cell_x = x) + 1;
  307. string defaultFace = acsvParser6.GetCellAsString(cell_x, y);
  308. ACsvParser acsvParser7 = csv;
  309. x = (cell_x = x) + 1;
  310. string faceEvent = acsvParser7.GetCellAsString(cell_x, y);
  311. ACsvParser acsvParser8 = csv;
  312. x = (cell_x = x) + 1;
  313. string faceEvent2 = acsvParser8.GetCellAsString(cell_x, y);
  314. ACsvParser acsvParser9 = csv;
  315. x = (cell_x = x) + 1;
  316. string faceEvent3 = acsvParser9.GetCellAsString(cell_x, y);
  317. ACsvParser acsvParser10 = csv;
  318. x = (cell_x = x) + 1;
  319. string faceEvent4 = acsvParser10.GetCellAsString(cell_x, y);
  320. ACsvParser acsvParser11 = csv;
  321. x = (cell_x = x) + 1;
  322. string endEvent = acsvParser11.GetCellAsString(cell_x, y);
  323. int flag = 0;
  324. if (GameMain.Instance.CharacterMgr.GetMaid(0) != null)
  325. {
  326. flag = GameMain.Instance.CharacterMgr.GetMaid(0).status.GetFlag(getFlag);
  327. }
  328. if (flag == 1)
  329. {
  330. int faceIndex = 0;
  331. if (!string.IsNullOrEmpty(defaultFace))
  332. {
  333. if (defaultFace == "鑑賞_喜び")
  334. {
  335. faceIndex = 0;
  336. }
  337. else if (defaultFace == "鑑賞_怒り")
  338. {
  339. faceIndex = 1;
  340. }
  341. else if (defaultFace == "鑑賞_哀しみ")
  342. {
  343. faceIndex = 2;
  344. }
  345. else if (defaultFace == "鑑賞_楽しい")
  346. {
  347. faceIndex = 3;
  348. }
  349. }
  350. this.CreateMediaInfoButton3(this.m_UIPrefabMovieButton.gameObject, movieTitle, this.m_MediaFilePath + "GameData/movie_vrcom/" + movieName + ".ine", thumbnailPath, faceIndex, MediaPlayerEvent.EventType.FirstFrameReady);
  351. yield return null;
  352. }
  353. }
  354. }
  355. }
  356. }
  357. this.LoadAllMovieFile(this.m_MediaFilePath + "movie_vrcom/", new string[]
  358. {
  359. "*.mp4",
  360. "*.mov",
  361. "*.avi"
  362. });
  363. }
  364. else if (this.m_TypeMedia == VRExternalFileLoader.TYPE_MEDIA.Music)
  365. {
  366. string fileName2 = "vrcom_music.nei";
  367. if (!GameUty.FileSystem.IsExistentFile(fileName2))
  368. {
  369. NDebug.Assert("表がありません。" + fileName2, false);
  370. }
  371. using (AFileBase file2 = GameUty.FileSystem.FileOpen(fileName2))
  372. {
  373. using (CsvParser csv2 = new CsvParser())
  374. {
  375. bool result2 = csv2.Open(file2);
  376. NDebug.Assert(result2, fileName2 + "\nopen failed.");
  377. for (int y2 = 1; y2 < csv2.max_cell_y; y2++)
  378. {
  379. if (csv2.IsCellToExistData(0, y2))
  380. {
  381. int x2 = 0;
  382. ACsvParser acsvParser12 = csv2;
  383. int cell_x;
  384. x2 = (cell_x = x2) + 1;
  385. int id2 = acsvParser12.GetCellAsInteger(cell_x, y2);
  386. ACsvParser acsvParser13 = csv2;
  387. x2 = (cell_x = x2) + 1;
  388. string defaultFace2 = acsvParser13.GetCellAsString(cell_x, y2);
  389. ACsvParser acsvParser14 = csv2;
  390. x2 = (cell_x = x2) + 1;
  391. string faceEvent5 = acsvParser14.GetCellAsString(cell_x, y2);
  392. ACsvParser acsvParser15 = csv2;
  393. x2 = (cell_x = x2) + 1;
  394. string faceEvent6 = acsvParser15.GetCellAsString(cell_x, y2);
  395. ACsvParser acsvParser16 = csv2;
  396. x2 = (cell_x = x2) + 1;
  397. string faceEvent7 = acsvParser16.GetCellAsString(cell_x, y2);
  398. ACsvParser acsvParser17 = csv2;
  399. x2 = (cell_x = x2) + 1;
  400. string faceEvent8 = acsvParser17.GetCellAsString(cell_x, y2);
  401. ACsvParser acsvParser18 = csv2;
  402. x2 = (cell_x = x2) + 1;
  403. string endEvent2 = acsvParser18.GetCellAsString(cell_x, y2);
  404. string musicTitle = "none";
  405. string musicName = "none.ogg";
  406. this.GetBGMName(id2, ref musicTitle, ref musicName);
  407. if (GameUty.FileSystem.IsExistentFile(musicName))
  408. {
  409. int faceIndex2 = 0;
  410. if (!string.IsNullOrEmpty(defaultFace2))
  411. {
  412. if (defaultFace2 == "鑑賞_喜び")
  413. {
  414. faceIndex2 = 0;
  415. }
  416. else if (defaultFace2 == "鑑賞_怒り")
  417. {
  418. faceIndex2 = 1;
  419. }
  420. else if (defaultFace2 == "鑑賞_哀しみ")
  421. {
  422. faceIndex2 = 2;
  423. }
  424. else if (defaultFace2 == "鑑賞_楽しい")
  425. {
  426. faceIndex2 = 3;
  427. }
  428. }
  429. UIButtonElement element = this.CreateMediaInfoButton2(this.m_UIPrefabMusicButton.gameObject, musicTitle, musicName, faceIndex2);
  430. for (int k = 0; k < element.buttonFaces.Length; k++)
  431. {
  432. element.buttonFaces[k].GetComponent<Graphic>().raycastTarget = false;
  433. if (k != faceIndex2)
  434. {
  435. element.buttonFaces[k].gameObject.SetActive(false);
  436. }
  437. }
  438. yield return null;
  439. }
  440. }
  441. }
  442. }
  443. }
  444. this.LoadAllMusicFile(this.m_MediaFilePath + "music_vrcom/", new string[]
  445. {
  446. "*.wav",
  447. "*.mp3"
  448. });
  449. }
  450. Resources.UnloadUnusedAssets();
  451. yield break;
  452. }
  453. public UIButtonElement CreateMediaInfoButton(GameObject buttonPrefab, string buttonName, string mediaPath, int faceIndex, MediaPlayerEvent.EventType successType)
  454. {
  455. UIButtonElement data = null;
  456. base.StartCoroutine(this.Coroutine_GetMovieInfo(mediaPath, successType, delegate(bool isSuccess, IMediaInfo info)
  457. {
  458. if (!isSuccess)
  459. {
  460. return;
  461. }
  462. Transform transform = null;
  463. for (int i = 0; i < this.m_UIContent.childCount; i++)
  464. {
  465. if (!this.m_UIContent.GetChild(i).gameObject.activeSelf)
  466. {
  467. transform = this.m_UIContent.GetChild(i);
  468. break;
  469. }
  470. }
  471. if (transform == null)
  472. {
  473. transform = UnityEngine.Object.Instantiate<GameObject>(buttonPrefab).transform;
  474. }
  475. transform.gameObject.SetActive(true);
  476. UIButtonElement element = transform.GetComponent<UIButtonElement>();
  477. transform.SetParent(this.m_UIContent, false);
  478. int num = 0;
  479. for (int j = 0; j < this.m_UIContent.childCount; j++)
  480. {
  481. if (this.m_UIContent.GetChild(j).gameObject.activeSelf)
  482. {
  483. num++;
  484. }
  485. }
  486. element.textContentNumber.text = num.ToString("000");
  487. Text textContentName = element.textContentName;
  488. TextGenerator textGenerator = new TextGenerator();
  489. TextGenerationSettings generationSettings = textContentName.GetGenerationSettings(textContentName.rectTransform.rect.size);
  490. generationSettings.resizeTextMinSize = textContentName.resizeTextMinSize;
  491. generationSettings.resizeTextMaxSize = textContentName.resizeTextMaxSize;
  492. generationSettings.fontSize = textContentName.fontSize;
  493. generationSettings.font = textContentName.font;
  494. buttonName = buttonName.Replace(' ', '\u00a0');
  495. textGenerator.Populate(buttonName, generationSettings);
  496. int characterCountVisible = textGenerator.characterCountVisible;
  497. string text = buttonName;
  498. if (buttonName.Length > characterCountVisible && characterCountVisible > 3)
  499. {
  500. Debug.Log(characterCountVisible + "\n" + buttonName.Length);
  501. text = buttonName.Substring(0, characterCountVisible - 3);
  502. text += "...";
  503. }
  504. textContentName.text = text;
  505. element.ButtonEvent_ChangeFaceType(faceIndex);
  506. for (int k = 0; k < element.buttonFaces.Length; k++)
  507. {
  508. element.buttonFaces[k].GetComponent<Graphic>().raycastTarget = true;
  509. element.buttonFaces[k].gameObject.SetActive(true);
  510. }
  511. element.buttonStart.onClick.RemoveAllListeners();
  512. element.buttonStart.onClick.AddListener(delegate()
  513. {
  514. if (VRExternalFileLoader.m_LoadingCount > 0)
  515. {
  516. return;
  517. }
  518. if (!File.Exists(mediaPath))
  519. {
  520. return;
  521. }
  522. if (<CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer == null)
  523. {
  524. if (VRExternalFileLoader.m_PtrMediaPlayerObject == null)
  525. {
  526. VRExternalFileLoader.m_PtrMediaPlayerObject = (UnityEngine.Object.Instantiate(Resources.Load("SceneVRCommunication\\Tablet\\Media Outputer (Music And Movie)")) as GameObject);
  527. }
  528. GameObject[] array = GameObject.FindGameObjectsWithTag("MediaPlayerObj");
  529. for (int l = 0; l < array.Length; l++)
  530. {
  531. if (<CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer != null && <CreateMediaInfoButton>c__AnonStoreyA.m_MovieOutputer != null)
  532. {
  533. break;
  534. }
  535. if (<CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer == null)
  536. {
  537. <CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer = array[l].GetComponent<MediaPlayer>();
  538. }
  539. if (<CreateMediaInfoButton>c__AnonStoreyA.m_MovieOutputer == null)
  540. {
  541. <CreateMediaInfoButton>c__AnonStoreyA.m_MovieOutputer = array[l].GetComponent<ApplyToMaterial>();
  542. }
  543. }
  544. }
  545. GameMain.Instance.SoundMgr.StopBGM(0.5f);
  546. <CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer.CloseVideo();
  547. <CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, mediaPath, true);
  548. if (element.imageThumbnail)
  549. {
  550. <CreateMediaInfoButton>c__AnonStoreyA.m_MovieOutputer.GetComponent<MeshRenderer>().enabled = true;
  551. }
  552. string text3 = "*鑑賞_";
  553. if (element.faceIndex == 0)
  554. {
  555. text3 += "喜び";
  556. }
  557. else if (element.faceIndex == 1)
  558. {
  559. text3 += "怒り";
  560. }
  561. else if (element.faceIndex == 2)
  562. {
  563. text3 += "哀しみ";
  564. }
  565. else if (element.faceIndex == 3)
  566. {
  567. text3 += "楽しい";
  568. }
  569. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  570. GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(((!(maid == null)) ? ScriptManager.ReplacePersonal(maid, "?_movieface_main") : "?_movieface_main.ks") + ".ks", text3);
  571. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  572. });
  573. if (element.imageThumbnail)
  574. {
  575. Texture2D texture2D = new Texture2D(info.GetVideoWidth(), info.GetVideoHeight(), TextureFormat.ARGB32, false);
  576. this.m_MediaPlayer.ExtractFrame(texture2D, 0.5f, false, 50);
  577. if (texture2D)
  578. {
  579. Rect rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
  580. element.imageThumbnail.sprite = Sprite.Create(texture2D, rect, Vector2.zero, 100f, 0U, SpriteMeshType.FullRect);
  581. }
  582. }
  583. float num2 = info.GetDurationMs();
  584. num2 *= 0.001f;
  585. string text2 = "再生時間 " + Mathf.Floor(num2 / 60f).ToString("00") + ":" + Mathf.Repeat(num2, 60f).ToString("00");
  586. element.textContentTime.text = text2;
  587. VRExternalFileLoader.m_IsEndLoad = true;
  588. VRExternalFileLoader.m_LoadingCount--;
  589. this.m_MediaPlayer.CloseVideo();
  590. this.m_MovieOutputer.enabled = true;
  591. data = element;
  592. }));
  593. return data;
  594. }
  595. public void CreateMediaInfoButton3(GameObject buttonPrefab, string buttonName, string mediaPath, string thumbnailPath, int faceIndex, MediaPlayerEvent.EventType successType)
  596. {
  597. base.StartCoroutine(this.Coroutine_GetMovieInfo(mediaPath, successType, delegate(bool isSuccess, IMediaInfo info)
  598. {
  599. if (!isSuccess)
  600. {
  601. return;
  602. }
  603. Transform transform = null;
  604. for (int i = 0; i < this.m_UIContent.childCount; i++)
  605. {
  606. if (!this.m_UIContent.GetChild(i).gameObject.activeSelf)
  607. {
  608. transform = this.m_UIContent.GetChild(i);
  609. break;
  610. }
  611. }
  612. if (transform == null)
  613. {
  614. transform = UnityEngine.Object.Instantiate<GameObject>(buttonPrefab).transform;
  615. }
  616. transform.gameObject.SetActive(true);
  617. UIButtonElement element = transform.GetComponent<UIButtonElement>();
  618. transform.SetParent(this.m_UIContent, false);
  619. int num = 0;
  620. for (int j = 0; j < this.m_UIContent.childCount; j++)
  621. {
  622. if (this.m_UIContent.GetChild(j).gameObject.activeSelf)
  623. {
  624. num++;
  625. }
  626. }
  627. element.textContentNumber.text = num.ToString("000");
  628. element.textContentName.text = buttonName;
  629. element.ButtonEvent_ChangeFaceType(faceIndex);
  630. for (int k = 0; k < element.buttonFaces.Length; k++)
  631. {
  632. element.buttonFaces[k].GetComponent<Graphic>().raycastTarget = false;
  633. if (k != faceIndex)
  634. {
  635. element.buttonFaces[k].gameObject.SetActive(false);
  636. }
  637. }
  638. element.buttonStart.onClick.RemoveAllListeners();
  639. element.buttonStart.onClick.AddListener(delegate()
  640. {
  641. if (VRExternalFileLoader.m_LoadingCount > 0)
  642. {
  643. return;
  644. }
  645. if (!File.Exists(mediaPath))
  646. {
  647. return;
  648. }
  649. if (<CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer == null)
  650. {
  651. if (VRExternalFileLoader.m_PtrMediaPlayerObject == null)
  652. {
  653. VRExternalFileLoader.m_PtrMediaPlayerObject = (UnityEngine.Object.Instantiate(Resources.Load("SceneVRCommunication\\Tablet\\Media Outputer (Music And Movie)")) as GameObject);
  654. }
  655. GameObject[] array = GameObject.FindGameObjectsWithTag("MediaPlayerObj");
  656. for (int l = 0; l < array.Length; l++)
  657. {
  658. if (<CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer != null && <CreateMediaInfoButton3>c__AnonStoreyC.m_MovieOutputer != null)
  659. {
  660. break;
  661. }
  662. if (<CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer == null)
  663. {
  664. <CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer = array[l].GetComponent<MediaPlayer>();
  665. }
  666. if (<CreateMediaInfoButton3>c__AnonStoreyC.m_MovieOutputer == null)
  667. {
  668. <CreateMediaInfoButton3>c__AnonStoreyC.m_MovieOutputer = array[l].GetComponent<ApplyToMaterial>();
  669. }
  670. }
  671. }
  672. GameMain.Instance.SoundMgr.StopBGM(0.5f);
  673. <CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer.CloseVideo();
  674. <CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, mediaPath, true);
  675. if (element.imageThumbnail)
  676. {
  677. <CreateMediaInfoButton3>c__AnonStoreyC.m_MovieOutputer.GetComponent<MeshRenderer>().enabled = true;
  678. }
  679. string text2 = "*鑑賞_";
  680. if (element.faceIndex == 0)
  681. {
  682. text2 += "喜び";
  683. }
  684. else if (element.faceIndex == 1)
  685. {
  686. text2 += "怒り";
  687. }
  688. else if (element.faceIndex == 2)
  689. {
  690. text2 += "哀しみ";
  691. }
  692. else if (element.faceIndex == 3)
  693. {
  694. text2 += "楽しい";
  695. }
  696. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  697. GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(((!(maid == null)) ? ScriptManager.ReplacePersonal(maid, "?_movieface_main") : "?_movieface_main.ks") + ".ks", text2);
  698. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  699. });
  700. if (element.imageThumbnail)
  701. {
  702. this.StartCoroutine(this.Coroutine_Load<Sprite>("SceneVRCommunication/Tablet/Sprite/" + thumbnailPath, delegate(ResourceRequest req)
  703. {
  704. element.imageThumbnail.sprite = (req.asset as Sprite);
  705. }));
  706. }
  707. float num2 = info.GetDurationMs();
  708. num2 *= 0.001f;
  709. string text = "再生時間 " + Mathf.Floor(num2 / 60f).ToString("00") + ":" + Mathf.Repeat(num2, 60f).ToString("00");
  710. element.textContentTime.text = text;
  711. VRExternalFileLoader.m_IsEndLoad = true;
  712. VRExternalFileLoader.m_LoadingCount--;
  713. this.m_MediaPlayer.CloseVideo();
  714. this.m_MovieOutputer.enabled = true;
  715. }));
  716. }
  717. public UIButtonElement CreateMediaInfoButton2(GameObject buttonPrefab, string buttonName, string mediaName, int faceIndex)
  718. {
  719. Transform transform = null;
  720. for (int i = 0; i < this.m_UIContent.childCount; i++)
  721. {
  722. if (!this.m_UIContent.GetChild(i).gameObject.activeSelf)
  723. {
  724. transform = this.m_UIContent.GetChild(i);
  725. break;
  726. }
  727. }
  728. if (transform == null)
  729. {
  730. transform = UnityEngine.Object.Instantiate<GameObject>(buttonPrefab).transform;
  731. }
  732. transform.gameObject.SetActive(true);
  733. UIButtonElement element = transform.GetComponent<UIButtonElement>();
  734. int num = 0;
  735. for (int j = 0; j < this.m_UIContent.childCount; j++)
  736. {
  737. if (this.m_UIContent.GetChild(j).gameObject.activeSelf)
  738. {
  739. num++;
  740. }
  741. }
  742. element.textContentNumber.text = num.ToString("000");
  743. element.textContentName.text = buttonName;
  744. Button buttonStart = element.buttonStart;
  745. if (buttonStart)
  746. {
  747. buttonStart.onClick.RemoveAllListeners();
  748. buttonStart.onClick.AddListener(delegate()
  749. {
  750. if (this.m_MovieOutputer)
  751. {
  752. this.m_MovieOutputer.GetComponent<MeshRenderer>().enabled = false;
  753. }
  754. this.m_MediaPlayer.CloseVideo();
  755. GameMain.Instance.SoundMgr.PlayBGM(mediaName, 0f, true);
  756. string text = "*鑑賞_";
  757. if (element.faceIndex == 0)
  758. {
  759. text += "喜び";
  760. }
  761. else if (element.faceIndex == 1)
  762. {
  763. text += "怒り";
  764. }
  765. else if (element.faceIndex == 2)
  766. {
  767. text += "哀しみ";
  768. }
  769. else if (element.faceIndex == 3)
  770. {
  771. text += "楽しい";
  772. }
  773. Debug.Log("外部スクリプト名:?_movieface_main.ks\nラベル文字列:" + text);
  774. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  775. GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(((!(maid == null)) ? ScriptManager.ReplacePersonal(maid, "?_movieface_main") : "?_movieface_main.ks") + ".ks", text);
  776. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  777. });
  778. }
  779. element.ButtonEvent_ChangeFaceType(faceIndex);
  780. for (int k = 0; k < element.buttonFaces.Length; k++)
  781. {
  782. element.buttonFaces[k].GetComponent<Graphic>().raycastTarget = true;
  783. element.buttonFaces[k].gameObject.SetActive(true);
  784. }
  785. transform.SetParent(this.m_UIContent, false);
  786. return element;
  787. }
  788. private void GetBGMName(int id, ref string BGMTitle, ref string BGMFileName)
  789. {
  790. string text = "phot_sound_list.nei";
  791. if (!GameUty.FileSystem.IsExistentFile(text))
  792. {
  793. NDebug.Assert("表がありません。" + text, false);
  794. }
  795. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  796. {
  797. using (CsvParser csvParser = new CsvParser())
  798. {
  799. bool condition = csvParser.Open(afileBase);
  800. NDebug.Assert(condition, text + "\nopen failed.");
  801. for (int i = 1; i < csvParser.max_cell_y; i++)
  802. {
  803. if (csvParser.IsCellToExistData(0, i))
  804. {
  805. if (csvParser.GetCellAsInteger(0, i) == id)
  806. {
  807. BGMTitle = csvParser.GetCellAsString(1, i);
  808. BGMFileName = csvParser.GetCellAsString(2, i);
  809. break;
  810. }
  811. }
  812. }
  813. }
  814. }
  815. }
  816. private void SaveAndPlay(string MediaName, UnityAction callback)
  817. {
  818. string mediaFilePath = this.m_MediaFilePath;
  819. if (GameUty.FileSystem.IsExistentFile(MediaName))
  820. {
  821. using (AFileBase afileBase = GameUty.FileOpen(MediaName, null))
  822. {
  823. if (afileBase != null && afileBase.IsValid())
  824. {
  825. byte[] bytes = afileBase.ReadAll();
  826. File.WriteAllBytes(mediaFilePath + "\\b.bgm", bytes);
  827. callback();
  828. }
  829. }
  830. }
  831. }
  832. public static void Event_PlayMovie(string movieName)
  833. {
  834. if (VRExternalFileLoader.m_PtrMediaPlayerObject == null)
  835. {
  836. VRExternalFileLoader.m_PtrMediaPlayerObject = (UnityEngine.Object.Instantiate(Resources.Load("SceneVRCommunication\\Tablet\\Media Outputer (Music And Movie)")) as GameObject);
  837. }
  838. GameObject[] array = GameObject.FindGameObjectsWithTag("MediaPlayerObj");
  839. MediaPlayer mediaPlayer = null;
  840. ApplyToMaterial applyToMaterial = null;
  841. for (int i = 0; i < array.Length; i++)
  842. {
  843. if (mediaPlayer != null && applyToMaterial != null)
  844. {
  845. break;
  846. }
  847. if (mediaPlayer == null)
  848. {
  849. mediaPlayer = array[i].GetComponent<MediaPlayer>();
  850. }
  851. if (applyToMaterial == null)
  852. {
  853. applyToMaterial = array[i].GetComponent<ApplyToMaterial>();
  854. }
  855. }
  856. if (mediaPlayer == null)
  857. {
  858. Debug.LogError("[VR動画再生]\u3000MediaPlayer を持ったオブジェクトが見つかりません。");
  859. return;
  860. }
  861. if (applyToMaterial == null)
  862. {
  863. Debug.LogError("[VR動画再生]\u3000ApplyToMaterial を持ったオブジェクトが見つかりません。");
  864. return;
  865. }
  866. mediaPlayer.CloseVideo();
  867. applyToMaterial.GetComponent<MeshRenderer>().enabled = true;
  868. string path = UTY.gameProjectPath + "\\GameData/movie_vrcom/" + Path.ChangeExtension(movieName, ".ine");
  869. NDebug.Assert(File.Exists(path), "動画「" + movieName + "」が見つかりません");
  870. mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, path, true);
  871. }
  872. public static void Event_CloseMovie()
  873. {
  874. GameObject[] array = GameObject.FindGameObjectsWithTag("MediaPlayerObj");
  875. for (int i = 0; i < array.Length; i++)
  876. {
  877. ApplyToMaterial component = array[i].GetComponent<ApplyToMaterial>();
  878. if (component)
  879. {
  880. MeshRenderer component2 = component.GetComponent<MeshRenderer>();
  881. if (component2)
  882. {
  883. component2.enabled = false;
  884. }
  885. }
  886. MediaPlayer component3 = array[i].GetComponent<MediaPlayer>();
  887. if (component3)
  888. {
  889. component3.CloseVideo();
  890. }
  891. }
  892. if (VRExternalFileLoader.m_PtrMediaPlayerObject)
  893. {
  894. UnityEngine.Object.Destroy(VRExternalFileLoader.m_PtrMediaPlayerObject);
  895. }
  896. }
  897. public static void Event_OpenSelect()
  898. {
  899. VRCanvasManager.Instance.ClearCanvasStack();
  900. VRDialogMenu vrdialogMenu = VRDialogMenu.CreateDialog();
  901. List<VRDialogMenu.DialogButton> list = new List<VRDialogMenu.DialogButton>();
  902. list.Add(new VRDialogMenu.DialogButton(true, "vr_dialog_cd", delegate()
  903. {
  904. VRExternalFileLoader.m_MediaNowType = VRExternalFileLoader.TYPE_MEDIA.Music;
  905. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MusicPlayer);
  906. }, new Vector3(250f, -270f, 0f), new Vector2(300f, 300f)));
  907. list.Add(new VRDialogMenu.DialogButton(true, "vr_dialog_tv", delegate()
  908. {
  909. VRExternalFileLoader.m_MediaNowType = VRExternalFileLoader.TYPE_MEDIA.Movie;
  910. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MoviePlayer);
  911. }, new Vector3(-250f, -270f, 0f), new Vector2(300f, 300f)));
  912. list.Add(new VRDialogMenu.DialogButton(true, "vr_bottom_system_return", delegate()
  913. {
  914. string label_name = "*鑑賞_終了";
  915. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  916. GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(((!(maid == null)) ? ScriptManager.ReplacePersonal(maid, "?_movieface_main") : "?_movieface_main.ks") + ".ks", label_name);
  917. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  918. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
  919. }, new Vector3(-778f, -365f, 0f), new Vector2(200f, 200f)));
  920. vrdialogMenu.OpenDialog("再生機器を選んでください。", list.ToArray());
  921. if (SceneVRCommunication.Instance.GetNowTime() == SceneVRCommunication.VR_TIME.NIGHT)
  922. {
  923. GameMain.Instance.SoundMgr.PlayBGM("BGM_vr0001.ogg", 1f, true);
  924. }
  925. else
  926. {
  927. GameMain.Instance.SoundMgr.PlayBGM("BGM007.ogg", 1f, true);
  928. }
  929. }
  930. public void ScrollEvent_ContentScroll(Vector2 normalizedPos)
  931. {
  932. this.m_SliderBar.value = normalizedPos.y;
  933. }
  934. public void ButtonEvent_CloseVideo()
  935. {
  936. if (this.m_MovieOutputer)
  937. {
  938. this.m_MovieOutputer.GetComponent<MeshRenderer>().enabled = false;
  939. }
  940. if (this.m_MediaPlayer)
  941. {
  942. this.m_MediaPlayer.CloseVideo();
  943. }
  944. GameMain.Instance.SoundMgr.StopBGM(0f);
  945. }
  946. public void ButtonEvent_CloseCanvas()
  947. {
  948. base.StopAllCoroutines();
  949. UICanvasFade component = base.GetComponent<UICanvasFade>();
  950. if (component)
  951. {
  952. component.FadeOut();
  953. }
  954. if (VRExternalFileLoader.m_PtrMediaPlayerObject)
  955. {
  956. UnityEngine.Object.Destroy(VRExternalFileLoader.m_PtrMediaPlayerObject);
  957. }
  958. VRExternalFileLoader.Event_OpenSelect();
  959. }
  960. private void OnEnable()
  961. {
  962. if (VRExternalFileLoader.m_MediaNowType != this.m_TypeMedia)
  963. {
  964. return;
  965. }
  966. base.StartCoroutine(this.Coroutine_Refresh());
  967. }
  968. private void OnDisable()
  969. {
  970. for (int i = 0; i < this.m_UIContent.childCount; i++)
  971. {
  972. UnityEngine.Object.Destroy(this.m_UIContent.GetChild(i).gameObject);
  973. }
  974. }
  975. private IEnumerator Coroutine_Load<T>(string path, UnityAction<ResourceRequest> callback) where T : UnityEngine.Object
  976. {
  977. ResourceRequest res = Resources.LoadAsync<T>(path);
  978. while (!res.isDone)
  979. {
  980. yield return null;
  981. }
  982. callback(res);
  983. yield break;
  984. }
  985. [SerializeField]
  986. private RectTransform m_UIContent;
  987. [SerializeField]
  988. private Slider m_SliderBar;
  989. [SerializeField]
  990. private RectTransform m_UIPrefabMovieButton;
  991. [SerializeField]
  992. private RectTransform m_UIPrefabMusicButton;
  993. [SerializeField]
  994. private MediaPlayer m_MediaPlayer;
  995. [SerializeField]
  996. private ApplyToMaterial m_MovieOutputer;
  997. [SerializeField]
  998. [Tooltip("外部ファイルへのパス。「~/Movie/」など、\nファイルが置いてあるパスを指定する。")]
  999. private string m_MediaFilePath;
  1000. [SerializeField]
  1001. [Space(16f)]
  1002. private VRExternalFileLoader.TYPE_MEDIA m_TypeMedia;
  1003. public static GameObject m_PtrMediaPlayerObject;
  1004. private bool m_BeforeFreeMode;
  1005. private static bool m_IsEndLoad = true;
  1006. private static int m_LoadingCount;
  1007. private static VRExternalFileLoader.TYPE_MEDIA m_MediaNowType = VRExternalFileLoader.TYPE_MEDIA.Movie;
  1008. private enum TYPE_MEDIA
  1009. {
  1010. Music,
  1011. Movie
  1012. }
  1013. }