MeidoPhotoStudio.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using System.Linq;
  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("COM3D2.MeidoPhotoStudio.Plugin"), 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 PropManager propManager;
  20. private LightManager lightManager;
  21. private EffectManager effectManager;
  22. private Constants.Scene currentScene;
  23. private bool initialized = false;
  24. private bool isActive = false;
  25. private bool uiActive = false;
  26. private MeidoPhotoStudio()
  27. {
  28. MeidoPhotoStudio.instance = this;
  29. }
  30. private void Awake()
  31. {
  32. DontDestroyOnLoad(this);
  33. Translation.Initialize("en");
  34. Constants.Initialize();
  35. }
  36. private void Start()
  37. {
  38. SceneManager.sceneLoaded += OnSceneLoaded;
  39. }
  40. private void Update()
  41. {
  42. if (currentScene == Constants.Scene.Daily)
  43. {
  44. if (Input.GetKeyDown(KeyCode.F6))
  45. {
  46. if (!initialized)
  47. {
  48. Initialize();
  49. windowManager.MainWindowVisible = true;
  50. }
  51. else
  52. {
  53. ReturnToMenu();
  54. }
  55. }
  56. if (isActive)
  57. {
  58. bool qFlag = Input.GetKey(KeyCode.Q);
  59. if (!qFlag && Input.GetKeyDown(KeyCode.S))
  60. {
  61. StartCoroutine(TakeScreenShot());
  62. }
  63. meidoManager.Update();
  64. windowManager.Update();
  65. environmentManager.Update();
  66. }
  67. }
  68. }
  69. private IEnumerator TakeScreenShot()
  70. {
  71. // Hide UI and dragpoints
  72. GameObject editUI = GameObject.Find("/UI Root/Camera");
  73. GameObject fpsViewer =
  74. UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/FpsCounter", false);
  75. GameObject sysDialog =
  76. UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/SystemDialog", false);
  77. GameObject sysShortcut =
  78. UTY.GetChildObject(GameMain.Instance.gameObject, "SystemUI Root/SystemShortcut", false);
  79. if (editUI != null) editUI.SetActive(false);
  80. fpsViewer.SetActive(false);
  81. sysDialog.SetActive(false);
  82. sysShortcut.SetActive(false);
  83. uiActive = false;
  84. List<Meido> activeMeidoList = this.meidoManager.ActiveMeidoList;
  85. bool[] isIK = new bool[activeMeidoList.Count];
  86. for (int i = 0; i < activeMeidoList.Count; i++)
  87. {
  88. Meido meido = activeMeidoList[i];
  89. isIK[i] = meido.IsIK;
  90. if (meido.IsIK) meido.SetIKActive(false);
  91. }
  92. GizmoRender.UIVisible = false;
  93. yield return new WaitForEndOfFrame();
  94. // Take Screenshot
  95. int[] superSize = new[] { 1, 2, 4 };
  96. int selectedSuperSize = superSize[(int)GameMain.Instance.CMSystem.ScreenShotSuperSize];
  97. Application.CaptureScreenshot(Utility.ScreenshotFilename(), selectedSuperSize);
  98. GameMain.Instance.SoundMgr.PlaySe("se022.ogg", false);
  99. yield return new WaitForEndOfFrame();
  100. // Show UI and dragpoints
  101. uiActive = true;
  102. if (editUI != null) editUI.SetActive(true);
  103. fpsViewer.SetActive(GameMain.Instance.CMSystem.ViewFps);
  104. sysDialog.SetActive(true);
  105. sysShortcut.SetActive(true);
  106. for (int i = 0; i < activeMeidoList.Count; i++)
  107. {
  108. Meido meido = activeMeidoList[i];
  109. if (isIK[i]) meido.SetIKActive(true);
  110. }
  111. GizmoRender.UIVisible = true;
  112. }
  113. private void OnGUI()
  114. {
  115. if (uiActive)
  116. {
  117. windowManager.OnGUI();
  118. }
  119. }
  120. private void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
  121. {
  122. currentScene = (Constants.Scene)scene.buildIndex;
  123. }
  124. private void ReturnToMenu()
  125. {
  126. if (meidoManager.IsBusy) return;
  127. meidoManager.Deactivate();
  128. environmentManager.Deactivate();
  129. messageWindowManager.Deactivate();
  130. isActive = false;
  131. uiActive = false;
  132. initialized = false;
  133. windowManager.MainWindowVisible = false;
  134. GameMain.Instance.SoundMgr.PlayBGM("bgm009.ogg", 1f, true);
  135. GameObject go = GameObject.Find("UI Root").transform.Find("DailyPanel").gameObject;
  136. go.SetActive(true);
  137. bool isNight = GameMain.Instance.CharacterMgr.status.GetFlag("時間帯") == 3;
  138. if (isNight)
  139. {
  140. GameMain.Instance.BgMgr.ChangeBg("ShinShitsumu_ChairRot_Night");
  141. }
  142. else
  143. {
  144. GameMain.Instance.BgMgr.ChangeBg("ShinShitsumu_ChairRot");
  145. }
  146. GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
  147. GameMain.Instance.MainCamera.SetTargetPos(new Vector3(0.5609447f, 1.380762f, -1.382336f), true);
  148. GameMain.Instance.MainCamera.SetDistance(1.6f, true);
  149. GameMain.Instance.MainCamera.SetAroundAngle(new Vector2(245.5691f, 6.273283f), true);
  150. }
  151. private void Initialize()
  152. {
  153. TabsPane.SelectedTab = Constants.Window.Call;
  154. initialized = true;
  155. meidoManager = new MeidoManager();
  156. meidoManager.BeginCallMeidos += (s, a) => this.uiActive = false;
  157. meidoManager.EndCallMeidos += (s, a) => this.uiActive = true;
  158. lightManager = new LightManager();
  159. propManager = new PropManager();
  160. effectManager = new EffectManager();
  161. environmentManager = new EnvironmentManager(propManager, lightManager, effectManager);
  162. messageWindowManager = new MessageWindowManager();
  163. windowManager = new WindowManager(meidoManager, environmentManager, messageWindowManager);
  164. environmentManager.Initialize();
  165. isActive = true;
  166. uiActive = true;
  167. #region maid stuff
  168. // if (maid)
  169. // {
  170. // maid.StopKuchipakuPattern();
  171. // maid.body0.trsLookTarget = GameMain.Instance.MainCamera.transform;
  172. // if (maid.Visible && maid.body0.isLoadedBody)
  173. // {
  174. // maid.CrossFade("pose_taiki_f.anm", false, true, false, 0f);
  175. // maid.SetAutoTwistAll(true);
  176. // maid.body0.MuneYureL(1f);
  177. // maid.body0.MuneYureR(1f);
  178. // maid.body0.jbMuneL.enabled = true;
  179. // maid.body0.jbMuneR.enabled = true;
  180. // }
  181. // maid.body0.SetMask(TBody.SlotID.wear, true);
  182. // maid.body0.SetMask(TBody.SlotID.skirt, true);
  183. // maid.body0.SetMask(TBody.SlotID.bra, true);
  184. // maid.body0.SetMask(TBody.SlotID.panz, true);
  185. // maid.body0.SetMask(TBody.SlotID.mizugi, true);
  186. // maid.body0.SetMask(TBody.SlotID.onepiece, true);
  187. // if (maid.body0.isLoadedBody)
  188. // {
  189. // for (int i = 0; i < maid.body0.goSlot.Count; i++)
  190. // {
  191. // List<THair1> fieldValue = Utility.GetFieldValue<TBoneHair_, List<THair1>>(maid.body0.goSlot[i].bonehair, "hair1list");
  192. // for (int j = 0; j < fieldValue.Count; ++j)
  193. // {
  194. // fieldValue[j].SoftG = new Vector3(0.0f, -3f / 1000f, 0.0f);
  195. // }
  196. // }
  197. // }
  198. // }
  199. #endregion
  200. GameObject dailyPanel = GameObject.Find("UI Root").transform.Find("DailyPanel").gameObject;
  201. dailyPanel.SetActive(false);
  202. }
  203. }
  204. }