PrivateMaidTouchManager.cs 9.9 KB

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