Exemple #1
0
        private Vector2 GetMoveInput()
        {
            Vector2 rawInput  = m_input.GetAxis2D(Action.MoveHorizontal, Action.MoveVertical);
            Vector2 moveInput = Vector2.ClampMagnitude(rawInput, 1);

            return(Vector3.ProjectOnPlane(moveInput, GetGravityNormal()));
        }
Exemple #2
0
        private Vector2 GetMoveInput()
        {
            Vector2 rawInput  = m_input.GetAxis2D(Action.MoveHorizontal, Action.MoveVertical);
            Vector2 moveInput = Vector2.ClampMagnitude(rawInput, 1);

            return(moveInput);
        }
Exemple #3
0
        bool actorInput()
        {
            //
            MouseDataSingleton mouseSingleton = default;

            updateMouse(ref mouseSingleton);


            //
            var myPlayerSingleton = GetSingleton <MyPlayerSingleton>();
            var myPlayerEntity    = myPlayerSingleton.playerEntity;

            if (myPlayerEntity == Entity.Null)
            {
                return(false);
            }
            if (EntityManager.HasComponent <PlayerActorArray>(myPlayerEntity) == false)
            {
                return(false);
            }
            var actors = EntityManager.GetComponentData <PlayerActorArray>(myPlayerEntity);

            if (actors.shipEntity == Entity.Null)
            {
                return(false);
            }

            if (EntityManager.HasComponent <ShipControlInfo>(actors.shipEntity) == false)
            {
                var actor       = EntityManager.GetComponentData <Actor>(actors.shipEntity);
                var shipSpawner = actorSpawnerMap.GetActorSpawner(actor.actorType) as ShipSpawner;
                shipSpawner.AddComponentTypesInMyShip(actors.shipEntity);
            }


            //if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject() == false)
            {
                float3     shipPosition = EntityManager.GetComponentData <Translation>(actors.shipEntity).Value;
                quaternion shipRotation = EntityManager.GetComponentData <Rotation>(actors.shipEntity).Value;


                //
                var observerSingleton = GetSingleton <ObserverSingleton>();
                {
                    observerSingleton.position = (half2)math.lerp(shipPosition, mouseSingleton.point, 0.5f).xz;
                }
                SetSingleton(observerSingleton);


                //
                Entities
                .WithAll <NetworkUnreliableOutBuffer>().WithAllReadOnly <NetworkConnection>()
                .WithNone <NetworkDisconnectedMessage>()
                .ForEach((DynamicBuffer <NetworkUnreliableOutBuffer> outBuffer) =>
                {
                    //
                    if (EntityManager.HasComponent <ShipLostInputState>(actors.shipEntity) == false)
                    {
                        var torqueY = 0f;     //[0,1]
                        if (input.GetButton(PlayerInputActions.Torque))
                        {
                            var angle = Vector3.SignedAngle(math.forward(shipRotation), mouseSingleton.direction, Vector3.up);
                            angle     = Mathf.Clamp(angle, -maxAngle, maxAngle);
                            torqueY   = math.pow(angle / maxAngle, 2f);
                            if (angle < 0f)
                            {
                                torqueY = -torqueY;
                            }
                        }
                        else
                        {
                            torqueY = input.GetButton(PlayerInputActions.Torque_Left) ? -1f : input.GetButton(PlayerInputActions.Torque_Right) ? 1f : 0f;
                        }


                        var move = input.GetAxis2D(PlayerInputActions.Move_Horizontal, PlayerInputActions.Move_Vertical);
                        var s    = new PlayerActorMoveInputSerialize
                        {
                            observerPosition = observerSingleton.position,
                            shipMoveInput    = new ShipMoveInput
                            {
                                moveForward = move.y > 0f,
                                moveBack    = move.y < 0f,
                                moveLeft    = move.x <0f,
                                                      moveRight = move.x> 0f,

                                torqueY = (half)torqueY,

                                accelerate = input.GetButton(PlayerInputActions.Accelerate),
                            }
                        };

                        if (math.distance(s.observerPosition, lastShipMoveInput.observerPosition) > 10f ||
                            s.shipMoveInput.moveForward != lastShipMoveInput.shipMoveInput.moveForward ||
                            s.shipMoveInput.moveBack != lastShipMoveInput.shipMoveInput.moveBack ||
                            s.shipMoveInput.moveLeft != lastShipMoveInput.shipMoveInput.moveLeft ||
                            s.shipMoveInput.moveRight != lastShipMoveInput.shipMoveInput.moveRight ||
                            s.shipMoveInput.torqueY != lastShipMoveInput.shipMoveInput.torqueY ||
                            s.shipMoveInput.accelerate != lastShipMoveInput.shipMoveInput.accelerate)
                        {
                            s._DoSerialize(outBuffer);

                            lastShipMoveInput = s;
                            EntityManager.SetComponentData(actors.shipEntity, s.shipMoveInput);
                        }
                    }


                    //
                    if (EntityManager.HasComponent <ShipLostInputState>(actors.shipEntity) == false)
                    {
                        //
                        FireAction fireAction = FireAction.none;
                        for (var i = PlayerInputActions.Weapon0; i <= PlayerInputActions.Weapon6; ++i)
                        {
                            if (input.GetButtonDown(i))
                            {
                                var index = i - PlayerInputActions.Weapon0;
                                if (input.GetButton(PlayerInputActions.Shift))
                                {
                                    fireAction = (FireAction)index + (int)FireAction.__uninstallSlotIndexBegin;
                                }
                                else
                                {
                                    fireAction = (FireAction)index + (int)FireAction.__fireSlotIndexBegin;
                                }
                                break;
                            }
                        }


                        if (fireAction == FireAction.none)
                        {
                            for (var i = PlayerInputActions.AssistWeapon0; i <= PlayerInputActions.AssistWeapon2; ++i)
                            {
                                if (input.GetButtonDown(i))
                                {
                                    var index = i - PlayerInputActions.AssistWeapon0;
                                    if (input.GetButton(PlayerInputActions.Shift))
                                    {
                                        fireAction = (FireAction)index + (int)FireAction.__uninstallAssistSlotIndexBegin;
                                    }
                                    else
                                    {
                                        //fireAction = (FireAction)index + (int)FireAction.__fireSlotIndexBegin;
                                    }
                                    break;
                                }
                            }
                        }


                        //
                        if (fireAction == FireAction.none)
                        {
                            if (input.GetButtonDown(PlayerInputActions.MouseButton2))
                            {
                                fireAction = FireAction.autoFire;
                            }
                            else if (input.GetButtonDown(PlayerInputActions.MouseButton1))
                            {
                                fireAction = FireAction.mainFire;
                            }

                            /*else if (input.GetButtonDown(PlayerInputActions.MouseButton2))
                             * {
                             *  fireAction = FireAction.mouseButton2;
                             * }*/
                            else if (input.GetButtonDown(PlayerInputActions.Shield))
                            {
                                fireAction = FireAction.shield;
                            }
                        }



                        if (fireAction != FireAction.none)
                        {
                            //
                            var s = new PlayerActorFireInputSerialize
                            {
                                firePosition = (half2)mouseSingleton.point.xz,

                                fireAction = fireAction,
                            };
                            s._DoSerialize(outBuffer);


                            //
                            mouseFx.OnPlayFx(mouseSingleton.point);
                        }
                    }
                });
            }

            return(true);
        }