示例#1
0
        private static void RegisterGamepadPlayer(IServiceCollection services, PlayerId playerId, GamepadId padId)
        {
            //var playerType = PlayerType.GetPlayerType(playerId);
            //Type[] typeArgs = { playerType };

            //var playerControlsType = typeof(PlayerControls<>);
            //var perPlayerPlayerControls = playerControlsType.MakeGenericType(typeArgs);

            var perPlayerPlayerControls = playerId.GetPlayerKeyedType(typeof(PlayerControls <>));

            //var playerType = playerId.GetPlayerType();

            services.AddSingleton(perPlayerPlayerControls, s =>
            {
                var i = Activator.CreateInstance(perPlayerPlayerControls, s.GetRequiredService(typeof(IEventLayerKeyInjector <PlayerControls>))) as PlayerControls;
                //i.MoveRightEvent.addButton(KeyboardButtonCode.KC_D);
                //i.MoveLeftEvent.addButton(KeyboardButtonCode.KC_A);
                //i.MoveUpEvent.addButton(KeyboardButtonCode.KC_W);
                //i.MoveDownEvent.addButton(KeyboardButtonCode.KC_S);
                //i.JumpEvent.addButton(KeyboardButtonCode.KC_SPACE);

                //i.MoveRightEvent.addButton(KeyboardButtonCode.KC_RIGHT);
                //i.MoveLeftEvent.addButton(KeyboardButtonCode.KC_LEFT);
                //i.MoveUpEvent.addButton(KeyboardButtonCode.KC_UP);
                //i.MoveDownEvent.addButton(KeyboardButtonCode.KC_DOWN);
                //i.JumpEvent.addButton(KeyboardButtonCode.KC_NUMPAD0);

                i.MoveRightEvent.addButton(GamepadButtonCode.XInput_DPadRight, padId);
                i.MoveLeftEvent.addButton(GamepadButtonCode.XInput_DPadLeft, padId);
                i.MoveUpEvent.addButton(GamepadButtonCode.XInput_DPadUp, padId);
                i.MoveDownEvent.addButton(GamepadButtonCode.XInput_DPadDown, padId);
                i.JumpEvent.addButton(GamepadButtonCode.XInput_RightShoulder, padId);

                i.Build(s.GetRequiredService <EventManager>());

                return(i);
            });

            var perPlayerFireControls = playerId.GetPlayerKeyedType(typeof(FireControls <>));

            services.AddSingleton(perPlayerFireControls, s =>
            {
                var i = Activator.CreateInstance(perPlayerFireControls, s.GetRequiredService(typeof(IEventLayerKeyInjector <FireControls>))) as FireControls;

                //i.Fire.addButton(MouseButtonCode.MB_BUTTON0);

                //i.Fire.addButton(KeyboardButtonCode.KC_NUMPAD1);

                i.Fire.addButton(GamepadButtonCode.XInput_RTrigger, padId);

                i.Build(s.GetRequiredService <EventManager>());

                return(i);
            });
        }