12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using RenderHeads.Media.AVProVideo;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.UI;
- public class VRExternalFileLoader : MonoBehaviour
- {
- private void Update()
- {
- if (SceneVRCommunication.Instance == null)
- {
- return;
- }
- bool isFreeMode = SceneVRCommunication.Instance.IsFreeMode;
- if (!isFreeMode && this.m_BeforeFreeMode)
- {
- VRExternalFileLoader.Event_CloseMovie();
- if (SceneVRCommunication.Instance.GetNowTime() == SceneVRCommunication.VR_TIME.NIGHT)
- {
- GameMain.Instance.SoundMgr.PlayBGM("BGM_vr0001.ogg", 1f, true);
- }
- else
- {
- GameMain.Instance.SoundMgr.PlayBGM("BGM007.ogg", 1f, true);
- }
- }
- this.m_BeforeFreeMode = isFreeMode;
- }
- public void LoadAllMovieFile(string dataPath, params string[] extensions)
- {
- this.m_MediaPlayer.m_VideoPath = dataPath;
- DirectoryInfo directoryInfo = new DirectoryInfo(dataPath);
- if (!directoryInfo.Exists)
- {
- Directory.CreateDirectory(dataPath);
- }
- foreach (string searchPattern in extensions)
- {
- FileInfo[] files = directoryInfo.GetFiles(searchPattern);
- foreach (FileInfo fileInfo in files)
- {
- this.CreateMediaInfoButton(this.m_UIPrefabMovieButton.gameObject, fileInfo.Name, fileInfo.FullName, 0, MediaPlayerEvent.EventType.FirstFrameReady);
- VRExternalFileLoader.m_LoadingCount++;
- }
- }
- }
- public void LoadAllMusicFile(string dataPath, params string[] extensions)
- {
- this.m_MediaPlayer.m_VideoPath = dataPath;
- DirectoryInfo directoryInfo = new DirectoryInfo(dataPath);
- if (!directoryInfo.Exists)
- {
- Directory.CreateDirectory(dataPath);
- }
- foreach (string searchPattern in extensions)
- {
- FileInfo[] files = directoryInfo.GetFiles(searchPattern);
- foreach (FileInfo fileInfo in files)
- {
- this.CreateMediaInfoButton(this.m_UIPrefabMusicButton.gameObject, fileInfo.Name, fileInfo.FullName, 0, MediaPlayerEvent.EventType.ReadyToPlay);
- VRExternalFileLoader.m_LoadingCount++;
- }
- }
- }
- private IEnumerator Coroutine_GetMovieThumbnail(UIButtonElement element, string moviePath, GameObject elementObject)
- {
- while (!VRExternalFileLoader.m_IsEndLoad)
- {
- yield return null;
- }
- VRExternalFileLoader.m_IsEndLoad = false;
- if (this.m_MovieOutputer)
- {
- this.m_MovieOutputer.enabled = false;
- }
- if (!File.Exists(moviePath))
- {
- VRExternalFileLoader.m_IsEndLoad = true;
- VRExternalFileLoader.m_LoadingCount--;
- this.m_MediaPlayer.CloseVideo();
- this.m_MovieOutputer.enabled = true;
- yield break;
- }
- this.m_MediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, moviePath, false);
- int isOpenReady = 1;
- this.m_MediaPlayer.Events.AddListener(delegate(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
- {
- if (et != MediaPlayerEvent.EventType.Error)
- {
- if (et == MediaPlayerEvent.EventType.FirstFrameReady)
- {
- isOpenReady = 0;
- }
- }
- else
- {
- isOpenReady = -1;
- }
- });
- while (isOpenReady == 1)
- {
- yield return null;
- }
- if (isOpenReady == -1)
- {
- UnityEngine.Object.Destroy(elementObject);
- yield return null;
- VRExternalFileLoader.m_IsEndLoad = true;
- VRExternalFileLoader.m_LoadingCount--;
- this.m_MediaPlayer.CloseVideo();
- this.m_MovieOutputer.enabled = true;
- yield break;
- }
- IMediaInfo info = this.m_MediaPlayer.Info;
- Texture2D tex2D = new Texture2D(info.GetVideoWidth(), info.GetVideoHeight(), TextureFormat.ARGB32, false);
- this.m_MediaPlayer.ExtractFrame(tex2D, 0.5f, false, 50);
- if (tex2D)
- {
- Rect rect = new Rect(0f, 0f, (float)tex2D.width, (float)tex2D.height);
- element.imageThumbnail.sprite = Sprite.Create(tex2D, rect, Vector2.zero, 100f, 0u, SpriteMeshType.FullRect);
- }
- yield return null;
- float tim = info.GetDurationMs();
- tim *= 0.001f;
- string str = "再生時間 " + Mathf.Floor(tim / 60f).ToString("00") + ":" + Mathf.Repeat(tim, 60f).ToString("00");
- element.textContentTime.text = str;
- VRExternalFileLoader.m_IsEndLoad = true;
- VRExternalFileLoader.m_LoadingCount--;
- this.m_MediaPlayer.CloseVideo();
- this.m_MovieOutputer.enabled = true;
- yield break;
- }
- private IEnumerator Coroutine_GetMovieInfo(string moviePath, MediaPlayerEvent.EventType successType, UnityAction<bool, IMediaInfo> callback)
- {
- while (!VRExternalFileLoader.m_IsEndLoad)
- {
- yield return null;
- }
- VRExternalFileLoader.m_IsEndLoad = false;
- if (this.m_MovieOutputer)
- {
- this.m_MovieOutputer.enabled = false;
- }
- if (!File.Exists(moviePath))
- {
- VRExternalFileLoader.m_IsEndLoad = true;
- VRExternalFileLoader.m_LoadingCount--;
- this.m_MediaPlayer.CloseVideo();
- this.m_MovieOutputer.enabled = true;
- callback(false, null);
- yield break;
- }
- this.m_MediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, moviePath, false);
- int isOpenReady = 1;
- this.m_MediaPlayer.Events.AddListener(delegate(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
- {
- if (et == MediaPlayerEvent.EventType.Error)
- {
- isOpenReady = -1;
- }
- else if (et == successType)
- {
- isOpenReady = 0;
- }
- });
- while (isOpenReady == 1)
- {
- yield return null;
- }
- if (isOpenReady == -1)
- {
- VRExternalFileLoader.m_IsEndLoad = true;
- VRExternalFileLoader.m_LoadingCount--;
- this.m_MediaPlayer.CloseVideo();
- this.m_MovieOutputer.enabled = true;
- callback(false, null);
- yield break;
- }
- IMediaInfo info = this.m_MediaPlayer.Info;
- callback(true, info);
- yield break;
- }
- private IEnumerator Coroutine_GetMusicPlaybackTime(UIButtonElement element, string musicPath)
- {
- while (!VRExternalFileLoader.m_IsEndLoad)
- {
- yield return null;
- }
- VRExternalFileLoader.m_IsEndLoad = false;
- this.m_MediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, musicPath, false);
- bool isOpenReady = false;
- this.m_MediaPlayer.Events.AddListener(delegate(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
- {
- if (et == MediaPlayerEvent.EventType.ReadyToPlay)
- {
- isOpenReady = true;
- }
- });
- while (!isOpenReady)
- {
- yield return null;
- }
- IMediaInfo info = this.m_MediaPlayer.Info;
- float tim = info.GetDurationMs();
- tim *= 0.001f;
- for (int i = 0; i < 3; i++)
- {
- yield return null;
- }
- string str = "再生時間 " + Mathf.Floor(tim / 60f).ToString("00") + ":" + Mathf.Repeat(tim, 60f).ToString("00");
- element.textContentTime.text = str;
- VRExternalFileLoader.m_IsEndLoad = true;
- VRExternalFileLoader.m_LoadingCount--;
- this.m_MediaPlayer.CloseVideo();
- yield break;
- }
- private IEnumerator Coroutine_LoadMovieAsset(string LocalFilePath, string FileName, string AssetBundleURL)
- {
- string FullPath = LocalFilePath + FileName;
- if (File.Exists(FullPath))
- {
- yield break;
- }
- WWW www = new WWW(AssetBundleURL);
- yield return www;
- AssetBundle assetbundle = www.assetBundle;
- AssetBundleRequest resultObject = assetbundle.LoadAssetAsync<TextAsset>(FileName);
- yield return new WaitWhile(() => !resultObject.isDone);
- TextAsset movie = resultObject.asset as TextAsset;
- byte[] byteData = movie.bytes;
- File.WriteAllBytes(FullPath, byteData);
- assetbundle.Unload(false);
- yield break;
- }
- private IEnumerator Coroutine_Refresh()
- {
- VRExternalFileLoader.m_LoadingCount = 0;
- VRExternalFileLoader.m_IsEndLoad = true;
- this.m_MediaFilePath = Path.GetFullPath(".\\");
- if (VRExternalFileLoader.m_PtrMediaPlayerObject == null)
- {
- VRExternalFileLoader.m_PtrMediaPlayerObject = (UnityEngine.Object.Instantiate(Resources.Load("SceneVRCommunication\\Tablet\\Media Outputer (Music And Movie)")) as GameObject);
- }
- GameObject[] MediaPlayers = GameObject.FindGameObjectsWithTag("MediaPlayerObj");
- for (int i = 0; i < MediaPlayers.Length; i++)
- {
- if (this.m_MediaPlayer != null && this.m_MovieOutputer != null)
- {
- break;
- }
- if (this.m_MediaPlayer == null)
- {
- this.m_MediaPlayer = MediaPlayers[i].GetComponent<MediaPlayer>();
- }
- if (this.m_MovieOutputer == null)
- {
- this.m_MovieOutputer = MediaPlayers[i].GetComponent<ApplyToMaterial>();
- }
- }
- this.m_MediaPlayer.m_AutoOpen = false;
- this.m_MediaPlayer.m_AutoStart = false;
- this.m_MovieOutputer.GetComponent<MeshRenderer>().enabled = false;
- this.m_UIContent.anchoredPosition = Vector2.zero;
- for (int j = 0; j < this.m_UIContent.childCount; j++)
- {
- this.m_UIContent.GetChild(j).gameObject.SetActive(false);
- }
- if (this.m_TypeMedia == VRExternalFileLoader.TYPE_MEDIA.Movie)
- {
- string fileName = "vrcom_movie.nei";
- if (!GameUty.FileSystem.IsExistentFile(fileName))
- {
- NDebug.Assert("表がありません。" + fileName, false);
- }
- using (AFileBase file = GameUty.FileSystem.FileOpen(fileName))
- {
- using (CsvParser csv = new CsvParser())
- {
- bool result = csv.Open(file);
- NDebug.Assert(result, fileName + "\nopen failed.");
- for (int y = 1; y < csv.max_cell_y; y++)
- {
- if (csv.IsCellToExistData(0, y))
- {
- int x = 0;
- ACsvParser acsvParser = csv;
- int cell_x;
- x = (cell_x = x) + 1;
- int id = acsvParser.GetCellAsInteger(cell_x, y);
- ACsvParser acsvParser2 = csv;
- x = (cell_x = x) + 1;
- string thumbnailPath = acsvParser2.GetCellAsString(cell_x, y);
- ACsvParser acsvParser3 = csv;
- x = (cell_x = x) + 1;
- string movieName = acsvParser3.GetCellAsString(cell_x, y);
- ACsvParser acsvParser4 = csv;
- x = (cell_x = x) + 1;
- string movieTitle = acsvParser4.GetCellAsString(cell_x, y);
- ACsvParser acsvParser5 = csv;
- x = (cell_x = x) + 1;
- string getFlag = acsvParser5.GetCellAsString(cell_x, y);
- ACsvParser acsvParser6 = csv;
- x = (cell_x = x) + 1;
- string defaultFace = acsvParser6.GetCellAsString(cell_x, y);
- ACsvParser acsvParser7 = csv;
- x = (cell_x = x) + 1;
- string faceEvent = acsvParser7.GetCellAsString(cell_x, y);
- ACsvParser acsvParser8 = csv;
- x = (cell_x = x) + 1;
- string faceEvent2 = acsvParser8.GetCellAsString(cell_x, y);
- ACsvParser acsvParser9 = csv;
- x = (cell_x = x) + 1;
- string faceEvent3 = acsvParser9.GetCellAsString(cell_x, y);
- ACsvParser acsvParser10 = csv;
- x = (cell_x = x) + 1;
- string faceEvent4 = acsvParser10.GetCellAsString(cell_x, y);
- ACsvParser acsvParser11 = csv;
- x = (cell_x = x) + 1;
- string endEvent = acsvParser11.GetCellAsString(cell_x, y);
- int flag = 0;
- if (GameMain.Instance.CharacterMgr.GetMaid(0) != null)
- {
- flag = GameMain.Instance.CharacterMgr.GetMaid(0).status.GetFlag(getFlag);
- }
- if (flag == 1)
- {
- int faceIndex = 0;
- if (!string.IsNullOrEmpty(defaultFace))
- {
- if (defaultFace == "鑑賞_喜び")
- {
- faceIndex = 0;
- }
- else if (defaultFace == "鑑賞_怒り")
- {
- faceIndex = 1;
- }
- else if (defaultFace == "鑑賞_哀しみ")
- {
- faceIndex = 2;
- }
- else if (defaultFace == "鑑賞_楽しい")
- {
- faceIndex = 3;
- }
- }
- this.CreateMediaInfoButton3(this.m_UIPrefabMovieButton.gameObject, movieTitle, this.m_MediaFilePath + "GameData/movie_vrcom/" + movieName + ".ine", thumbnailPath, faceIndex, MediaPlayerEvent.EventType.FirstFrameReady);
- yield return null;
- }
- }
- }
- }
- }
- this.LoadAllMovieFile(this.m_MediaFilePath + "movie_vrcom/", new string[]
- {
- "*.mp4",
- "*.mov",
- "*.avi"
- });
- }
- else if (this.m_TypeMedia == VRExternalFileLoader.TYPE_MEDIA.Music)
- {
- string fileName2 = "vrcom_music.nei";
- if (!GameUty.FileSystem.IsExistentFile(fileName2))
- {
- NDebug.Assert("表がありません。" + fileName2, false);
- }
- using (AFileBase file2 = GameUty.FileSystem.FileOpen(fileName2))
- {
- using (CsvParser csv2 = new CsvParser())
- {
- bool result2 = csv2.Open(file2);
- NDebug.Assert(result2, fileName2 + "\nopen failed.");
- for (int y2 = 1; y2 < csv2.max_cell_y; y2++)
- {
- if (csv2.IsCellToExistData(0, y2))
- {
- int x2 = 0;
- ACsvParser acsvParser12 = csv2;
- int cell_x;
- x2 = (cell_x = x2) + 1;
- int id2 = acsvParser12.GetCellAsInteger(cell_x, y2);
- ACsvParser acsvParser13 = csv2;
- x2 = (cell_x = x2) + 1;
- string defaultFace2 = acsvParser13.GetCellAsString(cell_x, y2);
- ACsvParser acsvParser14 = csv2;
- x2 = (cell_x = x2) + 1;
- string faceEvent5 = acsvParser14.GetCellAsString(cell_x, y2);
- ACsvParser acsvParser15 = csv2;
- x2 = (cell_x = x2) + 1;
- string faceEvent6 = acsvParser15.GetCellAsString(cell_x, y2);
- ACsvParser acsvParser16 = csv2;
- x2 = (cell_x = x2) + 1;
- string faceEvent7 = acsvParser16.GetCellAsString(cell_x, y2);
- ACsvParser acsvParser17 = csv2;
- x2 = (cell_x = x2) + 1;
- string faceEvent8 = acsvParser17.GetCellAsString(cell_x, y2);
- ACsvParser acsvParser18 = csv2;
- x2 = (cell_x = x2) + 1;
- string endEvent2 = acsvParser18.GetCellAsString(cell_x, y2);
- string musicTitle = "none";
- string musicName = "none.ogg";
- this.GetBGMName(id2, ref musicTitle, ref musicName);
- if (GameUty.FileSystem.IsExistentFile(musicName))
- {
- int faceIndex2 = 0;
- if (!string.IsNullOrEmpty(defaultFace2))
- {
- if (defaultFace2 == "鑑賞_喜び")
- {
- faceIndex2 = 0;
- }
- else if (defaultFace2 == "鑑賞_怒り")
- {
- faceIndex2 = 1;
- }
- else if (defaultFace2 == "鑑賞_哀しみ")
- {
- faceIndex2 = 2;
- }
- else if (defaultFace2 == "鑑賞_楽しい")
- {
- faceIndex2 = 3;
- }
- }
- UIButtonElement element = this.CreateMediaInfoButton2(this.m_UIPrefabMusicButton.gameObject, musicTitle, musicName, faceIndex2);
- for (int k = 0; k < element.buttonFaces.Length; k++)
- {
- element.buttonFaces[k].GetComponent<Graphic>().raycastTarget = false;
- if (k != faceIndex2)
- {
- element.buttonFaces[k].gameObject.SetActive(false);
- }
- }
- yield return null;
- }
- }
- }
- }
- }
- this.LoadAllMusicFile(this.m_MediaFilePath + "music_vrcom/", new string[]
- {
- "*.wav",
- "*.mp3"
- });
- }
- Resources.UnloadUnusedAssets();
- yield break;
- }
- public UIButtonElement CreateMediaInfoButton(GameObject buttonPrefab, string buttonName, string mediaPath, int faceIndex, MediaPlayerEvent.EventType successType)
- {
- UIButtonElement data = null;
- base.StartCoroutine(this.Coroutine_GetMovieInfo(mediaPath, successType, delegate(bool isSuccess, IMediaInfo info)
- {
- if (!isSuccess)
- {
- return;
- }
- Transform transform = null;
- for (int i = 0; i < this.m_UIContent.childCount; i++)
- {
- if (!this.m_UIContent.GetChild(i).gameObject.activeSelf)
- {
- transform = this.m_UIContent.GetChild(i);
- break;
- }
- }
- if (transform == null)
- {
- transform = UnityEngine.Object.Instantiate<GameObject>(buttonPrefab).transform;
- }
- transform.gameObject.SetActive(true);
- UIButtonElement element = transform.GetComponent<UIButtonElement>();
- transform.SetParent(this.m_UIContent, false);
- int num = 0;
- for (int j = 0; j < this.m_UIContent.childCount; j++)
- {
- if (this.m_UIContent.GetChild(j).gameObject.activeSelf)
- {
- num++;
- }
- }
- element.textContentNumber.text = num.ToString("000");
- Text textContentName = element.textContentName;
- TextGenerator textGenerator = new TextGenerator();
- TextGenerationSettings generationSettings = textContentName.GetGenerationSettings(textContentName.rectTransform.rect.size);
- generationSettings.resizeTextMinSize = textContentName.resizeTextMinSize;
- generationSettings.resizeTextMaxSize = textContentName.resizeTextMaxSize;
- generationSettings.fontSize = textContentName.fontSize;
- generationSettings.font = textContentName.font;
- buttonName = buttonName.Replace(' ', '\u00a0');
- textGenerator.Populate(buttonName, generationSettings);
- int characterCountVisible = textGenerator.characterCountVisible;
- string text = buttonName;
- if (buttonName.Length > characterCountVisible && characterCountVisible > 3)
- {
- Debug.Log(characterCountVisible + "\n" + buttonName.Length);
- text = buttonName.Substring(0, characterCountVisible - 3);
- text += "...";
- }
- textContentName.text = text;
- element.ButtonEvent_ChangeFaceType(faceIndex);
- for (int k = 0; k < element.buttonFaces.Length; k++)
- {
- element.buttonFaces[k].GetComponent<Graphic>().raycastTarget = true;
- element.buttonFaces[k].gameObject.SetActive(true);
- }
- element.buttonStart.onClick.RemoveAllListeners();
- element.buttonStart.onClick.AddListener(delegate()
- {
- if (VRExternalFileLoader.m_LoadingCount > 0)
- {
- return;
- }
- if (!File.Exists(mediaPath))
- {
- return;
- }
- if (<CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer == null)
- {
- if (VRExternalFileLoader.m_PtrMediaPlayerObject == null)
- {
- VRExternalFileLoader.m_PtrMediaPlayerObject = (UnityEngine.Object.Instantiate(Resources.Load("SceneVRCommunication\\Tablet\\Media Outputer (Music And Movie)")) as GameObject);
- }
- GameObject[] array = GameObject.FindGameObjectsWithTag("MediaPlayerObj");
- for (int l = 0; l < array.Length; l++)
- {
- if (<CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer != null && <CreateMediaInfoButton>c__AnonStoreyA.m_MovieOutputer != null)
- {
- break;
- }
- if (<CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer == null)
- {
- <CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer = array[l].GetComponent<MediaPlayer>();
- }
- if (<CreateMediaInfoButton>c__AnonStoreyA.m_MovieOutputer == null)
- {
- <CreateMediaInfoButton>c__AnonStoreyA.m_MovieOutputer = array[l].GetComponent<ApplyToMaterial>();
- }
- }
- }
- GameMain.Instance.SoundMgr.StopBGM(0.5f);
- <CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer.CloseVideo();
- <CreateMediaInfoButton>c__AnonStoreyA.m_MediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, mediaPath, true);
- if (element.imageThumbnail)
- {
- <CreateMediaInfoButton>c__AnonStoreyA.m_MovieOutputer.GetComponent<MeshRenderer>().enabled = true;
- }
- string text3 = "*鑑賞_";
- if (element.faceIndex == 0)
- {
- text3 += "喜び";
- }
- else if (element.faceIndex == 1)
- {
- text3 += "怒り";
- }
- else if (element.faceIndex == 2)
- {
- text3 += "哀しみ";
- }
- else if (element.faceIndex == 3)
- {
- text3 += "楽しい";
- }
- Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
- GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(((!(maid == null)) ? ScriptManager.ReplacePersonal(maid, "?_movieface_main") : "?_movieface_main.ks") + ".ks", text3);
- GameMain.Instance.ScriptMgr.adv_kag.Exec();
- });
- if (element.imageThumbnail)
- {
- Texture2D texture2D = new Texture2D(info.GetVideoWidth(), info.GetVideoHeight(), TextureFormat.ARGB32, false);
- this.m_MediaPlayer.ExtractFrame(texture2D, 0.5f, false, 50);
- if (texture2D)
- {
- Rect rect = new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height);
- element.imageThumbnail.sprite = Sprite.Create(texture2D, rect, Vector2.zero, 100f, 0u, SpriteMeshType.FullRect);
- }
- }
- float num2 = info.GetDurationMs();
- num2 *= 0.001f;
- string text2 = "再生時間 " + Mathf.Floor(num2 / 60f).ToString("00") + ":" + Mathf.Repeat(num2, 60f).ToString("00");
- element.textContentTime.text = text2;
- VRExternalFileLoader.m_IsEndLoad = true;
- VRExternalFileLoader.m_LoadingCount--;
- this.m_MediaPlayer.CloseVideo();
- this.m_MovieOutputer.enabled = true;
- data = element;
- }));
- return data;
- }
- public void CreateMediaInfoButton3(GameObject buttonPrefab, string buttonName, string mediaPath, string thumbnailPath, int faceIndex, MediaPlayerEvent.EventType successType)
- {
- base.StartCoroutine(this.Coroutine_GetMovieInfo(mediaPath, successType, delegate(bool isSuccess, IMediaInfo info)
- {
- if (!isSuccess)
- {
- return;
- }
- Transform transform = null;
- for (int i = 0; i < this.m_UIContent.childCount; i++)
- {
- if (!this.m_UIContent.GetChild(i).gameObject.activeSelf)
- {
- transform = this.m_UIContent.GetChild(i);
- break;
- }
- }
- if (transform == null)
- {
- transform = UnityEngine.Object.Instantiate<GameObject>(buttonPrefab).transform;
- }
- transform.gameObject.SetActive(true);
- UIButtonElement element = transform.GetComponent<UIButtonElement>();
- transform.SetParent(this.m_UIContent, false);
- int num = 0;
- for (int j = 0; j < this.m_UIContent.childCount; j++)
- {
- if (this.m_UIContent.GetChild(j).gameObject.activeSelf)
- {
- num++;
- }
- }
- element.textContentNumber.text = num.ToString("000");
- element.textContentName.text = buttonName;
- element.ButtonEvent_ChangeFaceType(faceIndex);
- for (int k = 0; k < element.buttonFaces.Length; k++)
- {
- element.buttonFaces[k].GetComponent<Graphic>().raycastTarget = false;
- if (k != faceIndex)
- {
- element.buttonFaces[k].gameObject.SetActive(false);
- }
- }
- element.buttonStart.onClick.RemoveAllListeners();
- element.buttonStart.onClick.AddListener(delegate()
- {
- if (VRExternalFileLoader.m_LoadingCount > 0)
- {
- return;
- }
- if (!File.Exists(mediaPath))
- {
- return;
- }
- if (<CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer == null)
- {
- if (VRExternalFileLoader.m_PtrMediaPlayerObject == null)
- {
- VRExternalFileLoader.m_PtrMediaPlayerObject = (UnityEngine.Object.Instantiate(Resources.Load("SceneVRCommunication\\Tablet\\Media Outputer (Music And Movie)")) as GameObject);
- }
- GameObject[] array = GameObject.FindGameObjectsWithTag("MediaPlayerObj");
- for (int l = 0; l < array.Length; l++)
- {
- if (<CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer != null && <CreateMediaInfoButton3>c__AnonStoreyC.m_MovieOutputer != null)
- {
- break;
- }
- if (<CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer == null)
- {
- <CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer = array[l].GetComponent<MediaPlayer>();
- }
- if (<CreateMediaInfoButton3>c__AnonStoreyC.m_MovieOutputer == null)
- {
- <CreateMediaInfoButton3>c__AnonStoreyC.m_MovieOutputer = array[l].GetComponent<ApplyToMaterial>();
- }
- }
- }
- GameMain.Instance.SoundMgr.StopBGM(0.5f);
- <CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer.CloseVideo();
- <CreateMediaInfoButton3>c__AnonStoreyC.m_MediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, mediaPath, true);
- if (element.imageThumbnail)
- {
- <CreateMediaInfoButton3>c__AnonStoreyC.m_MovieOutputer.GetComponent<MeshRenderer>().enabled = true;
- }
- string text2 = "*鑑賞_";
- if (element.faceIndex == 0)
- {
- text2 += "喜び";
- }
- else if (element.faceIndex == 1)
- {
- text2 += "怒り";
- }
- else if (element.faceIndex == 2)
- {
- text2 += "哀しみ";
- }
- else if (element.faceIndex == 3)
- {
- text2 += "楽しい";
- }
- Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
- GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(((!(maid == null)) ? ScriptManager.ReplacePersonal(maid, "?_movieface_main") : "?_movieface_main.ks") + ".ks", text2);
- GameMain.Instance.ScriptMgr.adv_kag.Exec();
- });
- if (element.imageThumbnail)
- {
- this.StartCoroutine(this.Coroutine_Load<Sprite>("SceneVRCommunication/Tablet/Sprite/" + thumbnailPath, delegate(ResourceRequest req)
- {
- element.imageThumbnail.sprite = (req.asset as Sprite);
- }));
- }
- float num2 = info.GetDurationMs();
- num2 *= 0.001f;
- string text = "再生時間 " + Mathf.Floor(num2 / 60f).ToString("00") + ":" + Mathf.Repeat(num2, 60f).ToString("00");
- element.textContentTime.text = text;
- VRExternalFileLoader.m_IsEndLoad = true;
- VRExternalFileLoader.m_LoadingCount--;
- this.m_MediaPlayer.CloseVideo();
- this.m_MovieOutputer.enabled = true;
- }));
- }
- public UIButtonElement CreateMediaInfoButton2(GameObject buttonPrefab, string buttonName, string mediaName, int faceIndex)
- {
- Transform transform = null;
- for (int i = 0; i < this.m_UIContent.childCount; i++)
- {
- if (!this.m_UIContent.GetChild(i).gameObject.activeSelf)
- {
- transform = this.m_UIContent.GetChild(i);
- break;
- }
- }
- if (transform == null)
- {
- transform = UnityEngine.Object.Instantiate<GameObject>(buttonPrefab).transform;
- }
- transform.gameObject.SetActive(true);
- UIButtonElement element = transform.GetComponent<UIButtonElement>();
- int num = 0;
- for (int j = 0; j < this.m_UIContent.childCount; j++)
- {
- if (this.m_UIContent.GetChild(j).gameObject.activeSelf)
- {
- num++;
- }
- }
- element.textContentNumber.text = num.ToString("000");
- element.textContentName.text = buttonName;
- Button buttonStart = element.buttonStart;
- if (buttonStart)
- {
- buttonStart.onClick.RemoveAllListeners();
- buttonStart.onClick.AddListener(delegate()
- {
- if (this.m_MovieOutputer)
- {
- this.m_MovieOutputer.GetComponent<MeshRenderer>().enabled = false;
- }
- this.m_MediaPlayer.CloseVideo();
- GameMain.Instance.SoundMgr.PlayBGM(mediaName, 0f, true);
- string text = "*鑑賞_";
- if (element.faceIndex == 0)
- {
- text += "喜び";
- }
- else if (element.faceIndex == 1)
- {
- text += "怒り";
- }
- else if (element.faceIndex == 2)
- {
- text += "哀しみ";
- }
- else if (element.faceIndex == 3)
- {
- text += "楽しい";
- }
- Debug.Log("外部スクリプト名:?_movieface_main.ks\nラベル文字列:" + text);
- Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
- GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(((!(maid == null)) ? ScriptManager.ReplacePersonal(maid, "?_movieface_main") : "?_movieface_main.ks") + ".ks", text);
- GameMain.Instance.ScriptMgr.adv_kag.Exec();
- });
- }
- element.ButtonEvent_ChangeFaceType(faceIndex);
- for (int k = 0; k < element.buttonFaces.Length; k++)
- {
- element.buttonFaces[k].GetComponent<Graphic>().raycastTarget = true;
- element.buttonFaces[k].gameObject.SetActive(true);
- }
- transform.SetParent(this.m_UIContent, false);
- return element;
- }
- private void GetBGMName(int id, ref string BGMTitle, ref string BGMFileName)
- {
- string text = "phot_sound_list.nei";
- if (!GameUty.FileSystem.IsExistentFile(text))
- {
- NDebug.Assert("表がありません。" + text, false);
- }
- using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
- {
- using (CsvParser csvParser = new CsvParser())
- {
- bool condition = csvParser.Open(afileBase);
- NDebug.Assert(condition, text + "\nopen failed.");
- for (int i = 1; i < csvParser.max_cell_y; i++)
- {
- if (csvParser.IsCellToExistData(0, i))
- {
- if (csvParser.GetCellAsInteger(0, i) == id)
- {
- BGMTitle = csvParser.GetCellAsString(1, i);
- BGMFileName = csvParser.GetCellAsString(2, i);
- break;
- }
- }
- }
- }
- }
- }
- private void SaveAndPlay(string MediaName, UnityAction callback)
- {
- string mediaFilePath = this.m_MediaFilePath;
- if (GameUty.FileSystem.IsExistentFile(MediaName))
- {
- using (AFileBase afileBase = GameUty.FileOpen(MediaName, null))
- {
- if (afileBase != null && afileBase.IsValid())
- {
- byte[] bytes = afileBase.ReadAll();
- File.WriteAllBytes(mediaFilePath + "\\b.bgm", bytes);
- callback();
- }
- }
- }
- }
- public static void Event_PlayMovie(string movieName)
- {
- if (VRExternalFileLoader.m_PtrMediaPlayerObject == null)
- {
- VRExternalFileLoader.m_PtrMediaPlayerObject = (UnityEngine.Object.Instantiate(Resources.Load("SceneVRCommunication\\Tablet\\Media Outputer (Music And Movie)")) as GameObject);
- }
- GameObject[] array = GameObject.FindGameObjectsWithTag("MediaPlayerObj");
- MediaPlayer mediaPlayer = null;
- ApplyToMaterial applyToMaterial = null;
- for (int i = 0; i < array.Length; i++)
- {
- if (mediaPlayer != null && applyToMaterial != null)
- {
- break;
- }
- if (mediaPlayer == null)
- {
- mediaPlayer = array[i].GetComponent<MediaPlayer>();
- }
- if (applyToMaterial == null)
- {
- applyToMaterial = array[i].GetComponent<ApplyToMaterial>();
- }
- }
- if (mediaPlayer == null)
- {
- Debug.LogError("[VR動画再生]\u3000MediaPlayer を持ったオブジェクトが見つかりません。");
- return;
- }
- if (applyToMaterial == null)
- {
- Debug.LogError("[VR動画再生]\u3000ApplyToMaterial を持ったオブジェクトが見つかりません。");
- return;
- }
- mediaPlayer.CloseVideo();
- applyToMaterial.GetComponent<MeshRenderer>().enabled = true;
- string path = Path.GetFullPath(".\\") + "GameData/movie_vrcom/" + Path.ChangeExtension(movieName, ".ine");
- NDebug.Assert(File.Exists(path), "動画「" + movieName + "」が見つかりません");
- mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, path, true);
- }
- public static void Event_CloseMovie()
- {
- GameObject[] array = GameObject.FindGameObjectsWithTag("MediaPlayerObj");
- for (int i = 0; i < array.Length; i++)
- {
- ApplyToMaterial component = array[i].GetComponent<ApplyToMaterial>();
- if (component)
- {
- MeshRenderer component2 = component.GetComponent<MeshRenderer>();
- if (component2)
- {
- component2.enabled = false;
- }
- }
- MediaPlayer component3 = array[i].GetComponent<MediaPlayer>();
- if (component3)
- {
- component3.CloseVideo();
- }
- }
- if (VRExternalFileLoader.m_PtrMediaPlayerObject)
- {
- UnityEngine.Object.Destroy(VRExternalFileLoader.m_PtrMediaPlayerObject);
- }
- }
- public static void Event_OpenSelect()
- {
- VRCanvasManager.Instance.ClearCanvasStack();
- VRDialogMenu vrdialogMenu = VRDialogMenu.CreateDialog();
- List<VRDialogMenu.DialogButton> list = new List<VRDialogMenu.DialogButton>();
- list.Add(new VRDialogMenu.DialogButton(true, "vr_dialog_cd", delegate()
- {
- VRExternalFileLoader.m_MediaNowType = VRExternalFileLoader.TYPE_MEDIA.Music;
- VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MusicPlayer);
- }, new Vector3(250f, -270f, 0f), new Vector2(300f, 300f)));
- list.Add(new VRDialogMenu.DialogButton(true, "vr_dialog_tv", delegate()
- {
- VRExternalFileLoader.m_MediaNowType = VRExternalFileLoader.TYPE_MEDIA.Movie;
- VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MoviePlayer);
- }, new Vector3(-250f, -270f, 0f), new Vector2(300f, 300f)));
- list.Add(new VRDialogMenu.DialogButton(true, "vr_bottom_system_return", delegate()
- {
- string label_name = "*鑑賞_終了";
- Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
- GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(((!(maid == null)) ? ScriptManager.ReplacePersonal(maid, "?_movieface_main") : "?_movieface_main.ks") + ".ks", label_name);
- GameMain.Instance.ScriptMgr.adv_kag.Exec();
- VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
- }, new Vector3(-778f, -365f, 0f), new Vector2(200f, 200f)));
- vrdialogMenu.OpenDialog("再生機器を選んでください。", list.ToArray());
- if (SceneVRCommunication.Instance.GetNowTime() == SceneVRCommunication.VR_TIME.NIGHT)
- {
- GameMain.Instance.SoundMgr.PlayBGM("BGM_vr0001.ogg", 1f, true);
- }
- else
- {
- GameMain.Instance.SoundMgr.PlayBGM("BGM007.ogg", 1f, true);
- }
- }
- public void ScrollEvent_ContentScroll(Vector2 normalizedPos)
- {
- this.m_SliderBar.value = normalizedPos.y;
- }
- public void ButtonEvent_CloseVideo()
- {
- if (this.m_MovieOutputer)
- {
- this.m_MovieOutputer.GetComponent<MeshRenderer>().enabled = false;
- }
- if (this.m_MediaPlayer)
- {
- this.m_MediaPlayer.CloseVideo();
- }
- GameMain.Instance.SoundMgr.StopBGM(0f);
- }
- public void ButtonEvent_CloseCanvas()
- {
- base.StopAllCoroutines();
- UICanvasFade component = base.GetComponent<UICanvasFade>();
- if (component)
- {
- component.FadeOut();
- }
- if (VRExternalFileLoader.m_PtrMediaPlayerObject)
- {
- UnityEngine.Object.Destroy(VRExternalFileLoader.m_PtrMediaPlayerObject);
- }
- VRExternalFileLoader.Event_OpenSelect();
- }
- private void OnEnable()
- {
- if (VRExternalFileLoader.m_MediaNowType != this.m_TypeMedia)
- {
- return;
- }
- base.StartCoroutine(this.Coroutine_Refresh());
- }
- private void OnDisable()
- {
- for (int i = 0; i < this.m_UIContent.childCount; i++)
- {
- UnityEngine.Object.Destroy(this.m_UIContent.GetChild(i).gameObject);
- }
- }
- private IEnumerator Coroutine_Load<T>(string path, UnityAction<ResourceRequest> callback) where T : UnityEngine.Object
- {
- ResourceRequest res = Resources.LoadAsync<T>(path);
- while (!res.isDone)
- {
- yield return null;
- }
- callback(res);
- yield break;
- }
- [SerializeField]
- private RectTransform m_UIContent;
- [SerializeField]
- private Slider m_SliderBar;
- [SerializeField]
- private RectTransform m_UIPrefabMovieButton;
- [SerializeField]
- private RectTransform m_UIPrefabMusicButton;
- [SerializeField]
- private MediaPlayer m_MediaPlayer;
- [SerializeField]
- private ApplyToMaterial m_MovieOutputer;
- [SerializeField]
- [Tooltip("外部ファイルへのパス。「~/Movie/」など、\nファイルが置いてあるパスを指定する。")]
- private string m_MediaFilePath;
- [SerializeField]
- [Space(16f)]
- private VRExternalFileLoader.TYPE_MEDIA m_TypeMedia;
- public static GameObject m_PtrMediaPlayerObject;
- private bool m_BeforeFreeMode;
- private static bool m_IsEndLoad = true;
- private static int m_LoadingCount;
- private static VRExternalFileLoader.TYPE_MEDIA m_MediaNowType = VRExternalFileLoader.TYPE_MEDIA.Movie;
- private enum TYPE_MEDIA
- {
- Music,
- Movie
- }
- }
|