From cee0f3d5cbdcd22778c5d71594039b89f6e154c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=90=8D?= <3077614386@qq.com> Date: Sat, 25 Nov 2023 12:34:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/StreamingAssets/IPPort.txt | 1 + Assets/StreamingAssets/IPPort.txt.meta | 7 +++ Assets/Zion/Scenes/InitConnect.unity | 13 ++++++ Assets/Zion/Scripts/AddConfing.cs | 60 +++++++++++++++++++++++++ Assets/Zion/Scripts/AddConfing.cs.meta | 11 +++++ Assets/Zion/Scripts/InterfaceManager.cs | 24 ++++++++-- 6 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 Assets/StreamingAssets/IPPort.txt create mode 100644 Assets/StreamingAssets/IPPort.txt.meta create mode 100644 Assets/Zion/Scripts/AddConfing.cs create mode 100644 Assets/Zion/Scripts/AddConfing.cs.meta diff --git a/Assets/StreamingAssets/IPPort.txt b/Assets/StreamingAssets/IPPort.txt new file mode 100644 index 00000000..f09e5924 --- /dev/null +++ b/Assets/StreamingAssets/IPPort.txt @@ -0,0 +1 @@ +111.229.30.246:48888 \ No newline at end of file diff --git a/Assets/StreamingAssets/IPPort.txt.meta b/Assets/StreamingAssets/IPPort.txt.meta new file mode 100644 index 00000000..652274ef --- /dev/null +++ b/Assets/StreamingAssets/IPPort.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: bd6e81e1f70f9cd4882885d83be5028e +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Zion/Scenes/InitConnect.unity b/Assets/Zion/Scenes/InitConnect.unity index b2520436..06fd75c9 100644 --- a/Assets/Zion/Scenes/InitConnect.unity +++ b/Assets/Zion/Scenes/InitConnect.unity @@ -218,6 +218,7 @@ GameObject: m_Component: - component: {fileID: 2132962759} - component: {fileID: 2132962758} + - component: {fileID: 2132962760} m_Layer: 0 m_Name: Net m_TagString: Untagged @@ -255,3 +256,15 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2132962760 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2132962757} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7849c2de1b8e12e478bd7b1e0af1e553, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Zion/Scripts/AddConfing.cs b/Assets/Zion/Scripts/AddConfing.cs new file mode 100644 index 00000000..5eb2cb4f --- /dev/null +++ b/Assets/Zion/Scripts/AddConfing.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using UnityEngine; +using UnityEngine.Networking; +using static InterfaceManager; + +public class AddConfing : MonoBehaviour +{ + private static string ipSetting = "IPPort.txt"; + + + private void Awake() + { + StartCoroutine(GetSetting(ipSetting, (data) => + { + string[] datas= data.ToString().Split(':'); + //Debug.Log(IP); + //Debug.Log(Port); + //Debug.Log(Url_Action); + IP = datas[0]; + Port = datas[1]; + //Debug.Log(IP); + //Debug.Log(Port); + //Debug.Log(Url_Action); + })); + } + + + + /// + /// 获取配置文件 + /// + /// + /// + /// + public static IEnumerator GetSetting(string _settings, Action callback) + { + string _url = Path.Combine(Application.streamingAssetsPath, _settings); + UnityWebRequest www = UnityWebRequest.Get(_url); + yield return www.SendWebRequest(); + if (www.isNetworkError || www.isHttpError) + { + callback(null); + Debug.Log("网络请求失败了"); + } + else + { + if (!string.IsNullOrEmpty(www.downloadHandler.text)) + { + callback(www.downloadHandler.text); + } + else + { + callback(null); + } + } + } +} diff --git a/Assets/Zion/Scripts/AddConfing.cs.meta b/Assets/Zion/Scripts/AddConfing.cs.meta new file mode 100644 index 00000000..b9820680 --- /dev/null +++ b/Assets/Zion/Scripts/AddConfing.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7849c2de1b8e12e478bd7b1e0af1e553 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Zion/Scripts/InterfaceManager.cs b/Assets/Zion/Scripts/InterfaceManager.cs index 3ab8e815..87d0d25f 100644 --- a/Assets/Zion/Scripts/InterfaceManager.cs +++ b/Assets/Zion/Scripts/InterfaceManager.cs @@ -8,9 +8,27 @@ using Newtonsoft.Json.Linq; public static class InterfaceManager { - - public static string IP { get => "111.229.30.246"; } - public static string Port { get => "48888"; } + + private static string _IP = "111.229.30.246"; + public static string IP + { + get { return _IP; } + set + { + if (_IP != value) + _IP = value; + } + } + private static string _Port = "48888"; + public static string Port + { + get { return _Port; } + set + { + if (_Port != value) + _Port = value; + } + } public static string IpAddress { get => string.Format("http://{0}:{1}", IP, Port); }