网络连接兼容socket和ws

This commit is contained in:
fatiao 2025-03-07 17:40:50 +08:00
parent 4002cbd452
commit 64adbabfab
3 changed files with 44 additions and 7 deletions

View File

@ -125,6 +125,15 @@ public class SocketConn
#endif
}
/*
gate端口规则
1. Editor模式使用ip和固定端口6411
2. WebGL包使用http和ws协议的使ip和端口6412
3. WebGL包使用https和wss协议的使4430
serverlist端口规则
1. ip+使 6410
2. 使https默认端口443
*/
public bool Connect(string host, int port, float timeout = 1f)
{
if (mSocketState != enSocketState.Disconnected)
@ -152,7 +161,7 @@ public class SocketConn
string address = "";
if (CommonUtil.IsValidIPv4(host))
{
address = string.Format("ws://{0}:{1}", host, port);
address = string.Format("ws://{0}:{1}", host, 6412);
}
else
{
@ -170,6 +179,8 @@ public class SocketConn
mLastPort = port;
m_fBeginConnectTime = Time.realtimeSinceStartup;
#else
// Editor 模式固定端口 6411
port = 6411;
mSocket = new Socket(newAddressFamily, SocketType.Stream, ProtocolType.Tcp);
IPAddress addr = IPAddress.Parse(newServerIp);
IPEndPoint endpoint = new IPEndPoint(addr, port);

View File

@ -1454,7 +1454,9 @@ public class AssetsMgr : SingletonMono<AssetsMgr>
yield break;
}
int loadCount = 0;
List<RuntimeAnimatorController> racs = new List<RuntimeAnimatorController>();
Dictionary<string, RuntimeAnimatorController> assetDict = new Dictionary<string, RuntimeAnimatorController>();
string path = "";
for (int i = 0; i < assetName.Length; ++i)
{
@ -1470,11 +1472,20 @@ public class AssetsMgr : SingletonMono<AssetsMgr>
}
//RuntimeAnimatorController rac = UnityEditor.AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>(path);
var handle = Addressables.LoadAssetAsync<RuntimeAnimatorController>(path);
yield return handle;
racs.Add(handle.Result);
var currAssetName = assetName[i];
Addressables.LoadAssetAsync<RuntimeAnimatorController>(path).Completed += handle =>
{
assetDict[currAssetName] = handle.Result;
loadCount++;
};
}
}
while (loadCount < assetName.Length) { yield return null; }
for (int i = 0; i < assetName.Length; ++i)
{
racs.Add(assetDict[assetName[i]]);
}
if (Application.isPlaying)
yield return new WaitForEndOfFrame();
callback.DynamicInvoke(racs, seqId, pathName, assetName);
@ -1482,6 +1493,8 @@ public class AssetsMgr : SingletonMono<AssetsMgr>
else if (typeof(T).Equals(typeof(List<AudioClip>)))
{
List<AudioClip> gos = new List<AudioClip>();
int loadCount = 0;
Dictionary<string, AudioClip> dict = new Dictionary<string, AudioClip>();
for (int i = 0; i < assetName.Length; ++i)
{
if (!string.IsNullOrEmpty(assetName[i]))
@ -1496,11 +1509,19 @@ public class AssetsMgr : SingletonMono<AssetsMgr>
}
//AudioClip ac = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>(path);
var handle = Addressables.LoadAssetAsync<AudioClip>(path);
yield return handle;
gos.Add(handle.Result);
var currAssetName = assetName[i];
Addressables.LoadAssetAsync<AudioClip>(path).Completed += handle =>
{
dict[currAssetName] = handle.Result;
loadCount++;
};
}
}
while (loadCount < assetName.Length) { yield return null; }
for (int i = 0; i < assetName.Length; ++i)
{
gos.Add(dict[assetName[i]]);
}
if (Application.isPlaying)
yield return new WaitForEndOfFrame();

View File

@ -54,9 +54,14 @@ public class LuaMgr : SingletonMono<LuaMgr>
{
var tolua_zip_data = await AssetsMgr.Instance.LoadLocalFileData(Application.streamingAssetsPath + "/" + Constants.LuaDirMergeFile);
UnzipLuaFiles(tolua_zip_data);
GC.Collect();
long before = GC.GetTotalMemory(true);
var lua_zip_data = await AssetsMgr.Instance.LoadLocalFileData(Application.streamingAssetsPath + "/" + Constants.LuaLogicDirMergeFile);
//UnzipLuaFiles(lua_zip_data);
_luaLogicZip = CommonUtil.GetZipFile(lua_zip_data);
long after = GC.GetTotalMemory(true);
Debug.Log($"_luaLogicZip size: {before} : {after}");
var pb_zip_data = await AssetsMgr.Instance.LoadLocalFileData(Application.streamingAssetsPath + "/" + Constants.LuaPbDirMergeFile);
UnzipPbFiles(pb_zip_data);
}