MeidoPhotoStudio.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using System.Linq;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using UnityEngine;
  7. using UnityEngine.SceneManagement;
  8. using UnityInjector;
  9. using UnityInjector.Attributes;
  10. namespace COM3D2.MeidoPhotoStudio.Plugin
  11. {
  12. [PluginName("COM3D2.MeidoPhotoStudio.Plugin"), PluginVersion("0.0.0")]
  13. public class MeidoPhotoStudio : PluginBase
  14. {
  15. private static MonoBehaviour instance;
  16. private WindowManager windowManager;
  17. private MeidoManager meidoManager;
  18. private EnvironmentManager environmentManager;
  19. private MessageWindowManager messageWindowManager;
  20. private Constants.Scene currentScene;
  21. private bool initialized = false;
  22. private bool isActive = false;
  23. private bool uiActive = false;
  24. private MeidoPhotoStudio()
  25. {
  26. MeidoPhotoStudio.instance = this;
  27. }
  28. private void Awake()
  29. {
  30. DontDestroyOnLoad(this);
  31. Translation.Initialize("en");
  32. Constants.Initialize();
  33. }
  34. private void Start()
  35. {
  36. SceneManager.sceneLoaded += OnSceneLoaded;
  37. }
  38. private void Update()
  39. {
  40. if (currentScene == Constants.Scene.Daily)
  41. {
  42. if (Input.GetKeyDown(KeyCode.F6))
  43. {
  44. if (isActive) Deactivate();
  45. else Activate();
  46. }
  47. if (isActive)
  48. {
  49. bool qFlag = Input.GetKey(KeyCode.Q);
  50. if (!qFlag && Input.GetKeyDown(KeyCode.S))
  51. {
  52. StartCoroutine(TakeScreenShot());
  53. }
  54. meidoManager.Update();
  55. environmentManager.Update();
  56. windowManager.Update();
  57. }
  58. }
  59. }
  60. private IEnumerator TakeScreenShot()
  61. {
  62. // Hide UI and dragpoints
  63. GameObject editUI = GameObject.Find("/UI Root/Camera");
  64. GameObject fpsViewer =
  65. UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/FpsCounter", false);
  66. GameObject sysDialog =
  67. UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/SystemDialog", false);
  68. GameObject sysShortcut =
  69. UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/SystemShortcut", false);
  70. editUI.SetActive(false);
  71. fpsViewer.SetActive(false);
  72. sysDialog.SetActive(false);
  73. sysShortcut.SetActive(false);
  74. uiActive = false;
  75. List<Meido> activeMeidoList = this.meidoManager.ActiveMeidoList;
  76. bool[] isIK = new bool[activeMeidoList.Count];
  77. for (int i = 0; i < activeMeidoList.Count; i++)
  78. {
  79. Meido meido = activeMeidoList[i];
  80. isIK[i] = meido.IsIK;
  81. if (meido.IsIK) meido.IsIK = false;
  82. }
  83. GizmoRender.UIVisible = false;
  84. yield return new WaitForEndOfFrame();
  85. // Take Screenshot
  86. int[] superSize = new[] { 1, 2, 4 };
  87. int selectedSuperSize = superSize[(int)GameMain.Instance.CMSystem.ScreenShotSuperSize];
  88. Application.CaptureScreenshot(Utility.ScreenshotFilename(), selectedSuperSize);
  89. GameMain.Instance.SoundMgr.PlaySe("se022.ogg", false);
  90. yield return new WaitForEndOfFrame();
  91. // Show UI and dragpoints
  92. uiActive = true;
  93. editUI.SetActive(true);
  94. fpsViewer.SetActive(GameMain.Instance.CMSystem.ViewFps);
  95. sysDialog.SetActive(true);
  96. sysShortcut.SetActive(true);
  97. for (int i = 0; i < activeMeidoList.Count; i++)
  98. {
  99. Meido meido = activeMeidoList[i];
  100. if (isIK[i]) meido.IsIK = true;
  101. }
  102. GizmoRender.UIVisible = true;
  103. }
  104. private void OnGUI()
  105. {
  106. if (uiActive)
  107. {
  108. windowManager.DrawWindows();
  109. if (DropdownHelper.Visible) DropdownHelper.HandleDropdown();
  110. }
  111. }
  112. private void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
  113. {
  114. currentScene = (Constants.Scene)scene.buildIndex;
  115. if (currentScene == Constants.Scene.Daily)
  116. {
  117. if (!initialized) Initialize();
  118. }
  119. }
  120. private void Initialize()
  121. {
  122. if (initialized) return;
  123. initialized = true;
  124. meidoManager = new MeidoManager();
  125. environmentManager = new EnvironmentManager(meidoManager);
  126. messageWindowManager = new MessageWindowManager();
  127. MaidSwitcherPane maidSwitcherPane = new MaidSwitcherPane(meidoManager);
  128. windowManager = new WindowManager()
  129. {
  130. [Constants.Window.Main] = new MainWindow(meidoManager)
  131. {
  132. [Constants.Window.Call] = new CallWindowPane(meidoManager),
  133. [Constants.Window.Pose] = new PoseWindowPane(meidoManager, maidSwitcherPane),
  134. [Constants.Window.Face] = new FaceWindowPane(meidoManager, maidSwitcherPane),
  135. [Constants.Window.BG] = new BGWindowPane(environmentManager),
  136. [Constants.Window.BG2] = new BG2WindowPane(meidoManager, environmentManager)
  137. },
  138. [Constants.Window.Message] = new MessageWindow(messageWindowManager)
  139. };
  140. meidoManager.BeginCallMeidos += (s, a) => uiActive = false;
  141. meidoManager.EndCallMeidos += (s, a) => uiActive = true;
  142. }
  143. private void Activate()
  144. {
  145. uiActive = true;
  146. isActive = true;
  147. meidoManager.Activate();
  148. environmentManager.Activate();
  149. windowManager.Activate();
  150. messageWindowManager.Activate();
  151. GameObject dailyPanel = GameObject.Find("UI Root").transform.Find("DailyPanel").gameObject;
  152. dailyPanel.SetActive(false);
  153. }
  154. private void Deactivate()
  155. {
  156. if (meidoManager.IsBusy) return;
  157. uiActive = false;
  158. isActive = false;
  159. meidoManager.Deactivate();
  160. environmentManager.Deactivate();
  161. messageWindowManager.Deactivate();
  162. windowManager.Deactivate();
  163. // GameMain.Instance.SoundMgr.PlayBGM("bgm009.ogg", 1f, true);
  164. GameObject dailyPanel = GameObject.Find("UI Root").transform.Find("DailyPanel").gameObject;
  165. dailyPanel.SetActive(true);
  166. }
  167. }
  168. }