MeidoPhotoStudio.cs 6.6 KB

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