RabbitHuntGameMode_LocalPK.cs 2.1 KB

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