PaperAirplaneManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using UnityEngine;
  5. public class PaperAirplaneManager : MonoBehaviour
  6. {
  7. private int totalScore
  8. {
  9. get
  10. {
  11. return this.miniGameManager.score / 10;
  12. }
  13. set
  14. {
  15. this.miniGameManager.ScoreBoard.score = value * 10;
  16. }
  17. }
  18. private void Awake()
  19. {
  20. this.playBGMName = Path.ChangeExtension(this.playBGMName, "ogg");
  21. this.throwPlaySeName = Path.ChangeExtension(this.throwPlaySeName, "ogg");
  22. this.throwMissPlaySeName = Path.ChangeExtension(this.throwMissPlaySeName, "ogg");
  23. this.explosionSeName = Path.ChangeExtension(this.explosionSeName, "ogg");
  24. }
  25. private void Start()
  26. {
  27. this.targetObject.onEndAnimationVanish = new Action(this.OnEndAnimationVanish);
  28. base.StartCoroutine(this.WaitVrStart());
  29. }
  30. private IEnumerator WaitVrStart()
  31. {
  32. while (GameMain.Instance.OvrMgr == null)
  33. {
  34. yield return null;
  35. }
  36. yield return null;
  37. GameMain.Instance.MainCamera.FadeIn(0.5f, false, null, true, true, default(Color));
  38. base.StartCoroutine(this.WaitFadeJob());
  39. yield break;
  40. }
  41. private IEnumerator WaitFadeJob()
  42. {
  43. while (GameMain.Instance.MainCamera.IsFadeProc())
  44. {
  45. yield return null;
  46. }
  47. this.AwakeMiniGame();
  48. yield break;
  49. }
  50. public void AwakeMiniGame()
  51. {
  52. GameMain.Instance.SoundMgr.PlayBGM(this.playBGMName, 0.5f, true);
  53. Vector3 vector = this.playerPosition.position;
  54. this.useCamera = GameMain.Instance.OvrMgr.OvrCamera;
  55. vector += this.playerPosition.forward * this.playerPositionDistance;
  56. vector = new Vector3(vector.x, this.useCamera.GetHeightStandAndSit(CameraMain.STAND_SIT.STAND), vector.z);
  57. this.useCamera.SetPos(vector);
  58. this.useCamera.SetRotation(Quaternion.LookRotation(this.appearancePosition[0].position - vector).eulerAngles);
  59. vector = this.maidPosition.position;
  60. GameMain.Instance.CharacterMgr.SetCharaAllPos(vector);
  61. Vector3 charaAllRot = new Vector3(0f, Quaternion.LookRotation(this.useCamera.GetPos() - vector).eulerAngles.y, 0f);
  62. GameMain.Instance.CharacterMgr.SetCharaAllRot(charaAllRot);
  63. this.is2DMode = false;
  64. if (this.devideType == GameMain.VRDeviceType.NON || this.devideType == GameMain.VRDeviceType.RIFT || this.devideType == GameMain.VRDeviceType.FOVE)
  65. {
  66. this.is2DMode = true;
  67. }
  68. this.useCamera.ForceHideUI(true);
  69. this.gaugeManager.ChangeDeviceMode(this.devideType);
  70. this.miniGameManager = VRMiniGameManager.Instance;
  71. VRMiniGameManager.VRMiniGameType type = VRMiniGameManager.VRMiniGameType.Kamihikouki;
  72. this.miniGameManager.Init(type);
  73. this.miniGameManager.CreateScoreBoard(this.scoreBoardPosition.position, Quaternion.LookRotation(this.scoreBoardPosition.position - this.useCamera.GetPos()));
  74. this.miniGameManager.ScoreBoard.gameObject.SetActive(false);
  75. if (!this.is2DMode)
  76. {
  77. Vector3 vector2 = this.useCamera.GetPos();
  78. vector2 -= Vector3.right * 1.5f;
  79. Quaternion uirot = Quaternion.LookRotation(vector2 - this.useCamera.GetPos());
  80. this.miniGameManager.StartRightLeftHand(vector2, uirot, delegate(AVRController con)
  81. {
  82. this.StartMiniGame(!con.m_bHandL);
  83. });
  84. }
  85. else
  86. {
  87. this.StartMiniGame(true);
  88. }
  89. }
  90. public void StartMiniGame(bool main_hand_right)
  91. {
  92. if (!this.is2DMode)
  93. {
  94. this.useCtrl = GameMain.Instance.OvrMgr.OvrCamera.GetVRControllerButtons(!main_hand_right);
  95. if (this.devideType == GameMain.VRDeviceType.RIFT_TOUCH)
  96. {
  97. this.grabber.SetGripTransform((!main_hand_right) ? "Rift_Left" : "Rift_Right");
  98. }
  99. else
  100. {
  101. this.grabber.SetGripTransform("HTC");
  102. }
  103. }
  104. else
  105. {
  106. this.useCtrl = this.dummyController;
  107. if (this.devideType == GameMain.VRDeviceType.NON)
  108. {
  109. this.grabber.SetGripTransform("2D");
  110. }
  111. else
  112. {
  113. this.grabber.SetGripTransform("Rift_Non");
  114. }
  115. }
  116. this.grabber.m_vrController = this.useCtrl;
  117. this.throwObject.onThrowObjectEvent = new WfGrabbableObject.OnThrowObjectEvent(this.OnThrowObject);
  118. this.throwObject.onCollisionEnter = new Action<WfGrabbableObject, Collision>(this.OnThrowObjectCollisionEnter);
  119. this.throwObject.onThrowObjectCorrectionVelocityEvent = new WfGrabbableObject.OnThrowObjectCorrectionVelocityEvent(this.OnThrowObjectCorrectionVelocity);
  120. int totalScore = 0;
  121. this.totalScore = totalScore;
  122. this.throwCount = totalScore;
  123. this.addPoint = 1;
  124. this.contactTime = 0f;
  125. this.throwFlag = (this.mistakeThrow = (this.isFinish = false));
  126. this.StopVoice();
  127. this.miniGameManager.ScoreBoard.gameObject.SetActive(true);
  128. this.gaugeManager.Stop();
  129. this.gaugeManager.onMouseClickDownEvent = delegate(VRMiniGameGaugeeManager eventObject)
  130. {
  131. if (this.gaugeManager.isPlay || !this.throwObject.IsGrabbed)
  132. {
  133. return;
  134. }
  135. this.gaugeManager.Play();
  136. };
  137. this.gaugeManager.onMouseClickUpEvent = new VRMiniGameGaugeeManager.OnMouseClickEvent(this.onMouseClickUpEvent);
  138. this.gaugeManager.enabledMouseClickEvent = true;
  139. this.GrabPaperAirplane();
  140. this.PopupTargetObject();
  141. }
  142. private void PopupTargetObject()
  143. {
  144. this.PopupTargetObject(this.throwCount);
  145. }
  146. private void PopupTargetObject(int throwCount)
  147. {
  148. if (0 <= throwCount && throwCount <= 10)
  149. {
  150. VRMiniGameManager.VoiceType type = (VRMiniGameManager.VoiceType)Enum.Parse(typeof(VRMiniGameManager.VoiceType), "Remaining" + (10 - throwCount).ToString());
  151. Debug.Log("throwCountボイス再生:" + throwCount);
  152. this.miniGameManager.AddQueueVoice(type);
  153. }
  154. Debug.Log(throwCount + 1 + "回目の投擲です");
  155. Vector3 pos = Vector3.zero;
  156. if (0 <= throwCount && throwCount < this.appearancePosition.Length)
  157. {
  158. Transform transform = this.appearancePosition[throwCount];
  159. int childCount = transform.childCount;
  160. pos = transform.GetChild(UnityEngine.Random.Range(0, childCount - 1)).position;
  161. }
  162. else
  163. {
  164. Debug.LogError("投擲回数は" + throwCount + "回目ですが、的位置の設定が見当たりません");
  165. pos = Vector3.zero;
  166. }
  167. this.targetObject.PopupPosition(pos);
  168. }
  169. private void GrabPaperAirplane()
  170. {
  171. Physics.gravity = this.customGravity;
  172. this.throwFlag = (this.mistakeThrow = false);
  173. this.contactTime = 0f;
  174. Rigidbody component = this.grabber.GetComponent<Rigidbody>();
  175. Rigidbody rigidbody = component;
  176. Vector3 zero = Vector3.zero;
  177. component.angularVelocity = zero;
  178. rigidbody.velocity = zero;
  179. this.throwObject.rigidBody.isKinematic = false;
  180. this.throwObject.rigidBody.useGravity = true;
  181. this.throwObject.StopLookRotationAnime();
  182. this.throwObject.transform.SetParent(base.transform, false);
  183. this.grabber.GrabBegin(this.throwObject);
  184. }
  185. private void OnThrowObjectCorrectionVelocity(ref Vector3 linearVelocity, ref Vector3 angularVelocity)
  186. {
  187. this.targetObject.OnThrowObjectCorrectionVelocity(this.throwObject.transform, ref linearVelocity, ref angularVelocity);
  188. }
  189. private void OnThrowObject(WfGrabbableObject throwObject, bool mistakeThrow)
  190. {
  191. this.throwFlag = true;
  192. this.mistakeThrow = mistakeThrow;
  193. if (!mistakeThrow)
  194. {
  195. this.throwCount++;
  196. this.PlaySe(this.throwPlaySeName);
  197. }
  198. else
  199. {
  200. this.PlaySe(this.throwMissPlaySeName);
  201. }
  202. }
  203. private void OnThrowObjectCollisionEnter(WfGrabbableObject throwObject, Collision collision)
  204. {
  205. if (!this.throwFlag)
  206. {
  207. return;
  208. }
  209. this.throwFlag = false;
  210. Physics.gravity = new Vector3(0f, -9.81f, 0f);
  211. throwObject.StopLookRotationAnime();
  212. if (collision.gameObject.layer == PaperAirplaneManager.MiniGameObjectLayerNumber)
  213. {
  214. throwObject.rigidBody.isKinematic = true;
  215. throwObject.rigidBody.useGravity = false;
  216. Rigidbody rigidBody = throwObject.rigidBody;
  217. Vector3 zero = Vector3.zero;
  218. throwObject.rigidBody.angularVelocity = zero;
  219. rigidBody.velocity = zero;
  220. Transform transform = collision.transform;
  221. while (transform != null)
  222. {
  223. PaperAirplaneTarget component = transform.GetComponent<PaperAirplaneTarget>();
  224. if (component != null)
  225. {
  226. component.Die();
  227. throwObject.transform.SetParent(component.modelTransform, true);
  228. break;
  229. }
  230. transform = transform.parent;
  231. }
  232. this.OnHit();
  233. }
  234. else if (this.mistakeThrow)
  235. {
  236. this.contactTime = Time.fixedTime;
  237. }
  238. else
  239. {
  240. this.OnMiss();
  241. }
  242. }
  243. private void OnHit()
  244. {
  245. this.PlaySe(this.explosionSeName);
  246. this.miniGameManager.AddQueueVoice(VRMiniGameManager.VoiceType.Hit);
  247. this.totalScore += this.addPoint;
  248. this.addPoint++;
  249. this.miniGameManager.ScoreBoard.life--;
  250. }
  251. private void OnMiss()
  252. {
  253. this.miniGameManager.AddQueueVoice(VRMiniGameManager.VoiceType.Miss);
  254. this.targetObject.Vanish();
  255. this.addPoint = 1;
  256. this.miniGameManager.ScoreBoard.life--;
  257. }
  258. private void OnEndAnimationVanish()
  259. {
  260. if (this.throwCount >= 10)
  261. {
  262. Physics.gravity = this.backupGravity;
  263. this.isFinish = true;
  264. this.gaugeManager.isVisible = false;
  265. this.miniGameManager.AddQueueVoice(VRMiniGameManager.VoiceType.Remaining0);
  266. this.miniGameManager.Result(null);
  267. }
  268. else
  269. {
  270. this.GrabPaperAirplane();
  271. this.PopupTargetObject();
  272. }
  273. }
  274. private void OnDestroy()
  275. {
  276. Physics.gravity = this.backupGravity;
  277. }
  278. private void FixedUpdate()
  279. {
  280. if (this.useCamera == null || this.isFinish)
  281. {
  282. return;
  283. }
  284. if (this.is2DMode)
  285. {
  286. this.dummyController.transform.position = this.useCamera.m_goCenterEye.transform.position + this.useCamera.m_goCenterEye.transform.forward * 0.2f;
  287. this.dummyController.transform.rotation = Quaternion.LookRotation(this.dummyController.transform.position - this.useCamera.m_goCenterEye.transform.position);
  288. }
  289. }
  290. private void onMouseClickUpEvent(VRMiniGameGaugeeManager eventObject)
  291. {
  292. if (!this.gaugeManager.isPlay || !this.throwObject.IsGrabbed)
  293. {
  294. return;
  295. }
  296. Vector3 a = this.dummyController.transform.position - this.useCamera.m_goCenterEye.transform.position;
  297. Vector3 eulerAngles = Quaternion.LookRotation(this.dummyController.transform.position - this.useCamera.m_goCenterEye.transform.position).eulerAngles;
  298. float d = this.gaugeRangeMin + (this.gaugeRangeMax - this.gaugeRangeMin) * this.gaugeManager.gaugeValue;
  299. this.grabber.GrabEnd(a * d, eulerAngles);
  300. this.gaugeManager.Stop();
  301. }
  302. private void Update()
  303. {
  304. if (this.useCamera == null || this.useCtrl == null || this.isFinish)
  305. {
  306. return;
  307. }
  308. if (this.throwObject.transform.position.y <= -3f)
  309. {
  310. if (-1000f < this.throwObject.transform.position.y)
  311. {
  312. if (!this.mistakeThrow)
  313. {
  314. this.throwObject.transform.position = new Vector3(0f, -1000f, 0f);
  315. this.throwObject.rigidBody.isKinematic = false;
  316. this.throwObject.rigidBody.useGravity = true;
  317. this.throwObject.StopLookRotationAnime();
  318. this.OnMiss();
  319. }
  320. else
  321. {
  322. this.GrabPaperAirplane();
  323. }
  324. }
  325. }
  326. else if (0f < this.contactTime && Time.fixedTime - this.contactTime >= 1.5f)
  327. {
  328. this.GrabPaperAirplane();
  329. }
  330. }
  331. private void PlaySe(string seFileName)
  332. {
  333. if (!string.IsNullOrEmpty(seFileName) && GameMain.Instance != null && GameMain.Instance.SoundMgr != null)
  334. {
  335. GameMain.Instance.SoundMgr.PlaySe(seFileName, false);
  336. }
  337. }
  338. private void StopVoice()
  339. {
  340. GameMain.Instance.SoundMgr.VoiceStopAll();
  341. }
  342. private GameMain.VRDeviceType devideType
  343. {
  344. get
  345. {
  346. return GameMain.Instance.VRDeviceTypeID;
  347. }
  348. }
  349. public static readonly int MiniGameObjectLayerNumber = 24;
  350. [SerializeField]
  351. public Vector3 customGravity = Physics.gravity;
  352. [SerializeField]
  353. private VRGrabber grabber;
  354. [SerializeField]
  355. private WfGrabbableObject throwObject;
  356. [SerializeField]
  357. private PaperAirplaneTarget targetObject;
  358. [SerializeField]
  359. private Transform[] appearancePosition;
  360. [SerializeField]
  361. [Tooltip("主人公の基準位置")]
  362. private Transform playerPosition;
  363. [SerializeField]
  364. [Tooltip("主人公の基準位置からの距離")]
  365. private float playerPositionDistance;
  366. [SerializeField]
  367. [Tooltip("メイドの位置")]
  368. private Transform maidPosition;
  369. [SerializeField]
  370. [Tooltip("スコアボードの位置")]
  371. private Transform scoreBoardPosition;
  372. [SerializeField]
  373. [Tooltip("再生BGM")]
  374. private string playBGMName = "BGM_vr0002";
  375. [SerializeField]
  376. [Tooltip("投擲成功の時呼ばれるSE")]
  377. private string throwPlaySeName = "SE_vrminigame003_01";
  378. [SerializeField]
  379. [Tooltip("投擲失敗の時呼ばれるSE")]
  380. private string throwMissPlaySeName = "SE_vrminigame003_01";
  381. [SerializeField]
  382. [Tooltip("対象にhitした時呼ばれるSE")]
  383. private string explosionSeName = string.Empty;
  384. [SerializeField]
  385. [Tooltip("2D用ダミーコントローラー")]
  386. private AVRControllerButtons dummyController;
  387. [SerializeField]
  388. [Tooltip("2D用ゲージマネージャー")]
  389. private VRMiniGameGaugeeManager gaugeManager;
  390. [SerializeField]
  391. [Tooltip("2D用ゲージの最小値")]
  392. private float gaugeRangeMin;
  393. [SerializeField]
  394. [Tooltip("2D用ゲージの最大値")]
  395. private float gaugeRangeMax;
  396. private OvrCamera useCamera;
  397. private AVRControllerButtons useCtrl;
  398. private VRMiniGameManager miniGameManager;
  399. private int throwCount;
  400. private bool throwFlag;
  401. private bool mistakeThrow;
  402. private float contactTime;
  403. private int addPoint = 1;
  404. private bool is2DMode;
  405. private Vector3 backupGravity = Physics.gravity;
  406. private bool isFinish;
  407. }