| using UnityEngine; | 
| using System; | 
| using System.Collections; | 
| using System.Collections.Generic; | 
| using vnxbqy.UI; | 
| using System.Net; | 
| using System.Net.Sockets; | 
| using System.Threading; | 
| using UnityEditor; | 
|   | 
|   | 
| public class CrossServerTest : EditorWindow | 
| { | 
|   | 
|     public static string crossServerAccount { | 
|         get { return LocalSave.GetString("CrossServerAccount"); } | 
|         set { LocalSave.SetString("CrossServerAccount", value); } | 
|     } | 
|   | 
|     public static int crossServerId { | 
|         get { return LocalSave.GetInt("CrossServerId", 23); } | 
|         set { LocalSave.SetInt("CrossServerId", value); } | 
|     } | 
|   | 
|     public static string crossServerIp { | 
|         get { return LocalSave.GetString("CrossServerIp"); } | 
|         set { LocalSave.SetString("CrossServerIp", value); } | 
|     } | 
|   | 
|     public bool autoOneVsOneMatch = false; | 
|   | 
|     [MenuItem("程序/跨服")] | 
|     public static void Open() | 
|     { | 
|         var window = GetWindow<CrossServerTest>(false, "跨服"); | 
|         window.Show(); | 
|         window.autoRepaintOnSceneChange = true; | 
|     } | 
|   | 
|     public static void DisconnectCrossServer() | 
|     { | 
|         GameNetSystem.Instance.DisconnectCrossServer(); | 
|     } | 
|   | 
|     private void Update() | 
|     { | 
|         if (autoOneVsOneMatch) | 
|         { | 
|             AutoCrossServerOneVsOneMatching(); | 
|         } | 
|     } | 
|   | 
|     private void OnGUI() | 
|     { | 
|         EditorGUILayout.Space(); | 
|   | 
|         if (EditorApplication.isPlaying) | 
|         { | 
|             EditorGUILayout.BeginHorizontal(); | 
|             EditorGUILayout.Toggle("主服链接状态", GameNetSystem.Instance.mainSocketConnected); | 
|             EditorGUILayout.Toggle("跨服链接状态", GameNetSystem.Instance.crossServerSocketConnected); | 
|             EditorGUILayout.EndHorizontal(); | 
|         } | 
|   | 
|         EditorGUILayout.Space(); | 
|         crossServerAccount = EditorGUILayout.TextField("跨服账号:", crossServerAccount); | 
|         crossServerId = EditorGUILayout.IntField("跨服服务器id:", crossServerId); | 
|         crossServerIp = EditorGUILayout.TextField("跨服ip:", crossServerIp); | 
|   | 
|         EditorGUILayout.Space(); | 
|         EditorGUILayout.Space(); | 
|         EditorGUILayout.BeginHorizontal(); | 
|   | 
|         if (GUILayout.Button("断开")) | 
|         { | 
|             DisconnectCrossServer(); | 
|         } | 
|   | 
|         EditorGUILayout.EndHorizontal(); | 
|   | 
|         EditorGUILayout.Space(); | 
|   | 
|         EditorGUILayout.BeginHorizontal(); | 
|         if (GUILayout.Button("匹配")) | 
|         { | 
|             var match = new CC101_tagCMCrossRealmPKMatch(); | 
|             match.Type = 1; | 
|             GameNetSystem.Instance.SendInfo(match); | 
|         } | 
|   | 
|         if (GUILayout.Button("取消")) | 
|         { | 
|             var match = new CC101_tagCMCrossRealmPKMatch(); | 
|             match.Type = 0; | 
|             GameNetSystem.Instance.SendInfo(match); | 
|         } | 
|   | 
|         EditorGUILayout.EndHorizontal(); | 
|   | 
|         EditorGUILayout.Space(); | 
|         EditorGUILayout.BeginHorizontal(); | 
|         if (GUILayout.Button("退出跨服")) | 
|         { | 
|             var match = new CC104_tagCMExitCrossRealm(); | 
|             GameNetSystem.Instance.SendToCrossServer(match); | 
|         } | 
|   | 
|         if (GUILayout.Button("强制退出跨服")) | 
|         { | 
|             var sendInfo = new CC003_tagCGForceQuitCrossState(); | 
|             GameNetSystem.Instance.SendInfo(sendInfo); | 
|         } | 
|   | 
|         EditorGUILayout.EndHorizontal(); | 
|         autoOneVsOneMatch = EditorGUILayout.Toggle("自动匹配", autoOneVsOneMatch); | 
|   | 
|         EditorGUILayout.Space(); | 
|         EditorGUILayout.BeginHorizontal(); | 
|         if (GUILayout.Button("开始客户端PK")) | 
|         { | 
|             ClientCrossServerOneVsOne.JiaMatchOk(); | 
|             ClientCrossServerOneVsOne.StartClientCrossServerOneVsOne(); | 
|         } | 
|   | 
|         if (GUILayout.Button("退出客户端PK")) | 
|         { | 
|             ClientCrossServerOneVsOne.StopClientCrossServerOneVsOne(); | 
|         } | 
|   | 
|         EditorGUILayout.EndHorizontal(); | 
|     } | 
|   | 
|     CrossServerOneVsOneModel oneVsOneModel { get { return ModelCenter.Instance.GetModel<CrossServerOneVsOneModel>(); } } | 
|     float timer = 0f; | 
|   | 
|     private void AutoCrossServerOneVsOneMatching() | 
|     { | 
|         timer += Time.deltaTime; | 
|         if (timer < 5f) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         timer = 0f; | 
|   | 
|         if (StageLoad.Instance.isLoading) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         var mapId = PlayerDatas.Instance.baseData.MapID; | 
|         var config = MapConfig.Get(mapId); | 
|         if (config == null) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         if (config.MapFBType != (int)MapType.OpenCountry) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         if (oneVsOneModel.IsMatching) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         if (CrossServerLogin.Instance.IsEnterCrossServerPreparing()) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         if (CrossServerLogin.Instance.busy) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         oneVsOneModel.SendCrossMatch(1); | 
|     } | 
|   | 
| } |