ShootCutInTex.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 = UTY.gameProjectPath + "\\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. DanceEnemyParam currentEnemy = VsDanceDataMgr.Instance.GetCurrentEnemy(is_second);
  181. if (currentEnemy == null)
  182. {
  183. return;
  184. }
  185. ShootCutInTex.m_EnemyCutInTexList.Add(ShootCutInTex.CutInName.対峙演出, currentEnemy.ConfrontCutin);
  186. ShootCutInTex.m_EnemyCutInTexList.Add(ShootCutInTex.CutInName.性格固有1, currentEnemy.PersonalCutin1);
  187. ShootCutInTex.m_EnemyCutInTexList.Add(ShootCutInTex.CutInName.性格固有2, currentEnemy.PersonalCutin2);
  188. ShootCutInTex.m_EnemyCutInTexList.Add(ShootCutInTex.CutInName.ジョブ固有, currentEnemy.JobCutin);
  189. ShootCutInTex.m_EnemyCutInTexList.Add(ShootCutInTex.CutInName.逆転, currentEnemy.ReversalCutin);
  190. }
  191. public static void SetPlayerCutInTex()
  192. {
  193. ShootCutInTex.m_IsShoot = false;
  194. Sprite value = Resources.Load<Sprite>("SceneDance/Rhythm_Action/Sprite/CutInTex/Personal1");
  195. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.性格固有1, value);
  196. value = Resources.Load<Sprite>("SceneDance/Rhythm_Action/Sprite/CutInTex/Personal2");
  197. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.性格固有2, value);
  198. value = Resources.Load<Sprite>("SceneDance/Rhythm_Action/Sprite/CutInTex/Job");
  199. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.ジョブ固有, value);
  200. value = Resources.Load<Sprite>("SceneDance/Rhythm_Action/Sprite/CutInTex/Reversal");
  201. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.逆転, value);
  202. value = Resources.Load<Sprite>("SceneDance/Rhythm_Action/Sprite/CutInTex/Confront");
  203. ShootCutInTex.m_PlayerCutInTexList.Add(ShootCutInTex.CutInName.対峙演出, value);
  204. }
  205. public static bool IsContainsTex(DanceBattle_Mgr.CharaType chara_type, ShootCutInTex.CutInName cut_name)
  206. {
  207. if (chara_type == DanceBattle_Mgr.CharaType.Player)
  208. {
  209. return ShootCutInTex.m_PlayerCutInTexList.ContainsKey(cut_name) && ShootCutInTex.m_PlayerCutInTexList[cut_name];
  210. }
  211. return ShootCutInTex.m_EnemyCutInTexList.ContainsKey(cut_name) && ShootCutInTex.m_EnemyCutInTexList[cut_name];
  212. }
  213. public static Sprite GetCutInTex(DanceBattle_Mgr.CharaType chara_type, ShootCutInTex.CutInName cut_name)
  214. {
  215. if (chara_type == DanceBattle_Mgr.CharaType.Player)
  216. {
  217. if (ShootCutInTex.m_PlayerCutInTexList.ContainsKey(cut_name))
  218. {
  219. return ShootCutInTex.m_PlayerCutInTexList[cut_name];
  220. }
  221. Debug.LogError("プレイヤーの" + cut_name + "カットイン用の画像が存在しません");
  222. return null;
  223. }
  224. else
  225. {
  226. if (chara_type != DanceBattle_Mgr.CharaType.Enemy)
  227. {
  228. return null;
  229. }
  230. if (ShootCutInTex.m_EnemyCutInTexList.ContainsKey(cut_name))
  231. {
  232. return ShootCutInTex.m_EnemyCutInTexList[cut_name];
  233. }
  234. Debug.LogError("敵の" + cut_name + "カットイン用の画像が存在しません");
  235. return null;
  236. }
  237. }
  238. public static void TextureClear(DanceBattle_Mgr.CharaType chara_type)
  239. {
  240. if (chara_type == DanceBattle_Mgr.CharaType.Player)
  241. {
  242. if (ShootCutInTex.m_IsShoot)
  243. {
  244. foreach (Sprite sprite in ShootCutInTex.m_PlayerCutInTexList.Values)
  245. {
  246. if (sprite)
  247. {
  248. if (sprite.texture)
  249. {
  250. UnityEngine.Object.DestroyImmediate(sprite.texture, true);
  251. }
  252. UnityEngine.Object.DestroyImmediate(sprite, true);
  253. }
  254. }
  255. }
  256. ShootCutInTex.m_PlayerCutInTexList.Clear();
  257. }
  258. else
  259. {
  260. ShootCutInTex.m_EnemyCutInTexList.Clear();
  261. }
  262. }
  263. public static void CutInTexShoot(string cut_name, string label)
  264. {
  265. GameObject gameObject = new GameObject("CutIn_Shoot", new Type[]
  266. {
  267. typeof(ShootCutInTex),
  268. typeof(Camera)
  269. });
  270. gameObject.GetComponent<ShootCutInTex>().Init(cut_name, label);
  271. }
  272. private const int m_TimeSpeed = 20;
  273. private const int m_CutInTexWidth = 1920;
  274. private const int m_CutInTexHeight = 1080;
  275. private const string m_PlayerTexPath = "AppealImage/";
  276. private const float m_CameraFov = 35f;
  277. private const int m_AntiAliasDefo = 2;
  278. private const string m_PersonalImage1 = "Sprite/CutInTex/Personal1";
  279. private const string m_PersonalImage2 = "Sprite/CutInTex/Personal2";
  280. private const string m_JobImage = "Sprite/CutInTex/Job";
  281. private const string m_ReversalImage = "Sprite/CutInTex/Reversal";
  282. private const string m_ConfrontImage = "Sprite/CutInTex/Confront";
  283. private ShootCutInTex.CutInName m_CutName;
  284. private string m_JumpLabel = string.Empty;
  285. private Camera m_MyCamera;
  286. private static Dictionary<ShootCutInTex.CutInName, Sprite> m_PlayerCutInTexList = new Dictionary<ShootCutInTex.CutInName, Sprite>();
  287. private static Dictionary<ShootCutInTex.CutInName, Sprite> m_EnemyCutInTexList = new Dictionary<ShootCutInTex.CutInName, Sprite>();
  288. private static bool m_IsShoot = false;
  289. public enum CutInName
  290. {
  291. 対峙演出,
  292. 性格固有1,
  293. 性格固有2,
  294. ジョブ固有,
  295. 逆転
  296. }
  297. }