PrivateMaidTouchManager.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using PrivateMaidMode;
  5. using UnityEngine;
  6. using wf;
  7. public class PrivateMaidTouchManager : MonoBehaviour
  8. {
  9. public int currentExcitement { get; private set; }
  10. public int currentMood { get; private set; }
  11. public Maid maid { get; private set; }
  12. public TouchDataBase.Data playTouchData { get; private set; }
  13. private void Awake()
  14. {
  15. PrivateMaidTouchManager.instance = this;
  16. this.subtitleDisplay.visible = false;
  17. if (!Product.supportMultiLanguage)
  18. {
  19. this.subtitleDisplay.autoDisplayTypeChange = false;
  20. }
  21. this.subtitleDisplay.displayType = SubtitleDisplayManager.DisplayType.Original;
  22. this.uiPanel.alpha = 0f;
  23. }
  24. private void Start()
  25. {
  26. if (ScenePrivateEventModeAwake.callEventId != -1)
  27. {
  28. this.CallTouchMode(GameMain.Instance.CharacterMgr.GetMaid(0), ScenePrivateEventModeAwake.callEventId);
  29. }
  30. }
  31. protected IEnumerator Setup()
  32. {
  33. this.setupCompleted = false;
  34. this.pointDatas = this.playTouchData.GetAllPointData();
  35. this.maid.AllProcPropSeqStart();
  36. this.maid.Visible = true;
  37. while (this.maid.IsBusy)
  38. {
  39. yield return null;
  40. }
  41. MaidPartsCollider partsCollider = MaidPartsCollider.AddPartCollider(this.maid);
  42. this.colliderList = partsCollider.AddCollider();
  43. for (int i = 0; i < this.colliderList.Count; i++)
  44. {
  45. int num = i;
  46. this.colliderList[num].canTouch = this.playTouchData.EnabledPoint(this.colliderList[num].point);
  47. ColliderEventVR colliderEventVR = this.colliderList[i].gameObject.AddComponent<ColliderEventVR>();
  48. colliderEventVR.onMouseDown = delegate()
  49. {
  50. if (this.playTouchData.EnabledPoint(this.colliderList[num].point))
  51. {
  52. this.OnTouchPoint(this.colliderList[num].point);
  53. }
  54. };
  55. }
  56. yield return null;
  57. yield return null;
  58. if (this.playTouchData.phaseType == 0)
  59. {
  60. this.currentExcitement = 0;
  61. this.currentMood = 300;
  62. }
  63. else
  64. {
  65. this.currentExcitement = PrivateMaidTouchManager.backupExcitement;
  66. this.currentMood = PrivateMaidTouchManager.backuptMood;
  67. }
  68. this.statusGauge.SetCurrentExcite(this.currentExcitement, false);
  69. this.statusGauge.SetCurrentMood(this.currentMood, false);
  70. GameMain.Instance.ScriptMgr.is_motion_blend = false;
  71. this.kagManager.LoadScript(null, this.playTouchData.ftFile, string.Empty);
  72. GameMain.Instance.ScriptMgr.is_motion_blend = true;
  73. this.rcVoiceList.Clear();
  74. this.kagManager.LoadScript(this.maid, this.playTouchData.rcRegisterFile, this.playTouchData.rcRegisterLabel);
  75. this.TouchPointViewer.Setup(this.playTouchData);
  76. this.setupCompleted = true;
  77. this.uiPanel.alpha = 1f;
  78. GameMain.Instance.MainCamera.FadeIn(0.5f, false, null, true, true, default(Color));
  79. yield break;
  80. }
  81. public void CallTouchMode(Maid maid, int id)
  82. {
  83. GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
  84. GameMain.Instance.MainLight.Reset();
  85. GameMain.Instance.CharacterMgr.ResetCharaPosAll();
  86. GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
  87. GameMain.Instance.SoundMgr.VoiceStopAll();
  88. this.playTouchData = ((!TouchDataBase.Contains(id)) ? null : TouchDataBase.GetData(id));
  89. if (this.playTouchData == null)
  90. {
  91. Debug.LogError("タッチモードを始められませんでした。要求id" + id.ToString());
  92. return;
  93. }
  94. this.maid = maid;
  95. base.StartCoroutine(this.Setup());
  96. }
  97. public void OnTouchPoint(TouchDataBase.TouchPoint point)
  98. {
  99. if (this.playTouchData == null || !this.playTouchData.EnabledPoint(point))
  100. {
  101. return;
  102. }
  103. this.repeatVoiceTriggerTime = (this.subtitleOffTime = 0f);
  104. this.subtitleDisplay.visible = false;
  105. TouchDataBase.PointData pointData = this.playTouchData.GetPointData(point);
  106. int num = 0;
  107. int num2 = 0;
  108. int num3 = (this.playTouchData.phaseType != 0) ? 100 : 0;
  109. while (num3 < 300 && num == 0)
  110. {
  111. num3 += 40;
  112. if (this.currentExcitement < num3)
  113. {
  114. num = num3;
  115. }
  116. else
  117. {
  118. num2++;
  119. }
  120. }
  121. this.currentExcitement = wf.Math.RoundMinMax(this.currentExcitement + pointData.addExcitement, 0, (this.playTouchData.phaseType != 0) ? 300 : 100);
  122. this.currentMood = wf.Math.RoundMinMax(this.currentMood + pointData.addMood, 0, 300);
  123. this.statusGauge.SetCurrentExcite(this.currentExcitement, true);
  124. this.statusGauge.SetCurrentMood(this.currentMood, true);
  125. if (this.currentMood <= 0)
  126. {
  127. GameMain.Instance.MainCamera.FadeOut(0.5f, false, delegate
  128. {
  129. this.OnFinish(false);
  130. }, true, default(Color));
  131. }
  132. else if ((this.playTouchData.phaseType == 0 && this.currentExcitement >= 100) || (this.playTouchData.phaseType == 1 && this.currentExcitement >= 300))
  133. {
  134. PrivateMaidTouchManager.backupExcitement = this.currentExcitement;
  135. PrivateMaidTouchManager.backuptMood = this.currentMood;
  136. GameMain.Instance.MainCamera.FadeOut(0.5f, false, delegate
  137. {
  138. this.OnFinish(true);
  139. }, true, default(Color));
  140. }
  141. else
  142. {
  143. this.kagManager.ClearExecWait();
  144. this.kagManager.LoadScript(this.maid, this.playTouchData.touchScriptFile, pointData.scriptLabelName);
  145. float reserveRepeatVoice;
  146. if (num <= this.currentExcitement && num2 < this.rcVoiceList.Count)
  147. {
  148. reserveRepeatVoice = this.PlayVoice(this.rcVoiceList[num2]);
  149. }
  150. else
  151. {
  152. reserveRepeatVoice = this.PlayVoice(this.singleVoiceData);
  153. }
  154. this.SetReserveRepeatVoice(reserveRepeatVoice);
  155. }
  156. }
  157. public void OnFinish(bool isSuccess)
  158. {
  159. if (this.playTouchData == null)
  160. {
  161. return;
  162. }
  163. string text = (!isSuccess) ? this.playTouchData.failureFile : this.playTouchData.successFile;
  164. string str = (!isSuccess) ? this.playTouchData.failureLabel : this.playTouchData.successLabel;
  165. if (this.maid != null && this.maid.GetComponent<MaidPartsCollider>() != null)
  166. {
  167. this.maid.GetComponent<MaidPartsCollider>().RemoveCollider();
  168. UnityEngine.Object.Destroy(this.maid.GetComponent<MaidPartsCollider>());
  169. }
  170. if (string.IsNullOrEmpty(text))
  171. {
  172. Debug.LogError("移動先の指定はありませんでした");
  173. return;
  174. }
  175. text = ((!(this.maid == null)) ? ScriptManager.ReplacePersonal(this.maid, text) : text);
  176. this.uiPanel.alpha = 0f;
  177. GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
  178. PartColliderData.SetDefaultCursor();
  179. ScriptManager scriptMgr = GameMain.Instance.ScriptMgr;
  180. scriptMgr.EvalScript("global.__private_maid_mode_adv_file = '" + text + "';");
  181. scriptMgr.EvalScript("global.__private_maid_mode_adv_label = '" + str + "';");
  182. scriptMgr.LoadAdvScenarioScript("private_maid_mode_adv_call.ks", "*ADVスタート");
  183. scriptMgr.adv_kag.Exec();
  184. }
  185. public void SetSingleVoice(PrivateMaidTouchManager.VoiceData voiceData)
  186. {
  187. this.singleVoiceData = voiceData;
  188. }
  189. public void SetRepeatVoice(PrivateMaidTouchManager.VoiceData voiceData)
  190. {
  191. this.repeatVoiceData = voiceData;
  192. }
  193. public void AddRcVoiceData(PrivateMaidTouchManager.VoiceData voiceData)
  194. {
  195. this.rcVoiceList.Add(voiceData);
  196. }
  197. private void SetReserveRepeatVoice(float playingVoiceTime)
  198. {
  199. this.repeatVoiceTriggerTime = Time.time + playingVoiceTime + UnityEngine.Random.Range(3f, 7f);
  200. }
  201. private float PlayVoice(PrivateMaidTouchManager.VoiceData voiceData)
  202. {
  203. if (voiceData == null)
  204. {
  205. return 0f;
  206. }
  207. Maid maid = null;
  208. for (int i = 0; i < GameMain.Instance.CharacterMgr.GetMaidCount(); i++)
  209. {
  210. Maid maid2 = GameMain.Instance.CharacterMgr.GetMaid(i);
  211. if (maid2 != null && maid2.status.guid == voiceData.maidGuid)
  212. {
  213. maid = maid2;
  214. break;
  215. }
  216. }
  217. float num = 0f;
  218. if (maid != null && maid.Visible)
  219. {
  220. maid.AudioMan.LoadPlay(voiceData.voiceFileName, 0f, false, false);
  221. if (maid.AudioMan.audiosource.clip != null)
  222. {
  223. num = maid.AudioMan.audiosource.clip.length;
  224. }
  225. }
  226. else
  227. {
  228. int voice_pitch = 50;
  229. AudioSourceMgr.Type soundType = AudioSourceMgr.Type.Voice;
  230. if (maid != null)
  231. {
  232. voice_pitch = maid.VoicePitch;
  233. soundType = maid.AudioMan.SoundType;
  234. }
  235. GameMain.Instance.SoundMgr.PlayDummyVoice(voiceData.voiceFileName, 0f, false, false, voice_pitch, soundType);
  236. if (GameMain.Instance.SoundMgr.m_AudioDummyVoice.audiosource.clip != null)
  237. {
  238. num = GameMain.Instance.SoundMgr.m_AudioDummyVoice.audiosource.clip.length;
  239. }
  240. }
  241. if (0f < num)
  242. {
  243. this.subtitleDisplay.SetTextFromScriptStyle(voiceData.text);
  244. this.subtitleDisplay.visible = true;
  245. this.subtitleOffTime = Time.time + num;
  246. }
  247. return num;
  248. }
  249. private void Update()
  250. {
  251. if (this.subtitleDisplay.visible && this.subtitleDisplay.messageBgAlpha != SubtitleDisplayManager.configMessageAlpha)
  252. {
  253. this.subtitleDisplay.messageBgAlpha = SubtitleDisplayManager.configMessageAlpha;
  254. }
  255. if (0f < this.subtitleOffTime && this.subtitleOffTime <= Time.time)
  256. {
  257. this.subtitleOffTime = 0f;
  258. this.subtitleDisplay.visible = false;
  259. }
  260. if (0f < this.repeatVoiceTriggerTime && this.repeatVoiceTriggerTime <= Time.time)
  261. {
  262. float reserveRepeatVoice = this.PlayVoice(this.repeatVoiceData);
  263. this.SetReserveRepeatVoice(reserveRepeatVoice);
  264. }
  265. }
  266. private PrivateMaidTouchKagManager kagManager
  267. {
  268. get
  269. {
  270. return GameMain.Instance.ScriptMgr.privatemode_touch_kag;
  271. }
  272. }
  273. private static int backupExcitement;
  274. private static int backuptMood;
  275. [SerializeField]
  276. private UIPanel uiPanel;
  277. [SerializeField]
  278. private PrivateMaidTouchParamBasicBar statusGauge;
  279. [SerializeField]
  280. private SubtitleDisplayManager subtitleDisplay;
  281. [SerializeField]
  282. private PrivateMaidTouchTouchPointViewer TouchPointViewer;
  283. public static PrivateMaidTouchManager instance;
  284. private List<PartColliderData> colliderList;
  285. private List<TouchDataBase.PointData> pointDatas;
  286. private bool setupCompleted;
  287. private List<PrivateMaidTouchManager.VoiceData> rcVoiceList = new List<PrivateMaidTouchManager.VoiceData>();
  288. private PrivateMaidTouchManager.VoiceData singleVoiceData;
  289. private PrivateMaidTouchManager.VoiceData repeatVoiceData;
  290. private float repeatVoiceTriggerTime;
  291. private float subtitleOffTime;
  292. public class VoiceData
  293. {
  294. public string maidGuid;
  295. public string voiceFileName;
  296. public string text;
  297. }
  298. }