提交 651e410e 编写于 作者: T tanghai

Unity自带的同步上下文timescale为0的时候不会某些await不会回调,用OneThreadSynchronizationContenx替换

上级 b5d55d7b
{ "_t" : "StartConfig", "_id" : NumberLong("98547768819754"), "components" : [{ "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10002, "Host2" : null }, { "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "HttpConfig", "Url" : "", "AppId" : 0, "AppKey" : "", "ManagerSystemUrl" : "" }, { "_t" : "DBConfig", "ConnectionString" : null, "DBName" : null }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }
{ "_t" : "StartConfig", "_id" : NumberLong("98547768819754"), "components" : [{ "_t" : "OuterConfig", "Host" : "127.0.0.1", "Port" : 10002, "Host2" : "127.0.0.1" }, { "_t" : "InnerConfig", "Host" : "127.0.0.1", "Port" : 20000 }, { "_t" : "HttpConfig", "Url" : "", "AppId" : 0, "AppKey" : "", "ManagerSystemUrl" : "" }, { "_t" : "DBConfig", "ConnectionString" : null, "DBName" : null }], "AppId" : 1, "AppType" : "AllServer", "ServerIP" : "*" }
......@@ -56,6 +56,7 @@
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Object.cs" Link="Base\Object\Object.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ObjectPool.cs" Link="Base\Object\ObjectPool.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ObjectSystemAttribute.cs" Link="Base\Object\ObjectSystemAttribute.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\OneThreadSynchronizationContext.cs" Link="Base\OneThreadSynchronizationContext.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\QueueDictionary.cs" Link="Base\QueueDictionary.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\TryLocker.cs" Link="Base\TryLocker.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\UnOrderMultiMap.cs" Link="Base\UnOrderMultiMap.cs" />
......
fileFormatVersion: 2
guid: fcb4a65fef4e05448a17ace64a0658dd
timeCreated: 1519875927
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Threading;
using UnityEngine;
namespace Model
{
public class Init : MonoBehaviour
{
private readonly OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext();
private async void Start()
{
try
......@@ -14,6 +17,8 @@ namespace Model
Log.Warning($"当前版本:{Application.unityVersion}, 最好使用运行指南推荐版本!");
}
SynchronizationContext.SetSynchronizationContext(this.contex);
DontDestroyOnLoad(gameObject);
Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);
......@@ -50,6 +55,7 @@ namespace Model
private void Update()
{
this.contex.Update();
Game.Hotfix.Update?.Invoke();
Game.EventSystem.Update();
}
......
......@@ -161,6 +161,9 @@ namespace Model
await this.sendBuffer.ReadAsync(stream);
}
}
catch (ObjectDisposedException)
{
}
catch (Exception e)
{
Log.Error(e.ToString());
......@@ -186,7 +189,7 @@ namespace Model
}
int n = await this.recvBuffer.WriteAsync(stream);
if (n == 0)
{
this.OnError(this, SocketError.NetworkReset);
......@@ -207,6 +210,9 @@ namespace Model
}
}
}
catch (ObjectDisposedException)
{
}
catch (Exception e)
{
Log.Error(e.ToString());
......
......@@ -175,6 +175,7 @@
<Compile Include="Assets\Scripts\Base\Object\Object.cs" />
<Compile Include="Assets\Scripts\Base\Object\ObjectPool.cs" />
<Compile Include="Assets\Scripts\Base\Object\ObjectSystemAttribute.cs" />
<Compile Include="Assets\Scripts\Base\OneThreadSynchronizationContext.cs" />
<Compile Include="Assets\Scripts\Base\QueueDictionary.cs" />
<Compile Include="Assets\Scripts\Base\TryLocker.cs" />
<Compile Include="Assets\Scripts\Base\UnOrderMultiMap.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册