Exemple #1
0
        public ClientWorld(ClientOptions options) : base(options, new ClientWorldCreator(options))
        {
            Options = options ?? throw new ArgumentNullException(nameof(options));

            Connected    += i => NetworkId = i;
            Disconnected += () => NetworkId = 0;

            void OnWorldCreate()
            {
                HookSystem hookSystem = World.GetHookSystem();

                hookSystem.RegisterHook <DisconnectedEvent>(e => Disconnected?.Invoke());
                hookSystem.RegisterHook <ConnectionInitiatedEvent>(e => Connecting?.Invoke());
                hookSystem.RegisterHook <ConnectionCompleteEvent>(e =>
                {
                    Connected?.Invoke(World.EntityManager
                                      .GetComponentData <NetworkIdComponent>(
                                          World.GetExistingSystem <CreateRpcRequestSystem>().CommandTargetComponentEntity)
                                      .Value);
                });
                hookSystem.RegisterHook <ConnectionFailedEvent>(e =>
                                                                ConnectionFailed?.Invoke(((ConnectionFailedEvent)e).Message.ToString()));
            }

            if (WorldCreator.WorldIsCreated)
            {
                OnWorldCreate();
            }

            WorldCreated += OnWorldCreate;
        }
Exemple #2
0
        public void ShouldAllowMultiHookRegistration()
        {
            int actionsCalled = 0;

            void OnAction1(IEventComponentData test) => actionsCalled++;
            void OnAction2(IEventComponentData test) => actionsCalled++;

            HookSystem system = world.CreateSystem <HookSystem>();

            system.RegisterHook <TestEvent>(OnAction1);
            system.RegisterHook <TestEvent>(OnAction2);
            world.EntityManager.CreateEntity(typeof(TestEvent));
            system.Update();
            Assert.AreEqual(2, actionsCalled);
        }