MeidoPhotoStudio.cs 6.8 KB

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