MeidoPhotoStudio.cs 7.6 KB

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