BattleRequestReceivedComp.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Api;
  4. using Message;
  5. using Plugins.CxShine.page;
  6. using UI;
  7. using UI.BattleRequest;
  8. using UnityEngine;
  9. public class BattleRequestReceivedComp : MonoBehaviour
  10. {
  11. public GameObject ItemLayout;
  12. public GameObject ItemPrefab;
  13. public GameObject PreparePagePrefab;
  14. // Start is called before the first frame update
  15. private void Start()
  16. {
  17. MessageComp.Instance.OnBattleAgree += OnBattleInviteAgree;
  18. MessageComp.Instance.OnBattleRequest += OnBattleRequest;
  19. }
  20. private void OnDestroy()
  21. {
  22. MessageComp.Instance.OnBattleAgree -= OnBattleInviteAgree;
  23. MessageComp.Instance.OnBattleRequest -= OnBattleRequest;
  24. HallComp.Instance.OnLoadingCloseAction += OnCancelInvite;
  25. }
  26. private void OnCancelInvite()
  27. {
  28. }
  29. private void OnBattleInviteAgree(int enemyId,MsgContent msgContent)
  30. {
  31. OpenPreparePage(msgContent.battleSession, enemyId);
  32. }
  33. private void OnBattleRequest(int enemyId,MsgContent msgContent)
  34. {
  35. Debug.Log("收到对战请求");
  36. if (BattleInviteManager.Instance.isAlreayHasPeople(msgContent.invitePlayer.playerId))
  37. {
  38. return;
  39. }
  40. BattleInviteManager.Instance.AddPlayerId(msgContent.invitePlayer.playerId);
  41. var o = Instantiate(ItemPrefab, ItemLayout.GetComponent<Transform>(), false);
  42. o.GetComponent<BqItemComp>().init(msgContent.invitePlayer,
  43. enemy =>
  44. {
  45. ApiComp.Instance.AgreeBattle(msgContent.battleSession);
  46. string enemyName = msgContent.invitePlayer.name;
  47. OpenPreparePage(msgContent.battleSession, enemyId);
  48. },
  49. (invitePlayer) => { BattleInviteManager.Instance.RemoveInvitePlayerId(msgContent.invitePlayer.playerId); });
  50. o.SetActive(true);
  51. }
  52. private void OpenPreparePage(string battleSession, int enemyId)
  53. {
  54. if (BattleInviteManager.Instance.isPrepareOpening())
  55. {
  56. return;
  57. }
  58. BattleInviteManager.Instance.Open(PreparePagePrefab, battleSession, enemyId);
  59. }
  60. }