From 78bba402a1f23f6d56b32611393eaf84f0eb7f6c Mon Sep 17 00:00:00 2001 From: chenxiangxue <910695411@qq.com> Date: Thu, 11 Jul 2024 13:16:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Scripts/cxx/CallForTest.cs | 16 +++++++++++----- .../Assets/Scripts/wj/Manager/ApiManager.cs | 2 +- .../Assets/StreamingAssets/Port.txt | 1 + .../Assets/StreamingAssets/Port.txt.meta | 7 +++++++ .../Assets/StreamingAssets/method.txt | 1 + 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 BulkCargo_UnityProject/Assets/StreamingAssets/Port.txt create mode 100644 BulkCargo_UnityProject/Assets/StreamingAssets/Port.txt.meta diff --git a/BulkCargo_UnityProject/Assets/Scripts/cxx/CallForTest.cs b/BulkCargo_UnityProject/Assets/Scripts/cxx/CallForTest.cs index 0e215b0e..8800fa56 100644 --- a/BulkCargo_UnityProject/Assets/Scripts/cxx/CallForTest.cs +++ b/BulkCargo_UnityProject/Assets/Scripts/cxx/CallForTest.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Runtime.InteropServices; using UnityEngine; @@ -36,6 +37,10 @@ public class CallForTest : MonoBehaviour /// 启动器传过来的服务器IP /// public string ServerIP; + /// + /// 服务器端口设置 + /// + public int ServerPort; [DllImport("user32.dll", EntryPoint = "FindWindow")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); @@ -48,13 +53,14 @@ public class CallForTest : MonoBehaviour instance = this; DontDestroyOnLoad(gameObject); - //#if UNITY_EDITOR - // Debug.unityLogger.logEnabled = true; - //#else - // Debug.unityLogger.logEnabled = false; - //#endif Debug.Log(Application.productName); + using (StreamReader _reader = new StreamReader(Application.streamingAssetsPath + "/Port.txt")) + { + ServerPort = int.Parse(_reader.ReadLine()); + Debug.Log("端口配置:" + ServerPort); + } + IntPtr ptr = FindWindow(null, Application.productName); SetWindowPos(ptr, (IntPtr)HWND_TOPMOST, 0, 0, Screen.width, Screen.height, SWP_SHOWWINDOW); } diff --git a/BulkCargo_UnityProject/Assets/Scripts/wj/Manager/ApiManager.cs b/BulkCargo_UnityProject/Assets/Scripts/wj/Manager/ApiManager.cs index 4e9503d5..04d3b4b5 100644 --- a/BulkCargo_UnityProject/Assets/Scripts/wj/Manager/ApiManager.cs +++ b/BulkCargo_UnityProject/Assets/Scripts/wj/Manager/ApiManager.cs @@ -27,7 +27,7 @@ public class ApiManager : Singleton if (!Application.isEditor) { //发布出来 - return "http://" + CallForTest.instance.ServerIP + ":4000"; + return "http://" + CallForTest.instance.ServerIP + ":"+CallForTest.instance.ServerPort; } else { diff --git a/BulkCargo_UnityProject/Assets/StreamingAssets/Port.txt b/BulkCargo_UnityProject/Assets/StreamingAssets/Port.txt new file mode 100644 index 00000000..a2113715 --- /dev/null +++ b/BulkCargo_UnityProject/Assets/StreamingAssets/Port.txt @@ -0,0 +1 @@ +4000 \ No newline at end of file diff --git a/BulkCargo_UnityProject/Assets/StreamingAssets/Port.txt.meta b/BulkCargo_UnityProject/Assets/StreamingAssets/Port.txt.meta new file mode 100644 index 00000000..80f136b2 --- /dev/null +++ b/BulkCargo_UnityProject/Assets/StreamingAssets/Port.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 26dd212f0d5cecf408706c553b82a106 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/BulkCargo_UnityProject/Assets/StreamingAssets/method.txt b/BulkCargo_UnityProject/Assets/StreamingAssets/method.txt index e69de29b..c2270834 100644 --- a/BulkCargo_UnityProject/Assets/StreamingAssets/method.txt +++ b/BulkCargo_UnityProject/Assets/StreamingAssets/method.txt @@ -0,0 +1 @@ +0 \ No newline at end of file