1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System.Collections;
- using System.Collections.Generic;
- using Api;
- using Message;
- using Plugins.CxShine.page;
- using UI;
- using UI.BattleRequest;
- using UnityEngine;
- public class BattleRequestReceivedComp : MonoBehaviour
- {
- public GameObject ItemLayout;
- public GameObject ItemPrefab;
- public GameObject PreparePagePrefab;
- // Start is called before the first frame update
- private void Start()
- {
- MessageComp.Instance.OnBattleAgree += OnBattleInviteAgree;
- MessageComp.Instance.OnBattleRequest += OnBattleRequest;
- }
- private void OnDestroy()
- {
- MessageComp.Instance.OnBattleAgree -= OnBattleInviteAgree;
- MessageComp.Instance.OnBattleRequest -= OnBattleRequest;
- HallComp.Instance.OnLoadingCloseAction += OnCancelInvite;
- }
- private void OnCancelInvite()
- {
- }
- private void OnBattleInviteAgree(int enemyId,MsgContent msgContent)
- {
-
- OpenPreparePage(msgContent.battleSession, enemyId);
- }
- private void OnBattleRequest(int enemyId,MsgContent msgContent)
- {
- Debug.Log("收到对战请求");
- if (BattleInviteManager.Instance.isAlreayHasPeople(msgContent.invitePlayer.playerId))
- {
- return;
- }
- BattleInviteManager.Instance.AddPlayerId(msgContent.invitePlayer.playerId);
- var o = Instantiate(ItemPrefab, ItemLayout.GetComponent<Transform>(), false);
- o.GetComponent<BqItemComp>().init(msgContent.invitePlayer,
- enemy =>
- {
- ApiComp.Instance.AgreeBattle(msgContent.battleSession);
- string enemyName = msgContent.invitePlayer.name;
- OpenPreparePage(msgContent.battleSession, enemyId);
- },
- (invitePlayer) => { BattleInviteManager.Instance.RemoveInvitePlayerId(msgContent.invitePlayer.playerId); });
- o.SetActive(true);
- }
- private void OpenPreparePage(string battleSession, int enemyId)
- {
- if (BattleInviteManager.Instance.isPrepareOpening())
- {
- return;
- }
- BattleInviteManager.Instance.Open(PreparePagePrefab, battleSession, enemyId);
- }
- }
|