public void Start() { try { string[] assemblyNames = { "Unity.Model.dll", "Unity.Hotfix.dll", "Unity.ModelView.dll", "Unity.HotfixView.dll" }; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { string assemblyName = $"{assembly.GetName().Name}.dll"; if (!assemblyNames.Contains(assemblyName)) { continue; } Game.EventSystem.Add(assembly); } ProtobufHelper.Init(); Game.Options = new Options(); Game.EventSystem.Publish(new EventType.AppStart()); } catch (Exception e) { Log.Error(e); } }
public static void SerializeTo(ushort opcode, object obj, MemoryStream memoryStream) { try { if (opcode < OpcodeRangeDefine.PbMaxOpcode) { ProtobufHelper.ToStream(obj, memoryStream); return; } if (opcode >= OpcodeRangeDefine.JsonMinOpcode) { string s = JsonHelper.ToJson(obj); byte[] bytes = s.ToUtf8(); memoryStream.Write(bytes, 0, bytes.Length); return; } #if NOT_UNITY MongoHelper.ToStream(obj, memoryStream); #else throw new Exception($"client no message: {opcode}"); #endif } catch (Exception e) { throw new Exception($"SerializeTo error: {opcode}", e); } }
private static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Log.Error(e.ExceptionObject.ToString()); }; // 异步方法全部会回掉到主线程 SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance); try { //初始化EventSystem { List <Type> types = new List <Type>(); types.AddRange(typeof(Game).Assembly.GetTypes()); types.AddRange(DllHelper.GetHotfixAssembly().GetTypes()); Game.EventSystem.AddRangeType(types); Game.EventSystem.TypeMonoInit(); Game.EventSystem.EventSystemInit(); } ProtobufHelper.Init(); MongoHelper.Init(); // 命令行参数 Options options = null; Parser.Default.ParseArguments <Options>(args) .WithNotParsed(error => throw new Exception($"命令行格式错误!")) .WithParsed(o => { options = o; }); GlobalDefine.Options = options; GlobalDefine.ILog = new NLogger(GlobalDefine.Options.AppType.ToString()); LogManager.Configuration.Variables["appIdFormat"] = $"{GlobalDefine.Options.Process:000000}"; Log.Info($"server start........................ {Game.Scene.Id}"); Game.EventSystem.Publish(new EventType.AppStart()); while (true) { try { Thread.Sleep(1); Game.Update(); Game.LateUpdate(); Game.FrameFinish(); } catch (Exception e) { Log.Error(e); } } } catch (Exception e) { Log.Error(e); } }
public static void Start() { try { Log.Info("初始化EventSystem"); { List <Type> types = new List <Type>(); types.AddRange(HotfixHelper.GetAssemblyTypes()); Game.EventSystem.AddRangeType(types); if (GlobalDefine.ILRuntimeMode) { Game.EventSystem.TypeIlrInit(); } else { Game.EventSystem.TypeMonoInit(); } Game.EventSystem.EventSystemInit(); } ProtobufHelper.Init(); GlobalDefine.Options = new Options(); Game.EventSystem.Publish(new EventType.AppStart()).Coroutine(); } catch (Exception e) { Log.Error(e); } }
public static void Start() { try { TypeHelper.Init(); Game.EventSystem.Init(); Log.Info("开始热更"); // 注册热更层回调 GameLoop.onUpdate += Update; GameLoop.onLateUpdate += LateUpdate; GameLoop.onApplicationQuit += OnApplicationQuit; ProtobufHelper.Init(); Game.Options = new Options(); Game.EventSystem.Publish(new EventType.AppStart()); } catch (Exception _e) { Log.Error(_e); } }
public void Start() { try { SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance); string[] assemblyNames = { "Unity.Model.dll", "Unity.Hotfix.dll", "Unity.ModelView.dll", "Unity.HotfixView.dll" }; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { string assemblyName = assembly.ManifestModule.Name; if (!assemblyNames.Contains(assemblyName)) { continue; } Game.EventSystem.Add(assembly); } ProtobufHelper.Init(); Game.Options = new Options(); Game.EventSystem.Publish(new EventType.AppStart()); } catch (Exception e) { Log.Error(e); } }
public static void LoadOneConfig(this ConfigComponent self, Type configType) { byte[] oneConfigBytes = self.ConfigLoader.GetOneConfigBytes(configType.FullName); object category = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length); self.AllConfig[configType] = category; }
public static void LoadOneConfig(this ConfigComponent self, Type configType) { byte[] oneConfigBytes = Game.EventSystem.Callback <string, byte[]>(CallbackType.GetOneConfigBytes, configType.FullName); object category = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length); self.AllConfig[configType] = category; }
public static object DeserializeFrom(ushort opcode, Type type, byte[] bytes, int index, int count) { if (opcode >= 20000) { return(ProtobufHelper.FromBytes(type, bytes, index, count)); } return(MongoHelper.FromBson(type, bytes, index, count)); }
public static object DeserializeFrom(ushort opcode, Type type, MemoryStream stream) { if (opcode >= 20000) { return(ProtobufHelper.FromStream(type, stream)); } return(MongoHelper.FromStream(type, stream)); }
public static void SerializeTo(ushort opcode, object obj, MemoryStream stream) { if (opcode >= 20000) { ProtobufHelper.ToStream(obj, stream); return; } MongoHelper.ToBson(obj, stream); }
private static int Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Log.Error(e.ExceptionObject.ToString()); }; ETTask.ExceptionHandler += Log.Error; // 异步方法全部会回掉到主线程 SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance); try { Game.EventSystem.Add(typeof(Game).Assembly); ProtobufHelper.Init(); MongoRegister.Init(); // 命令行参数 Options options = null; Parser.Default.ParseArguments <Options>(args) .WithNotParsed(error => throw new Exception($"命令行格式错误!")) .WithParsed(o => { options = o; }); Options.Instance = options; Log.ILog = new NLogger(Game.Options.AppType.ToString()); LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}"; Log.Info($"server start........................ {Game.Scene.Id}"); switch (Game.Options.AppType) { case AppType.ExcelExporter: { Game.Options.Console = 1; ExcelExporter.Export(); return(0); } case AppType.Proto2CS: { Game.Options.Console = 1; Proto2CS.Export(); return(0); } } } catch (Exception e) { Log.Console(e.ToString()); } return(1); }
private static void LoadOneInThread(this ConfigComponent self, Type configType, Dictionary <string, byte[]> configBytes) { byte[] oneConfigBytes = configBytes[configType.Name]; object category = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length); lock (self) { self.AllConfig[configType] = category; } }
public static object DeserializeFrom(ushort opcode, Type type, MemoryStream memoryStream) { if (opcode < OpcodeRangeDefine.PbMaxOpcode) { return(ProtobufHelper.FromStream(type, memoryStream)); } if (opcode >= OpcodeRangeDefine.JsonMinOpcode) { return(JsonHelper.FromJson(type, memoryStream.GetBuffer().ToStr((int)memoryStream.Position, (int)(memoryStream.Length - memoryStream.Position)))); } return(MongoHelper.FromStream(type, memoryStream)); }
private static void LoadOneInThread(this ConfigComponent self, Type configType, Dictionary <string, byte[]> configBytes) { byte[] oneConfigBytes = configBytes[configType.Name]; object category = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length); #if !SERVER MethodInfo methodInfo = category.GetType().GetMethod("AfterDeserialization"); methodInfo?.Invoke(category, null); #endif lock (self) { self.AllConfig[configType] = category; } }
private static void Main(string[] args) { // 异步方法全部会回掉到主线程 SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance); try { Game.EventSystem.Add(typeof(Game).Assembly); Game.EventSystem.Add(DllHelper.GetHotfixAssembly()); ProtobufHelper.Init(); MongoHelper.Init(); // 命令行参数 Options options = null; Parser.Default.ParseArguments <Options>(args) .WithNotParsed(error => throw new Exception($"命令行格式错误!")) .WithParsed(o => { options = o; }); Game.Options = options; Game.ILog = new NLogger(Game.Options.AppType.ToString()); LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}"; Log.Info($"server start........................ {Game.Scene.Id}"); Game.EventSystem.Publish(new EventType.AppStart()); while (true) { try { Thread.Sleep(1); Game.Update(); Game.LateUpdate(); Game.FrameFinish(); } catch (Exception e) { Log.Error(e); } } } catch (Exception e) { Log.Error(e); } }
public static object ToActorMessage(this MemoryStream memoryStream) { ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), 8); Type type = OpcodeTypeComponent.Instance.GetType(opcode); if (opcode < MessageSerializeHelper.PbMaxOpcode) { return(ProtobufHelper.FromBytes(type, memoryStream.GetBuffer(), 10, (int)memoryStream.Length - 10)); } if (opcode >= MessageSerializeHelper.JsonMinOpcode) { return(JsonHelper.FromJson(type, memoryStream.GetBuffer().ToStr(10, (int)(memoryStream.Length - 10)))); } return(MongoHelper.FromBson(type, memoryStream.GetBuffer(), 10, (int)memoryStream.Length - 10)); }
public static object DeserializeFrom(ushort opcode, Type type, MemoryStream memoryStream) { if (opcode < OpcodeRangeDefine.PbMaxOpcode) { return(ProtobufHelper.FromStream(type, memoryStream)); } if (opcode >= OpcodeRangeDefine.JsonMinOpcode) { return(JsonHelper.FromJson(type, memoryStream.GetBuffer().ToStr((int)memoryStream.Position, (int)(memoryStream.Length - memoryStream.Position)))); } #if NOT_UNITY return(MongoHelper.FromStream(type, memoryStream)); #else throw new Exception($"client no message: {opcode}"); #endif }
public static T LoadOneConfig <T>(this ConfigComponent self, string name = "", bool cache = false) where T : ProtoObject { Type configType = typeof(T); if (string.IsNullOrEmpty(name)) { name = configType.FullName; } byte[] oneConfigBytes = self.ConfigLoader.GetOneConfigBytes(name); object category = ProtobufHelper.FromBytes(configType, oneConfigBytes, 0, oneConfigBytes.Length); if (cache) { self.AllConfig[configType] = category; } return(category as T); }
public static void SerializeTo(ushort opcode, object obj, MemoryStream memoryStream) { if (opcode < PbMaxOpcode) { ProtobufHelper.ToStream(obj, memoryStream); return; } if (opcode >= JsonMinOpcode) { string s = JsonHelper.ToJson(obj); byte[] bytes = s.ToUtf8(); memoryStream.Write(bytes, 0, bytes.Length); return; } #if SERVER MongoHelper.ToStream(obj, memoryStream); #else throw new Exception($"client no message: {opcode}"); #endif }
public static void Start() { try { Game.EventSystem.Add(typeof(Entry).Assembly); CodeLoader.Instance.Update = Game.Update; CodeLoader.Instance.LateUpdate = Game.LateUpdate; CodeLoader.Instance.OnApplicationQuit = Game.Close; ProtobufHelper.Init(); Game.Options = new Options(); Game.EventSystem.Publish(new EventType.AppStart()).Coroutine(); } catch (Exception e) { Log.Error(e); } }
public byte[] SerializeTo(object obj) { return(ProtobufHelper.ToBytes(obj)); }
public object DeserializeFrom(object instance, MemoryStream stream) { return(ProtobufHelper.FromStream(instance, stream)); }
public object DeserializeFrom(Type type, MemoryStream stream) { return(ProtobufHelper.FromStream(type, stream)); }
public object DeserializeFrom(object instance, byte[] bytes, int index, int count) { return(ProtobufHelper.FromBytes(instance, bytes, index, count)); }
public object DeserializeFrom(Type type, byte[] bytes, int index, int count) { return(ProtobufHelper.FromBytes(type, bytes, index, count)); }
public void SerializeTo(object obj, MemoryStream stream) { ProtobufHelper.ToStream(obj, stream); }
public object Clone() { byte[] bytes = ProtobufHelper.ToBytes(this); return(ProtobufHelper.FromBytes(this.GetType(), bytes, 0, bytes.Length)); }