RabbitHuntGameMode_LocalPK.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /* 野兔关卡-本地pk模式 */
  5. public class RabbitHuntGameMode_LocalPK : RabbitHuntGameMode, ChallengeGameModeLocalPK
  6. {
  7. public int currentPlayerIndex = 0; // 双人0和1
  8. float singleShootReadyTime = 30f;
  9. float singleShootReadyTimeMax = 30f;
  10. public RabbitHuntGameMode_LocalPK(GameMgr gameMgr) : base(gameMgr) {
  11. hunterGamePlayerScoreCounter = new HunterGamePlayerScoreCounter(this);
  12. }
  13. public override void Start()
  14. {
  15. SetLevel(5);
  16. AddHuntGameView();
  17. this.gameMgr.transform.Find("HunterGameView_LocalPK").gameObject.SetActive(true);
  18. AddReadyView();
  19. }
  20. public override bool DoNextShoot() {
  21. bool canDo = base.DoNextShoot();
  22. if (canDo) {
  23. NextPlayerFinal();
  24. }
  25. return canDo;
  26. }
  27. void AddReadyView()
  28. {
  29. GameObject view = Resources.Load<GameObject>("Prefabs/Views/PKGameReadyView_Challenge");
  30. GameObject o = GameObject.Instantiate(view);
  31. PKGameReadyView_Challenge script = o.GetComponent<PKGameReadyView_Challenge>();
  32. script.currentPlayerIndex = currentPlayerIndex;
  33. }
  34. void NextPlayerFinal() {
  35. NextPlayer();
  36. BanBowReady();
  37. AddReadyView();
  38. }
  39. void NextPlayer() {
  40. currentPlayerIndex++;
  41. currentPlayerIndex %= 2;
  42. singleShootReadyTime = singleShootReadyTimeMax;
  43. }
  44. public override void Update() {
  45. base.Update();
  46. if (gameMgr.gameOver || pauseTimeCounting) return;
  47. singleShootReadyTime -= Time.deltaTime;
  48. if (singleShootReadyTime <= 0) {
  49. //切换玩家
  50. ArmBow.ins.readyShoot();
  51. NextPlayerFinal();
  52. }
  53. }
  54. //localPK interface
  55. public int GetCurrentPlayIndex() {
  56. return currentPlayerIndex;
  57. }
  58. public (float, float) GetSingleShootReadyTime() {
  59. return (singleShootReadyTime, singleShootReadyTimeMax);
  60. }
  61. HunterGamePlayerScoreCounter hunterGamePlayerScoreCounter;
  62. public HunterGamePlayerScoreCounter getHunterGamePlayerScoreCounter() {
  63. return hunterGamePlayerScoreCounter;
  64. }
  65. }
  66. public interface ChallengeGameModeLocalPK {
  67. public int GetCurrentPlayIndex();
  68. //获取单次射击的准备时间/准备时间上限(就是当前玩家的操作倒计时)
  69. public (float, float) GetSingleShootReadyTime();
  70. public HunterGamePlayerScoreCounter getHunterGamePlayerScoreCounter();
  71. }