using System.Collections.Generic; public class PKComp : Singleton { public void randomMatch() { MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo(); UserPlayer.ins.call("pkComp.randomMatch", playerInfo, GlobalData.matchGameType); } public void cancelRandomMatch() { UserPlayer.ins.call("pkComp.cancelRandomMatch", LoginMgr.myUserInfo.id); } public void inviteFriendGamePK(int targetID) { MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo(); UserPlayer.ins.call("pkComp.inviteFriendGamePK", playerInfo, GlobalData.matchGameType, targetID); } public void acceptFriendGamePK(string roomKey) { MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo(); UserPlayer.ins.call("pkComp.acceptFriendGamePK", playerInfo, roomKey); } private MatchPlayerInfo CreateMyMatchPlayerInfo() { UserInfo u = LoginMgr.myUserInfo; MatchPlayerInfo playerInfo = new MatchPlayerInfo(u.id, u.avatarID, u.nickname); return playerInfo; } //被服务端调用的接口 public void onGamePKMatchSuccess(List playerInfoList, int playerIndexInRoom, string roomKey) { GlobalData.roomKey = roomKey; GlobalData.matchPlayerInfos = playerInfoList; GlobalData.playerIndexInRoom = playerIndexInRoom; if (PKMatchingView.ins) { PKMatchingView.ins.EnterGameSceneOnMatchSuccess(); } } public void onInviteFriendGamePK(MatchPlayerInfo matchPlayerInfo, int gameType, string roomKey) { GlobalData.roomKey = roomKey; string pkTypeName = null; switch (gameType) { case 9: pkTypeName = "静止靶"; break; case 10: pkTypeName = "野兔闯关"; break; case 11: pkTypeName = "野鸡闯关"; break; case 12: pkTypeName = "野狼闯关"; break; } if (pkTypeName == null) return; string tip = $"好友邀请你参加{pkTypeName}PK"; System.Action cb = delegate() { if (!PKMatchingView.ins && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "Home") { PKMatchingView view = PKMatchingView.Create(); view.isFriendPKInvitee = true; view.targetJoinRoomKey = roomKey; GlobalData.pkMatchType = PKMatchType.OnlinePK; GlobalData.matchGameType = gameType; } else if (PKMatchingView.ins) { PopupMgr.ins.ShowTip("当前正处于匹配状态,无法接受好友PK邀请!"); } }; if (!PKMatchingView.ins && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "Home") { PopupMgr.ins.ShowPKInviteNotice(matchPlayerInfo.avatarID, matchPlayerInfo.nickname, tip, cb); } } }