MeidoPhotoStudio.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 =
  71. UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/FpsCounter", false);
  72. GameObject sysDialog =
  73. UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/SystemDialog", false);
  74. GameObject sysShortcut =
  75. UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/SystemShortcut", false);
  76. if (editUI != null) editUI.SetActive(false);
  77. fpsViewer.SetActive(false);
  78. sysDialog.SetActive(false);
  79. sysShortcut.SetActive(false);
  80. uiActive = false;
  81. List<Meido> activeMeidoList = this.meidoManager.ActiveMeidoList;
  82. bool[] isIK = new bool[activeMeidoList.Count];
  83. for (int i = 0; i < activeMeidoList.Count; i++)
  84. {
  85. Meido meido = activeMeidoList[i];
  86. isIK[i] = meido.IsIK;
  87. if (meido.IsIK) meido.SetIKActive(false);
  88. }
  89. GizmoRender.UIVisible = false;
  90. yield return new WaitForEndOfFrame();
  91. // Take Screenshot
  92. int[] superSize = new[] { 1, 2, 4 };
  93. int selectedSuperSize = superSize[(int)GameMain.Instance.CMSystem.ScreenShotSuperSize];
  94. Application.CaptureScreenshot(Utility.ScreenshotFilename(), selectedSuperSize);
  95. GameMain.Instance.SoundMgr.PlaySe("se022.ogg", false);
  96. yield return new WaitForEndOfFrame();
  97. // Show UI and dragpoints
  98. uiActive = true;
  99. if (editUI != null) editUI.SetActive(true);
  100. fpsViewer.SetActive(GameMain.Instance.CMSystem.ViewFps);
  101. sysDialog.SetActive(true);
  102. sysShortcut.SetActive(true);
  103. for (int i = 0; i < activeMeidoList.Count; i++)
  104. {
  105. Meido meido = activeMeidoList[i];
  106. if (isIK[i]) meido.SetIKActive(true);
  107. }
  108. GizmoRender.UIVisible = true;
  109. }
  110. private void OnGUI()
  111. {
  112. if (uiActive)
  113. {
  114. windowManager.OnGUI();
  115. }
  116. }
  117. private void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
  118. {
  119. currentScene = (Constants.Scene)scene.buildIndex;
  120. }
  121. private void ReturnToMenu()
  122. {
  123. if (meidoManager.IsBusy) return;
  124. meidoManager.DeactivateMeidos();
  125. environmentManager.Deactivate();
  126. messageWindowManager.Deactivate();
  127. isActive = false;
  128. uiActive = false;
  129. initialized = false;
  130. windowManager.MainWindowVisible = false;
  131. GameMain.Instance.SoundMgr.PlayBGM("bgm009.ogg", 1f, true);
  132. GameObject go = GameObject.Find("UI Root").transform.Find("DailyPanel").gameObject;
  133. go.SetActive(true);
  134. bool isNight = GameMain.Instance.CharacterMgr.status.GetFlag("時間帯") == 3;
  135. if (isNight)
  136. {
  137. GameMain.Instance.BgMgr.ChangeBg("ShinShitsumu_ChairRot_Night");
  138. }
  139. else
  140. {
  141. GameMain.Instance.BgMgr.ChangeBg("ShinShitsumu_ChairRot");
  142. }
  143. GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
  144. GameMain.Instance.MainCamera.SetTargetPos(new Vector3(0.5609447f, 1.380762f, -1.382336f), true);
  145. GameMain.Instance.MainCamera.SetDistance(1.6f, true);
  146. GameMain.Instance.MainCamera.SetAroundAngle(new Vector2(245.5691f, 6.273283f), true);
  147. }
  148. private void Initialize()
  149. {
  150. initialized = true;
  151. meidoManager = new MeidoManager();
  152. meidoManager.BeginCallMeidos += (s, a) => this.uiActive = false;
  153. meidoManager.EndCallMeidos += (s, a) => this.uiActive = true;
  154. environmentManager = new EnvironmentManager();
  155. messageWindowManager = new MessageWindowManager();
  156. windowManager = new WindowManager(meidoManager, environmentManager, messageWindowManager);
  157. environmentManager.Initialize();
  158. isActive = true;
  159. uiActive = true;
  160. #region maid stuff
  161. // if (maid)
  162. // {
  163. // maid.StopKuchipakuPattern();
  164. // maid.body0.trsLookTarget = GameMain.Instance.MainCamera.transform;
  165. // if (maid.Visible && maid.body0.isLoadedBody)
  166. // {
  167. // maid.CrossFade("pose_taiki_f.anm", false, true, false, 0f);
  168. // maid.SetAutoTwistAll(true);
  169. // maid.body0.MuneYureL(1f);
  170. // maid.body0.MuneYureR(1f);
  171. // maid.body0.jbMuneL.enabled = true;
  172. // maid.body0.jbMuneR.enabled = true;
  173. // }
  174. // maid.body0.SetMask(TBody.SlotID.wear, true);
  175. // maid.body0.SetMask(TBody.SlotID.skirt, true);
  176. // maid.body0.SetMask(TBody.SlotID.bra, true);
  177. // maid.body0.SetMask(TBody.SlotID.panz, true);
  178. // maid.body0.SetMask(TBody.SlotID.mizugi, true);
  179. // maid.body0.SetMask(TBody.SlotID.onepiece, true);
  180. // if (maid.body0.isLoadedBody)
  181. // {
  182. // for (int i = 0; i < maid.body0.goSlot.Count; i++)
  183. // {
  184. // List<THair1> fieldValue = Utility.GetFieldValue<TBoneHair_, List<THair1>>(maid.body0.goSlot[i].bonehair, "hair1list");
  185. // for (int j = 0; j < fieldValue.Count; ++j)
  186. // {
  187. // fieldValue[j].SoftG = new Vector3(0.0f, -3f / 1000f, 0.0f);
  188. // }
  189. // }
  190. // }
  191. // }
  192. #endregion
  193. GameObject dailyPanel = GameObject.Find("UI Root").transform.Find("DailyPanel").gameObject;
  194. dailyPanel.SetActive(false);
  195. }
  196. }
  197. }