123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using wf;
- public class SubtitleMovieManager : MonoBehaviour
- {
- public bool isPlaying { get; private set; }
- public static SubtitleMovieManager GetGlobalInstance(bool casinoType)
- {
- GameObject childObject = UTY.GetChildObject(GameObject.Find("__GameMain__"), "SystemUI Root", false);
- GameObject gameObject;
- if (!casinoType)
- {
- gameObject = UTY.GetChildObject(childObject, "GlobalSubtitleMovieManager", true);
- if (gameObject == null)
- {
- gameObject = Utility.CreatePrefab(childObject, "System/Prefab/SubtitleMovieManager", true);
- gameObject.name = "GlobalSubtitleMovieManager";
- }
- gameObject.transform.localPosition = new Vector3(-459f, -247f, 0f);
- }
- else
- {
- gameObject = UTY.GetChildObject(childObject, "GlobalSubtitleMovieManagerCasinoType", true);
- if (gameObject == null)
- {
- gameObject = Utility.CreatePrefab(childObject, "System/Prefab/SubtitleMovieManagerCasino", true);
- gameObject.name = "GlobalSubtitleMovieManagerCasinoType";
- }
- gameObject.transform.localPosition = new Vector3(228f, 375f, 0f);
- }
- return gameObject.GetComponent<SubtitleMovieManager>();
- }
- public static void DestroyGlobalInstance()
- {
- GameObject childObject = UTY.GetChildObject(GameObject.Find("__GameMain__"), "SystemUI Root", false);
- GameObject childObject2 = UTY.GetChildObject(childObject, "GlobalSubtitleMovieManager", true);
- if (childObject2 != null)
- {
- UnityEngine.Object.DestroyImmediate(childObject2);
- }
- childObject2 = UTY.GetChildObject(childObject, "GlobalSubtitleMovieManagerCasinoType", true);
- if (childObject2 != null)
- {
- UnityEngine.Object.DestroyImmediate(childObject2);
- }
- }
- public void Clear()
- {
- this.displayDatas.Clear();
- this.isPlaying = false;
- }
- public bool AddData(string text, int displayStartTime, int displayTime)
- {
- if (this.isPlaying)
- {
- return false;
- }
- SubtitleMovieManager.DisplayData displayData = new SubtitleMovieManager.DisplayData();
- displayData.displayStartTime = displayStartTime;
- displayData.displayEndTime = displayStartTime + displayTime;
- displayData.text = text;
- this.displayDatas.Add(displayData);
- return true;
- }
- public void LoadSubtitleScriptFile(string fileName)
- {
- if (!GameUty.FileSystem.IsExistentFile(fileName))
- {
- return;
- }
- byte[] array = null;
- try
- {
- using (AFileBase afileBase = GameUty.FileOpen(fileName, null))
- {
- if (!afileBase.IsValid())
- {
- return;
- }
- array = new byte[afileBase.GetSize()];
- afileBase.Read(ref array, afileBase.GetSize());
- }
- }
- catch (Exception)
- {
- return;
- }
- if (array == null)
- {
- return;
- }
- string[] array2 = NUty.SjisToUnicode(array).Split(new string[]
- {
- "\r\n",
- "\r",
- "\n"
- }, StringSplitOptions.RemoveEmptyEntries);
- int num = 0;
- int num2 = 0;
- bool flag = false;
- string text = string.Empty;
- foreach (string text2 in array2)
- {
- if (text2.IndexOf("@talk") == 0)
- {
- int num3 = text2.IndexOf("[") + 1;
- string[] array4 = text2.Substring(num3, text2.Length - num3 - 1).Split(new string[]
- {
- "-"
- }, StringSplitOptions.RemoveEmptyEntries);
- num = int.Parse(array4[0]);
- num2 = int.Parse(array4[1]);
- flag = true;
- text = string.Empty;
- }
- else if (text2.IndexOf("@hitret") == 0)
- {
- this.AddData(text, num, num2 - num);
- flag = false;
- }
- else if (flag)
- {
- text += text2;
- }
- }
- }
- public void Play(string text, int displayTime)
- {
- this.Clear();
- this.AddData(text, 0, displayTime);
- this.Play();
- }
- public void Play()
- {
- this.timeElapsed = 0;
- this.isPlaying = true;
- this.subtitleMgr.visible = false;
- }
- public void Stop()
- {
- if (this.subtitleMgr != null)
- {
- this.subtitleMgr.visible = false;
- }
- this.isPlaying = false;
- }
- public void Update()
- {
- if (!this.isPlaying || this.displayDatas.Count == 0 || this.subtitleMgr == null)
- {
- this.Stop();
- return;
- }
- this.timeElapsed += (int)(Time.deltaTime * 1000f);
- bool visible = false;
- List<SubtitleMovieManager.DisplayData> list = new List<SubtitleMovieManager.DisplayData>();
- for (int i = 0; i < this.displayDatas.Count; i++)
- {
- SubtitleMovieManager.DisplayData displayData = this.displayDatas[i];
- if (displayData.displayStartTime <= this.timeElapsed && this.timeElapsed <= displayData.displayEndTime)
- {
- visible = true;
- this.subtitleMgr.SetTextFromScriptStyle(displayData.text);
- }
- else if (displayData.displayEndTime < this.timeElapsed)
- {
- list.Add(displayData);
- }
- }
- this.subtitleMgr.visible = visible;
- for (int j = 0; j < list.Count; j++)
- {
- for (int k = 0; k < this.displayDatas.Count; k++)
- {
- if (list[j] == this.displayDatas[k])
- {
- this.displayDatas.RemoveAt(k);
- break;
- }
- }
- }
- if (this.displayDatas.Count == 0 && this.autoDestroy)
- {
- UnityEngine.Object.DestroyImmediate(base.gameObject);
- }
- }
- [SerializeField]
- private SubtitleDisplayManager subtitleMgr;
- public bool autoDestroy;
- private int timeElapsed;
- private List<SubtitleMovieManager.DisplayData> displayDatas = new List<SubtitleMovieManager.DisplayData>();
- private class DisplayData
- {
- public int displayStartTime;
- public int displayEndTime;
- public string text;
- }
- }
|