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(), false); o.GetComponent().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); } }