MeidoPhotoStudio.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using UnityEngine;
  6. using UnityEngine.SceneManagement;
  7. using UnityInjector;
  8. using UnityInjector.Attributes;
  9. namespace COM3D2.MeidoPhotoStudio.Plugin
  10. {
  11. [PluginName("Meido Photo Studio"), PluginVersion("0.0.0")]
  12. public class MeidoPhotoStudio : PluginBase
  13. {
  14. private static MonoBehaviour instance;
  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. private MeidoPhotoStudio()
  24. {
  25. MeidoPhotoStudio.instance = this;
  26. }
  27. private void Awake()
  28. {
  29. DontDestroyOnLoad(this);
  30. Translation.Initialize("en");
  31. Constants.Initialize();
  32. }
  33. private void Start()
  34. {
  35. SceneManager.sceneLoaded += OnSceneLoaded;
  36. }
  37. private void Update()
  38. {
  39. if (currentScene == Constants.Scene.Daily)
  40. {
  41. if (Input.GetKeyDown(KeyCode.F6))
  42. {
  43. if (!initialized)
  44. {
  45. Initialize();
  46. windowManager.MainWindowVisible = true;
  47. }
  48. else
  49. {
  50. ReturnToMenu();
  51. }
  52. }
  53. if (isActive)
  54. {
  55. bool qFlag = Input.GetKey(KeyCode.Q);
  56. if (!qFlag && Input.GetKeyDown(KeyCode.S))
  57. {
  58. StartCoroutine(TakeScreenShot());
  59. }
  60. meidoManager.Update();
  61. windowManager.Update();
  62. environmentManager.Update();
  63. }
  64. }
  65. }
  66. private IEnumerator TakeScreenShot()
  67. {
  68. // Hide UI and dragpoints
  69. GameObject editUI = GameObject.Find("/UI Root/Camera");
  70. GameObject fpsViewer = UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/FpsCounter", false);
  71. GameObject sysDialog = UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/SystemDialog", false);
  72. GameObject sysShortcut = UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/SystemShortcut", false);
  73. if (editUI != null) 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.SetIKActive(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. if (editUI != null) 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.SetIKActive(true);
  104. }
  105. GizmoRender.UIVisible = true;
  106. }
  107. private void OnGUI()
  108. {
  109. if (uiActive)
  110. {
  111. windowManager.OnGUI();
  112. }
  113. }
  114. private void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
  115. {
  116. currentScene = (Constants.Scene)scene.buildIndex;
  117. }
  118. private void ReturnToMenu()
  119. {
  120. if (meidoManager.IsBusy) return;
  121. meidoManager.DeactivateMeidos();
  122. environmentManager.Deactivate();
  123. messageWindowManager.Deactivate();
  124. isActive = false;
  125. uiActive = false;
  126. initialized = false;
  127. windowManager.MainWindowVisible = false;
  128. GameMain.Instance.SoundMgr.PlayBGM("bgm009.ogg", 1f, true);
  129. GameObject go = GameObject.Find("UI Root").transform.Find("DailyPanel").gameObject;
  130. go.SetActive(true);
  131. bool isNight = GameMain.Instance.CharacterMgr.status.GetFlag("時間帯") == 3;
  132. if (isNight)
  133. {
  134. GameMain.Instance.BgMgr.ChangeBg("ShinShitsumu_ChairRot_Night");
  135. }
  136. else
  137. {
  138. GameMain.Instance.BgMgr.ChangeBg("ShinShitsumu_ChairRot");
  139. }
  140. GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
  141. GameMain.Instance.MainCamera.SetTargetPos(new Vector3(0.5609447f, 1.380762f, -1.382336f), true);
  142. GameMain.Instance.MainCamera.SetDistance(1.6f, true);
  143. GameMain.Instance.MainCamera.SetAroundAngle(new Vector2(245.5691f, 6.273283f), true);
  144. }
  145. private void Initialize()
  146. {
  147. initialized = true;
  148. meidoManager = new MeidoManager();
  149. meidoManager.BeginCallMeidos += (s, a) => this.uiActive = false;
  150. meidoManager.EndCallMeidos += (s, a) => this.uiActive = true;
  151. environmentManager = new EnvironmentManager();
  152. messageWindowManager = new MessageWindowManager();
  153. windowManager = new WindowManager(meidoManager, environmentManager, messageWindowManager);
  154. environmentManager.Initialize();
  155. isActive = true;
  156. uiActive = true;
  157. #region maid stuff
  158. // if (maid)
  159. // {
  160. // maid.StopKuchipakuPattern();
  161. // maid.body0.trsLookTarget = GameMain.Instance.MainCamera.transform;
  162. // if (maid.Visible && maid.body0.isLoadedBody)
  163. // {
  164. // maid.CrossFade("pose_taiki_f.anm", false, true, false, 0f);
  165. // maid.SetAutoTwistAll(true);
  166. // maid.body0.MuneYureL(1f);
  167. // maid.body0.MuneYureR(1f);
  168. // maid.body0.jbMuneL.enabled = true;
  169. // maid.body0.jbMuneR.enabled = true;
  170. // }
  171. // maid.body0.SetMask(TBody.SlotID.wear, true);
  172. // maid.body0.SetMask(TBody.SlotID.skirt, true);
  173. // maid.body0.SetMask(TBody.SlotID.bra, true);
  174. // maid.body0.SetMask(TBody.SlotID.panz, true);
  175. // maid.body0.SetMask(TBody.SlotID.mizugi, true);
  176. // maid.body0.SetMask(TBody.SlotID.onepiece, true);
  177. // if (maid.body0.isLoadedBody)
  178. // {
  179. // for (int i = 0; i < maid.body0.goSlot.Count; i++)
  180. // {
  181. // List<THair1> fieldValue = Utility.GetFieldValue<TBoneHair_, List<THair1>>(maid.body0.goSlot[i].bonehair, "hair1list");
  182. // for (int j = 0; j < fieldValue.Count; ++j)
  183. // {
  184. // fieldValue[j].SoftG = new Vector3(0.0f, -3f / 1000f, 0.0f);
  185. // }
  186. // }
  187. // }
  188. // }
  189. #endregion
  190. GameObject dailyPanel = GameObject.Find("UI Root").transform.Find("DailyPanel").gameObject;
  191. dailyPanel.SetActive(false);
  192. }
  193. }
  194. }