RabbitHuntGameMode_LocalPK.cs 2.4 KB

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