|
|
@@ -14,10 +14,10 @@ public class PKMatchingView : MonoBehaviour
|
|
|
SocketPlayer socketPlayer;
|
|
|
|
|
|
//邀请者需要输入的信息
|
|
|
- public PKFriendInfoPack pkFriendInfoPack = null;
|
|
|
+ [NonSerialized] public int targetInvitePlayerID;
|
|
|
[NonSerialized] public bool isFriendPKInviter;
|
|
|
//被邀请者需要输入的信息
|
|
|
- [NonSerialized] public int targetJoinRoomID;
|
|
|
+ [NonSerialized] public string targetJoinRoomKey;
|
|
|
[NonSerialized] public bool isFriendPKInvitee;
|
|
|
|
|
|
public static PKMatchingView Create() {
|
|
|
@@ -34,6 +34,7 @@ public class PKMatchingView : MonoBehaviour
|
|
|
|
|
|
public void OnDestroy() {
|
|
|
if (ins == this) ins = null;
|
|
|
+ PKComp.ins.cancelRandomMatch();
|
|
|
}
|
|
|
|
|
|
void Start()
|
|
|
@@ -48,90 +49,46 @@ public class PKMatchingView : MonoBehaviour
|
|
|
} else {
|
|
|
RenderTip("正在搜索实力相当的对手···");
|
|
|
}
|
|
|
+
|
|
|
+ if (isFriendPKInviter) {
|
|
|
+ PKComp.ins.inviteFriendGamePK(targetInvitePlayerID);
|
|
|
+ } else if (isFriendPKInvitee) {
|
|
|
+ PKComp.ins.acceptFriendGamePK(targetJoinRoomKey);
|
|
|
+ } else {
|
|
|
+ PKComp.ins.randomMatch();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void EnterGameSceneOnMatchSuccess() {
|
|
|
+ int otherIndex = (GlobalData.playerIndexInRoom + 1) % 2;
|
|
|
+ MatchPlayerInfo info = GlobalData.matchPlayerInfos[otherIndex];
|
|
|
+ RenderPlayerInfo(2, RoleMgr.GetAvatar(info.avatarID), info.nickname, true);
|
|
|
+ RenderTip("匹配成功,即将开始游戏!");
|
|
|
+ HideBtnBack();
|
|
|
+ PauseWaitingTime();
|
|
|
+ JC.Unity.CoroutineStarter.Start(LoadSceneOnEnterGame());
|
|
|
+ }
|
|
|
|
|
|
- socketPlayer = new GameObject("SocketPlayer").AddComponent<SocketPlayer>();
|
|
|
- socketPlayer.onLoad_ = () => {
|
|
|
- socketPlayer.UploadPlayerInfo();
|
|
|
- if (isFriendPKInviter) {
|
|
|
- socketPlayer.CreateFriendPKRoom();
|
|
|
- } else if (isFriendPKInvitee) {
|
|
|
- socketPlayer.JoinFriendPKRoom(targetJoinRoomID);
|
|
|
- } else {
|
|
|
- socketPlayer.RandomMatchRoom();
|
|
|
- }
|
|
|
- };
|
|
|
- socketPlayer.onCreateFriendPKRoom = (roomID) => {
|
|
|
- UserPlayer.ins.call("friendComp.invitePK",
|
|
|
- pkFriendInfoPack.id, pkFriendInfoPack.avatarID, pkFriendInfoPack.nickname,
|
|
|
- roomID, GlobalData.matchRoomType
|
|
|
- );
|
|
|
- };
|
|
|
- socketPlayer.onMatchSuccess = () => {
|
|
|
- int otherIndex = (GlobalData.playerIndexInRoom + 1) % 2;
|
|
|
- MatchPlayerInfo info = GlobalData.matchPlayerInfos[otherIndex];
|
|
|
- (Sprite avatar, string nickname) = RoleMgr.GetRoleInfo(info.avatarID);
|
|
|
- nickname = info.nickname;
|
|
|
- RenderPlayerInfo(2, avatar, nickname, true);
|
|
|
- RenderTip("匹配成功,即将开始游戏!");
|
|
|
- HideBtnBack();
|
|
|
- PauseWaitingTime();
|
|
|
- socketPlayer.AgreeStartGame();
|
|
|
- };
|
|
|
- socketPlayer.onAgreeStartGame = () => {
|
|
|
- DontDestroyOnLoad(socketPlayer);
|
|
|
- toLoadGame = true;
|
|
|
- };
|
|
|
- socketPlayer.onDestroy_ += () => {
|
|
|
- if (this && this.gameObject) {
|
|
|
- Destroy(this.gameObject);
|
|
|
- Destroy(socketPlayer.gameObject);
|
|
|
- PopupMgr.ins.ShowBGTip("网络发生意外!");
|
|
|
- }
|
|
|
- };
|
|
|
+ IEnumerator LoadSceneOnEnterGame() {
|
|
|
+ yield return new WaitForSecondsRealtime(1);
|
|
|
+ GameMgr.gameType = GlobalData.matchGameType;
|
|
|
+ if (GameMgr.gameType == 9) {
|
|
|
+ SceneManager.LoadScene("Game", LoadSceneMode.Single);
|
|
|
+ } else {
|
|
|
+ SceneManager.LoadScene("GameChallenge", LoadSceneMode.Single);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//通过此方法,不需要经过匹配页面进行匹配,可以直接在游戏场景匹配,方便测试
|
|
|
public static void MoniMatchForTestInGameScene(Action onAgreeStartGame) {
|
|
|
- SocketPlayer socketPlayer = new GameObject("SocketPlayer").AddComponent<SocketPlayer>();
|
|
|
- socketPlayer.onLoad_ = () => {
|
|
|
- socketPlayer.UploadPlayerInfo();
|
|
|
- socketPlayer.RandomMatchRoom();
|
|
|
- };
|
|
|
- socketPlayer.onMatchSuccess = () => {
|
|
|
- socketPlayer.AgreeStartGame();
|
|
|
- };
|
|
|
- socketPlayer.onAgreeStartGame = () => {
|
|
|
- DontDestroyOnLoad(socketPlayer);
|
|
|
- if (onAgreeStartGame != null) onAgreeStartGame();
|
|
|
- };
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- bool toLoadGame = false;
|
|
|
- float loadGameSceneCountdown = 1;
|
|
|
void Update() {
|
|
|
if (waitingTime >= 0) {
|
|
|
waitingTime += Time.deltaTime;
|
|
|
this.transform.Find("BoxRight/TimeBG").GetComponentInChildren<Text>().text = TimeUtil.GetTimeStr(waitingTime, false);
|
|
|
}
|
|
|
- if (toLoadGame) {
|
|
|
- loadGameSceneCountdown -= Time.deltaTime;
|
|
|
- if (loadGameSceneCountdown <= 0) {
|
|
|
- toLoadGame = false;
|
|
|
- //loadscene
|
|
|
- if (GlobalData.matchRoomType == 0) {
|
|
|
- GameMgr.gameType = 9;
|
|
|
- SceneManager.LoadScene("Game", LoadSceneMode.Single);
|
|
|
- }
|
|
|
- //challenge-game
|
|
|
- int[] roomTypes = {1, 2, 3};
|
|
|
- int[] gameTypes = {10, 11, 12};
|
|
|
- int curIndex = Array.IndexOf(roomTypes, GlobalData.matchRoomType);
|
|
|
- if (curIndex >= 0) {
|
|
|
- GameMgr.gameType = gameTypes[curIndex];
|
|
|
- SceneManager.LoadScene("GameChallenge", LoadSceneMode.Single);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
void PauseWaitingTime() {
|
|
|
@@ -166,14 +123,3 @@ public class PKMatchingView : MonoBehaviour
|
|
|
Destroy(socketPlayer.gameObject);
|
|
|
}
|
|
|
}
|
|
|
-public class PKFriendInfoPack {
|
|
|
- public int id;
|
|
|
- public int avatarID;
|
|
|
- public string nickname = "";
|
|
|
- public PKFriendInfoPack() {}
|
|
|
- public PKFriendInfoPack(int id, int avatarID, string nickname) {
|
|
|
- this.id = id;
|
|
|
- this.avatarID = avatarID;
|
|
|
- this.nickname = nickname;
|
|
|
- }
|
|
|
-}
|