Exemple #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (Focused)
            {
                foreach (var _key in GInput.NewPressedKeys)
                {
                    switch (_key)
                    {
                    case Keys.Back:
                        if (Text.Length > 0)
                        {
                            Text = Text.Substring(0, Text.Length - 1);
                        }
                        break;

                    case Keys.Enter:
                        OnEnterPressed?.Invoke(this);
                        break;

                    default:
                        Text += GInput.KeyToString(_key, Filters);
                        break;
                    }
                }
            }
        }
Exemple #2
0
    protected override void OnUpdate()
    {
        int i = 0;

        Entities.WithAll <Transform, CameraTarget>().ForEach((Entity targetEntity, Transform targetTransform) =>
        {
            //Only want to do first entity with CaemraTarget
            if (i > 0)
            {
                return;
            }

            i++;

            //Get Target Entity from priority
            var dt = Time.deltaTime;
            var cameraTransform  = Camera.main.transform;
            var cameraTargetData = EntityManager.GetSharedComponentData <CameraTarget>(targetEntity).data;

            //Get Camera Socekt
            targetTransform = targetTransform.Find("CameraSocket");

            //Rotate
            {
                inputX += GInput.GetAxisRaw(GAxis.RIGHTHORIZONTAL) * dt * cameraTargetData.rotationSpeed;
                inputY += GInput.GetAxisRaw(GAxis.RIGHTVERTICAL) * dt * cameraTargetData.rotationSpeed;
                inputY  = Mathf.Clamp(inputY, cameraTargetData.minRotatonY, cameraTargetData.maxRotationY);
                cameraTransform.eulerAngles = new Vector3(inputY, inputX);
            }

            //Zoom
            {
                if (!currentDistances.ContainsKey(targetEntity.Index))
                {
                    currentDistances.Add(targetEntity.Index, cameraTargetData.defaultDistance);
                }

                // currentDistances[targetEntity.Index] += Input.GetAxis("Mouse ScrollWheel") * cameraTargetData.zoomSpeed * dt;
                currentDistances[targetEntity.Index] = Mathf.Clamp(currentDistances[targetEntity.Index], cameraTargetData.minDistance, cameraTargetData.maxDistance);
            }

            //Move To Default Position
            cameraTransform.position = (targetTransform.position) - cameraTransform.forward * currentDistances[targetEntity.Index];

            //Collision
            {
                if (!cameraTargetData.doCollision)
                {
                    return;
                }

                ClipPlanePoints nearClipPlanePoints = GetCameraClipPlanePoints();
                DetectCollision(ref nearClipPlanePoints, targetTransform);

                //Move To Position based on collision
                cameraTransform.position = (targetTransform.position) - cameraTransform.forward * ((nearClipPlanePoints.didCollide) ? nearClipPlanePoints.hitDistance : currentDistances[targetEntity.Index]);
            }
        });
    }
Exemple #3
0
        public override void PostUpdate()
        {
            GInput.Update();

            SdkUI.Update();

            base.PostUpdate();
        }
Exemple #4
0
        public override void PostGameDraw(SpriteBatch sb)
        {
            if (Main.gameMenu)
            {
                GInput.Update();

                SdkUI.Update();
            }

            base.PostGameDraw(sb);
        }
Exemple #5
0
 void Start()
 {
     // define the axes and buttons interfaces and configuration
     GInput.registerInterface("Mouse X", new GInputInterfaceExample());
     GInput.configInterface("Mouse X", "source=Mouse X;debug=true");
     GInput.registerInterface("Mouse Y", new GInputInterfaceExample());
     GInput.configInterface("Mouse Y", "source=Mouse Y;debug=true");
     GInput.registerInterface("Horizontal", new GInputInterfaceExample());
     GInput.configInterface("Horizontal", "source=Horizontal;debug=true");
     GInput.registerInterface("Vertical", new GInputInterfaceExample());
     GInput.configInterface("Vertical", "source=Vertical;debug=true");
     GInput.registerInterface("Jump", new GInputInterfaceExample());
     GInput.configInterface("Jump", "source=Jump;debug=true");
 }
Exemple #6
0
    private void UpdateAsPlayer(Entity entity, ref ActorInput actorInput)
    {
        if (!EntityManager.HasComponent(entity, typeof(ActorPlayer)))
        {
            return;
        }


        //Get Player Input
        {
            //AXIS
            actorInput.movement.x = GInput.GetAxisRaw(GAxis.LEFTHORIZONTAL);
            actorInput.movement.z = GInput.GetAxisRaw(GAxis.LEFTVERTICAL);

            //Reset
            actorInput.actionToDo = 0;

            //BUTTONS
            if (GInput.GetButtonDown(GButton.RIGHT))
            {
                actorInput.actionToDo = 1;
            }
            if (GInput.GetButtonDown(GButton.BOTTOM))
            {
                actorInput.actionToDo = 2;
            }
            if (GInput.GetButtonDown(GButton.LEFT))
            {
                actorInput.actionToDo = 3;
            }
            if (GInput.GetButtonDown(GButton.L3))
            {
                actorInput.crouch = (byte)(actorInput.crouch == 1 ? 0 : 1);
            }
            actorInput.sprint = (byte)(GInput.GetButton(GButton.TOP) ? 1 : 0);
            actorInput.strafe = (byte)(GInput.GetButton(GButton.L2) ? 1 : 0);
        }

        //Convert Actor Movement to Camera
        {
            var cameraForward = (Camera.main.transform.TransformDirection(Vector3.forward).normalized);
            cameraForward.y = 0;
            var camreaRight = new Vector3(cameraForward.z, 0, -cameraForward.x);
            actorInput.movement = actorInput.movement.x * camreaRight + actorInput.movement.z * cameraForward;
            actorInput.movement.Normalize();
        }
    }
Exemple #7
0
    void Update()
    {
        // accumulate the rotation angle
        valueLookX += GInput.GetAxis("Mouse X") * multLookX;
        valueLookY += -GInput.GetAxis("Mouse Y") * multLookY;

        // apply angles
        bodyRigidbodyRotation.eulerAngles        = new Vector3(0f, valueLookX, 0f);
        bodyRigidbody.transform.rotation         = bodyRigidbodyRotation;
        cameraGameObjectRotation.eulerAngles     = new Vector3(valueLookY, 0f, 0f);
        cameraGameObject.transform.localRotation = cameraGameObjectRotation;

        // apply forces
        bodyRigidbody.AddForce(bodyRigidbody.transform.forward * GInput.GetAxis("Vertical") * walkForce + bodyRigidbody.transform.right * GInput.GetAxis("Horizontal") * walkForce);
        if (GInput.GetButton("Jump"))
        {
            bodyRigidbody.AddForce(jumpForce * Vector3.up);
        }
    }