ShootCutInTex.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using UnityEngine;
  7. public class ShootCutInTex : MonoBehaviour
  8. {
  9. private void Init(string cut_name, string label)
  10. {
  11. ShootCutInTex.m_IsShoot = true;
  12. this.m_CutName = (ShootCutInTex.CutInName)Enum.Parse(typeof(ShootCutInTex.CutInName), cut_name);
  13. this.m_JumpLabel = label;
  14. this.m_MyCamera = base.GetComponent<Camera>();
  15. this.m_MyCamera.enabled = false;
  16. float distance = GameMain.Instance.MainCamera.GetDistance();
  17. Vector2 aroundAngle = GameMain.Instance.MainCamera.GetAroundAngle();
  18. Vector3 targetPos = GameMain.Instance.MainCamera.GetTargetPos();
  19. base.transform.rotation = Quaternion.identity;
  20. base.transform.Rotate(Vector3.up * aroundAngle.x, Space.World);
  21. base.transform.Rotate(Vector3.right * aroundAngle.y, Space.Self);
  22. base.transform.position = base.transform.rotation * Vector3.forward * -distance + targetPos;
  23. this.CameraValCpy(GameMain.Instance.MainCamera.camera, this.m_MyCamera);
  24. this.m_MyCamera.aspect = 1.77777779f;
  25. if (RhythmAction_Mgr.IsVSDance && RhythmAction_Mgr.NowState == RhythmAction_Mgr.DanceState.Dance_First)
  26. {
  27. ShootCutInTex.TextureClear(DanceBattle_Mgr.CharaType.Enemy);
  28. ShootCutInTex.SetEnemyCutInTex(false);
  29. }
  30. base.StartCoroutine(this.MakeCutInTex());
  31. }
  32. private bool CheckPlayerCutInTex()
  33. {
  34. if (this.m_CutName == ShootCutInTex.CutInName.対峙演出 || this.m_CutName == ShootCutInTex.CutInName.逆転)
  35. {
  36. return RhythmAction_Mgr.NowDance == RhythmAction_Mgr.DanceType.Challenge;
  37. }
  38. if (ShootCutInTex.m_PlayerCutInTexList.ContainsKey(this.m_CutName))
  39. {
  40. return true;
  41. }
  42. string text = Path.GetFullPath(".\\") + "AppealImage/";
  43. if (!Directory.Exists(text))
  44. {
  45. Directory.CreateDirectory(text);
  46. }
  47. string text2 = DanceSelect.SelectedMaid[0].status.charaName.GetFullName(" ");
  48. text2 = text2.Replace(" ", string.Empty) + "_" + ((Product.defaultLanguage != Product.Language.Japanese) ? "Appeal" : "アピール") + ".png";
  49. bool result = false;
  50. try
  51. {
  52. using (FileStream fileStream = new FileStream(text + text2, FileMode.Open, FileAccess.Read))
  53. {
  54. BinaryReader binaryReader = new BinaryReader(fileStream);
  55. byte[] data = binaryReader.ReadBytes((int)binaryReader.BaseStream.Length);
  56. Texture2D texture2D = new Texture2D(1920, 1080);
  57. texture2D.LoadImage(data);
  58. texture2D.Apply(true, true);
  59. Sprite value = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), Vector2.one * 0.5f);
  60. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.性格固有1, value);
  61. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.性格固有2, value);
  62. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.ジョブ固有, value);
  63. binaryReader.Close();
  64. result = true;
  65. }
  66. }
  67. catch (Exception ex)
  68. {
  69. if (!File.Exists(text + text2))
  70. {
  71. Debug.Log("ShootCutInTex.cs:プレイヤー側の画像が存在しなかったので撮影した画像を使います。");
  72. }
  73. else
  74. {
  75. Debug.LogError("ShootCutInTex.cs:画像読み込みエラー。エラー箇所:" + ex.StackTrace);
  76. }
  77. }
  78. return result;
  79. }
  80. private void CameraValCpy(Camera orijin, Camera cpy)
  81. {
  82. cpy.cullingMask = orijin.cullingMask;
  83. cpy.clearFlags = orijin.clearFlags;
  84. cpy.backgroundColor = orijin.backgroundColor;
  85. cpy.farClipPlane = orijin.farClipPlane;
  86. cpy.nearClipPlane = orijin.nearClipPlane;
  87. cpy.orthographic = orijin.orthographic;
  88. cpy.fieldOfView = orijin.fieldOfView;
  89. cpy.orthographicSize = orijin.orthographicSize;
  90. }
  91. private IEnumerator MakeCutInTex()
  92. {
  93. yield return null;
  94. if (this.CheckPlayerCutInTex())
  95. {
  96. this.ShootEnd();
  97. yield break;
  98. }
  99. while (GameMain.Instance.CharacterMgr.IsBusy())
  100. {
  101. yield return null;
  102. }
  103. Time.timeScale = 20f;
  104. List<Maid> active_maid = new List<Maid>();
  105. List<Transform> eye_target = new List<Transform>();
  106. for (int i = 0; i < DanceSelect.SelectedMaid.Count; i++)
  107. {
  108. if (DanceSelect.SelectedMaid[i] && DanceSelect.SelectedMaid[i].Visible)
  109. {
  110. Maid maid2 = DanceSelect.SelectedMaid[i];
  111. active_maid.Add(maid2);
  112. eye_target.Add(maid2.body0.trsLookTarget);
  113. maid2.EyeToTargetObject(base.transform, 0f);
  114. }
  115. }
  116. for (;;)
  117. {
  118. if (!active_maid.Any((Maid maid) => maid.GetAnimation().isPlaying || maid.boFaceAnime))
  119. {
  120. break;
  121. }
  122. yield return new WaitForEndOfFrame();
  123. }
  124. Time.timeScale = 1f;
  125. for (int j = 0; j < active_maid.Count; j++)
  126. {
  127. active_maid[j].EyeToTargetObject(eye_target[j], 0f);
  128. }
  129. if (GameMain.Instance.VRMode)
  130. {
  131. GameMain.Instance.OvrMgr.OvrCamera.ShowUI(false);
  132. GameMain.Instance.OvrMgr.GetVRControllerTransform(true).gameObject.SetActive(false);
  133. GameMain.Instance.OvrMgr.GetVRControllerTransform(false).gameObject.SetActive(false);
  134. }
  135. RenderTexture rend_tex = new RenderTexture(1920, 1080, 24);
  136. rend_tex.isPowerOfTwo = false;
  137. rend_tex.antiAliasing = ((QualitySettings.antiAliasing == 0) ? 2 : QualitySettings.antiAliasing);
  138. RenderTexture orijin_rendtex = this.m_MyCamera.targetTexture;
  139. RenderTexture active_tex = RenderTexture.active;
  140. RenderTexture.active = rend_tex;
  141. this.m_MyCamera.targetTexture = rend_tex;
  142. this.m_MyCamera.fieldOfView = 35f;
  143. this.m_MyCamera.enabled = true;
  144. this.m_MyCamera.Render();
  145. this.m_MyCamera.enabled = false;
  146. Texture2D tex = new Texture2D(1920, 1080, TextureFormat.RGB24, false);
  147. tex.ReadPixels(new Rect(0f, 0f, 1920f, 1080f), 0, 0);
  148. tex.Apply();
  149. ShootCutInTex.m_PlayerCutInTexList.Add(this.m_CutName, Sprite.Create(tex, new Rect(0f, 0f, 1920f, 1080f), Vector2.one * 0.5f));
  150. this.m_MyCamera.targetTexture = orijin_rendtex;
  151. RenderTexture.active = active_tex;
  152. if (GameMain.Instance.VRMode)
  153. {
  154. GameMain.Instance.OvrMgr.OvrCamera.ShowUI(true);
  155. GameMain.Instance.OvrMgr.GetVRControllerTransform(true).gameObject.SetActive(true);
  156. GameMain.Instance.OvrMgr.GetVRControllerTransform(false).gameObject.SetActive(true);
  157. }
  158. this.ShootEnd();
  159. yield break;
  160. }
  161. private void ShootEnd()
  162. {
  163. CameraMain.CameraType cameraType = GameMain.Instance.MainCamera.GetCameraType();
  164. bool control = GameMain.Instance.MainCamera.GetControl();
  165. GameMain.Instance.MainCamera.Reset(cameraType, control);
  166. if (!string.IsNullOrEmpty(this.m_JumpLabel))
  167. {
  168. GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_JumpLabel);
  169. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  170. }
  171. else
  172. {
  173. Debug.LogError("ShootCutInTex.cs:撮影終了後に飛ぶラベルが設定されてません");
  174. }
  175. UnityEngine.Object.Destroy(base.gameObject);
  176. }
  177. public static void SetEnemyCutInTex(bool is_second)
  178. {
  179. ShootCutInTex.m_EnemyCutInTexList.Clear();
  180. ShootCutInTex.m_EnemyCutInTexList.Add(ShootCutInTex.CutInName.対峙演出, VsDanceDataMgr.Instance.GetCurrentEnemy(is_second).ConfrontCutin);
  181. ShootCutInTex.m_EnemyCutInTexList.Add(ShootCutInTex.CutInName.性格固有1, VsDanceDataMgr.Instance.GetCurrentEnemy(is_second).PersonalCutin1);
  182. ShootCutInTex.m_EnemyCutInTexList.Add(ShootCutInTex.CutInName.性格固有2, VsDanceDataMgr.Instance.GetCurrentEnemy(is_second).PersonalCutin2);
  183. ShootCutInTex.m_EnemyCutInTexList.Add(ShootCutInTex.CutInName.ジョブ固有, VsDanceDataMgr.Instance.GetCurrentEnemy(is_second).JobCutin);
  184. ShootCutInTex.m_EnemyCutInTexList.Add(ShootCutInTex.CutInName.逆転, VsDanceDataMgr.Instance.GetCurrentEnemy(is_second).ReversalCutin);
  185. }
  186. public static void SetPlayerCutInTex()
  187. {
  188. ShootCutInTex.m_IsShoot = false;
  189. Sprite value = Resources.Load<Sprite>("SceneDance/Rhythm_Action/Sprite/CutInTex/Personal1");
  190. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.性格固有1, value);
  191. value = Resources.Load<Sprite>("SceneDance/Rhythm_Action/Sprite/CutInTex/Personal2");
  192. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.性格固有2, value);
  193. value = Resources.Load<Sprite>("SceneDance/Rhythm_Action/Sprite/CutInTex/Job");
  194. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.ジョブ固有, value);
  195. value = Resources.Load<Sprite>("SceneDance/Rhythm_Action/Sprite/CutInTex/Reversal");
  196. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.逆転, value);
  197. value = Resources.Load<Sprite>("SceneDance/Rhythm_Action/Sprite/CutInTex/Confront");
  198. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.対峙演出, value);
  199. }
  200. public static bool IsContainsTex(DanceBattle_Mgr.CharaType chara_type, ShootCutInTex.CutInName cut_name)
  201. {
  202. if (chara_type == DanceBattle_Mgr.CharaType.Player)
  203. {
  204. return ShootCutInTex.m_PlayerCutInTexList.ContainsKey(cut_name) && ShootCutInTex.m_PlayerCutInTexList[cut_name];
  205. }
  206. return ShootCutInTex.m_EnemyCutInTexList.ContainsKey(cut_name) && ShootCutInTex.m_EnemyCutInTexList[cut_name];
  207. }
  208. public static Sprite GetCutInTex(DanceBattle_Mgr.CharaType chara_type, ShootCutInTex.CutInName cut_name)
  209. {
  210. if (chara_type == DanceBattle_Mgr.CharaType.Player)
  211. {
  212. if (ShootCutInTex.m_PlayerCutInTexList.ContainsKey(cut_name))
  213. {
  214. return ShootCutInTex.m_PlayerCutInTexList[cut_name];
  215. }
  216. Debug.LogError("プレイヤーの" + cut_name + "カットイン用の画像が存在しません");
  217. return null;
  218. }
  219. else
  220. {
  221. if (chara_type != DanceBattle_Mgr.CharaType.Enemy)
  222. {
  223. return null;
  224. }
  225. if (ShootCutInTex.m_EnemyCutInTexList.ContainsKey(cut_name))
  226. {
  227. return ShootCutInTex.m_EnemyCutInTexList[cut_name];
  228. }
  229. Debug.LogError("敵の" + cut_name + "カットイン用の画像が存在しません");
  230. return null;
  231. }
  232. }
  233. public static void TextureClear(DanceBattle_Mgr.CharaType chara_type)
  234. {
  235. if (chara_type == DanceBattle_Mgr.CharaType.Player)
  236. {
  237. if (ShootCutInTex.m_IsShoot)
  238. {
  239. foreach (Sprite sprite in ShootCutInTex.m_PlayerCutInTexList.Values)
  240. {
  241. if (sprite)
  242. {
  243. if (sprite.texture)
  244. {
  245. UnityEngine.Object.DestroyImmediate(sprite.texture, true);
  246. }
  247. UnityEngine.Object.DestroyImmediate(sprite, true);
  248. }
  249. }
  250. }
  251. ShootCutInTex.m_PlayerCutInTexList.Clear();
  252. }
  253. else
  254. {
  255. ShootCutInTex.m_EnemyCutInTexList.Clear();
  256. }
  257. }
  258. public static void CutInTexShoot(string cut_name, string label)
  259. {
  260. GameObject gameObject = new GameObject("CutIn_Shoot", new Type[]
  261. {
  262. typeof(ShootCutInTex),
  263. typeof(Camera)
  264. });
  265. gameObject.GetComponent<ShootCutInTex>().Init(cut_name, label);
  266. }
  267. private const int m_TimeSpeed = 20;
  268. private const int m_CutInTexWidth = 1920;
  269. private const int m_CutInTexHeight = 1080;
  270. private const string m_PlayerTexPath = "AppealImage/";
  271. private const float m_CameraFov = 35f;
  272. private const int m_AntiAliasDefo = 2;
  273. private const string m_PersonalImage1 = "Sprite/CutInTex/Personal1";
  274. private const string m_PersonalImage2 = "Sprite/CutInTex/Personal2";
  275. private const string m_JobImage = "Sprite/CutInTex/Job";
  276. private const string m_ReversalImage = "Sprite/CutInTex/Reversal";
  277. private const string m_ConfrontImage = "Sprite/CutInTex/Confront";
  278. private ShootCutInTex.CutInName m_CutName;
  279. private string m_JumpLabel = string.Empty;
  280. private Camera m_MyCamera;
  281. private static Dictionary<ShootCutInTex.CutInName, Sprite> m_PlayerCutInTexList = new Dictionary<ShootCutInTex.CutInName, Sprite>();
  282. private static Dictionary<ShootCutInTex.CutInName, Sprite> m_EnemyCutInTexList = new Dictionary<ShootCutInTex.CutInName, Sprite>();
  283. private static bool m_IsShoot = false;
  284. public enum CutInName
  285. {
  286. 対峙演出,
  287. 性格固有1,
  288. 性格固有2,
  289. ジョブ固有,
  290. 逆転
  291. }
  292. }