Exemplo n.º 1
0
        public void SetPropertyValue(int propertyId, byte[] valueBytes)
        {
            var server = false;

#if SERVER
            server = true;
#endif
            var propertyCollection      = EntityDefine.PropertyCollectionMap[EntityDefine.GetTypeId(GetType())];
            var reactPropertyCollection = EntityDefine.ReactPropertyCollectionMap[EntityDefine.GetTypeId(GetType())];
            var propertyInfo            = propertyCollection[propertyId];
            var reactPropertyInfo       = reactPropertyCollection[propertyId];
            if (propertyInfo == null)
            {
                Log.Error($"Error {propertyId} propertyInfo == null {propertyInfo}");
                return;
            }
            if (propertyInfo.PropertyType == typeof(int))
            {
                if (server)
                {
                    propertyInfo.SetValue(this, MongoHelper.ToInt(valueBytes));
                }
                else
                {
                    typeof(ReactProperty <int>).GetProperty("Value").SetValue(reactPropertyInfo.GetValue(this), MongoHelper.ToInt(valueBytes));
                }
            }
            if (propertyInfo.PropertyType == typeof(float))
            {
                if (server)
                {
                    propertyInfo.SetValue(this, MongoHelper.ToFloat(valueBytes));
                }
                else
                {
                    typeof(ReactProperty <float>).GetProperty("Value").SetValue(reactPropertyInfo.GetValue(this), MongoHelper.ToFloat(valueBytes));
                }
            }
            if (propertyInfo.PropertyType == typeof(string))
            {
                if (server)
                {
                    propertyInfo.SetValue(this, MongoHelper.ToString(valueBytes));
                }
                else
                {
                    typeof(ReactProperty <string>).GetProperty("Value").SetValue(reactPropertyInfo.GetValue(this), MongoHelper.ToString(valueBytes));
                }
            }
            if (propertyInfo.PropertyType == typeof(Vector3))
            {
                if (server)
                {
                    propertyInfo.SetValue(this, MongoHelper.FromBson <Vector3>(valueBytes));
                }
                else
                {
                    typeof(ReactProperty <Vector3>).GetProperty("Value").SetValue(reactPropertyInfo.GetValue(this), MongoHelper.FromBson <Vector3>(valueBytes));
                }
            }
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            // 异步方法全部会回掉到主线程
            SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);

            try
            {
                Game.EventSystem.Add(DLLType.Model, typeof(Game).Assembly);
                Game.EventSystem.Add(DLLType.Hotfix, DllHelper.GetHotfixAssembly());

                MongoHelper.Init();
                EntityDefine.Init();


                //Console.WriteLine("Tumbler test 2000 step");

                // 命令行参数
                Parser.Default.ParseArguments <Options>(args)
                .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
                .WithParsed(o => { Game.Options = o; });

                IdGenerater.AppId = Game.Options.Id;

                // 启动配置
                StartConfig allConfig = MongoHelper.FromJson <StartConfig>(File.ReadAllText(Path.Combine("../Config/StartConfig/", Game.Options.Config)));

                StartConfig startConfig = allConfig.Get(Game.Options.Id);
                Game.Scene = EntityFactory.CreateScene(0, "Process", SceneType.Process);

                LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Scene.Id:0000}";

                Game.Scene.AddComponent <StartConfigComponent, StartConfig, long>(allConfig, startConfig.Id);

                Log.Info($"server start........................ {Game.Scene.Id}");

                Game.Scene.AddComponent <TimerComponent>();
                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatcherComponent>();
                Game.Scene.AddComponent <ConfigComponent>();
                Game.Scene.AddComponent <CoroutineLockComponent>();
                // 发送普通actor消息
                Game.Scene.AddComponent <ActorMessageSenderComponent>();
                // 发送location actor消息
                Game.Scene.AddComponent <ActorLocationSenderComponent>();
                // 访问location server的组件
                Game.Scene.AddComponent <LocationProxyComponent>();
                Game.Scene.AddComponent <ActorMessageDispatcherComponent>();
                // 数值订阅组件
                Game.Scene.AddComponent <NumericWatcherComponent>();
                // 控制台组件
                //Game.Scene.AddComponent<ConsoleComponent>();


                OuterConfig outerConfig = startConfig.GetComponent <OuterConfig>();
                if (outerConfig != null)
                {
                    // 外网消息组件
                    Game.Scene.AddComponent <NetOuterComponent, string>(outerConfig.Address);
                }

                InnerConfig innerConfig = startConfig.GetComponent <InnerConfig>();
                if (innerConfig != null)
                {
                    // 内网消息组件
                    Game.Scene.AddComponent <NetInnerComponent, string>(innerConfig.Address);
                }

                DBConfig dbConfig = startConfig.GetComponent <DBConfig>();
                if (dbConfig != null)
                {
                    Game.Scene.AddComponent <DBComponent, DBConfig>(dbConfig);
                }

                // 先加这里,后面删掉
                Game.EventSystem.Run(EventIdType.AfterScenesAdd);

                while (true)
                {
                    try
                    {
                        Thread.Sleep(1);
                        OneThreadSynchronizationContext.Instance.Update();
                        Game.EventSystem.Update();
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }