Skip to content

Commit 97526e5

Browse files
committed
[+] Fix Network Thread bug:Call network msg callback in main thread
1 parent 46a9862 commit 97526e5

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

Unity/Assets/Scenes/Demo.unity

0 Bytes
Binary file not shown.

Unity/Assets/Scripts/Logic/EntityComponent/Component/CAnimator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
using Lockstep.Game;
77
using Lockstep.UnityExt;
88
using Debug = Lockstep.Logging.Debug;
9-
109
#if UNITY_5_3_OR_NEWER
1110
using HideInInspector = UnityEngine.HideInInspector;
11+
1212
#endif
1313

1414
namespace Lockstep.Game {

Unity/Assets/Scripts/Logic/Framework/Base/BaseEntity.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public partial class BaseEntity : BaseLifeCycle, IEntity, ILPTriggerEventHandler
2222

2323
[ReRefBackup] public IEntityView EntityView;
2424

25-
public LVector3 prePos3;
26-
public LFloat preDeg;
25+
26+
2727

2828
public T GetService<T>() where T : IService{
2929
return ServiceContainer.GetService<T>();

Unity/Assets/Scripts/Logic/Framework/Launcher.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Linq;
33
using System.Reflection;
4+
using System.Threading;
45
using Lockstep.Math;
56
using Lockstep.Util;
67
using Lockstep.Game;
8+
using Lockstep.Network;
79
using NetMsg.Common;
810
using UnityEngine;
911
using Debug = UnityEngine.Debug;
@@ -38,8 +40,10 @@ public class Launcher : ILifeCycle {
3840
public bool IsClientMode => _constStateService.IsClientMode;
3941

4042
public object transform;
41-
43+
private OneThreadSynchronizationContext _syncContext;
4244
public void DoAwake(IServiceContainer services){
45+
_syncContext = new OneThreadSynchronizationContext();
46+
SynchronizationContext.SetSynchronizationContext(_syncContext);
4347
Utils.StartServices();
4448
if (Instance != null) {
4549
Debug.LogError("LifeCycle Error: Awake more than once!!");
@@ -126,6 +130,7 @@ public void _DoStart(){
126130
}
127131

128132
public void DoUpdate(float fDeltaTime){
133+
_syncContext.Update();
129134
Utils.UpdateServices();
130135
var deltaTime = fDeltaTime.ToLFloat();
131136
_networkService.DoUpdate(deltaTime);

0 commit comments

Comments
 (0)