MeidoPhotoStudio.cs 6.7 KB

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