Beispiel #1
0
        private bool ButtonCheck(string controlname, ButtonAction bAction)
        {
            Sinput.SinputUpdate();

            for (int i = 0; i < joystickIndeces.Count; i++)
            {
                if (bAction == ButtonAction.DOWN && Sinput.GetButtonDown(controlname, (InputDeviceSlot)joystickIndeces[i]))
                {
                    return(true);
                }
                if (bAction == ButtonAction.HELD && Sinput.GetButton(controlname, (InputDeviceSlot)joystickIndeces[i]))
                {
                    return(true);
                }
                if (bAction == ButtonAction.UP && Sinput.GetButtonUp(controlname, (InputDeviceSlot)joystickIndeces[i]))
                {
                    return(true);
                }
                if (bAction == ButtonAction.REPEATING && Sinput.GetButtonDownRepeating(controlname, (InputDeviceSlot)joystickIndeces[i]))
                {
                    return(true);
                }
            }


            return(false);
        }
Beispiel #2
0
 public bool ButtonCheck(ButtonAction bAction, InputDeviceSlot slot)
 {
     if (bAction == ButtonAction.DOWN && Sinput.GetButtonDown(positiveControl, slot))
     {
         return(true);
     }
     if (bAction == ButtonAction.DOWN && Sinput.GetButtonDown(negativeControl, slot))
     {
         return(true);
     }
     if (bAction == ButtonAction.HELD && Sinput.GetButton(positiveControl, slot))
     {
         return(true);
     }
     if (bAction == ButtonAction.HELD && Sinput.GetButton(negativeControl, slot))
     {
         return(true);
     }
     if (bAction == ButtonAction.UP && Sinput.GetButtonUp(positiveControl, slot))
     {
         return(true);
     }
     if (bAction == ButtonAction.UP && Sinput.GetButtonUp(negativeControl, slot))
     {
         return(true);
     }
     return(false);
 }
Beispiel #3
0
 public static bool IsButtonDown()
 {
     return(Input.GetMouseButtonDown(0) || Sinput.GetButton(GetInputName(InputButton.A)) ||
            Sinput.GetButton(GetInputName(InputButton.B)) || Sinput.GetButton(GetInputName(InputButton.X)) ||
            Sinput.GetButton(GetInputName(InputButton.Y)) ||
            Sinput.GetButton(GetInputName(InputButton.DPadLeft)) ||
            Sinput.GetButton(GetInputName(InputButton.DPadRight)) ||
            Sinput.GetButton(GetInputName(InputButton.DPadDown)) ||
            Sinput.GetButton(GetInputName(InputButton.DPadUp)) || Sinput.GetButton("LB") ||
            Sinput.GetButton("RB"));
 }
Beispiel #4
0
    private IEnumerator ButtonHighlight(InputManager.InputButton btn)
    {
        Image btnImage = GetBtnImage(btn);

        btnImage.color = btnColors.buttonColorsList.Find(bt => bt.button == btn).color;

        yield return(new WaitWhile(() => Sinput.GetButton(InputManager.GetInputName(btn))));

        while (Vector4.Distance(btnImage.color, Color.white) > 0.05f)
        {
            btnImage.color = Color.Lerp(btnImage.color, Color.white, Time.deltaTime * 2f);

            yield return(null);
        }
    }
    private IEnumerator CheckPress()
    {
        while (Sinput.GetButton(_button))
        {
            if (Sinput.GetButtonDown("RB"))
            {
                _audioSource.pitch += 0.1f;
            }

            if (Sinput.GetButtonDown("LB"))
            {
                _audioSource.pitch -= 0.1f;
            }

            yield return(null);
        }

        Destroy(gameObject);
    }
Beispiel #6
0
    void attacks()
    {
        if (Sinput.GetButtonDown("BasicAttack", slot))
        {
            warrior.startBasicAttack();
        }



        if (Sinput.GetButton("SpecialAttack", slot))
        {
            warrior.startSpecialAttack();
        }


        if (Sinput.GetButtonUp("SpecialAttack", slot))
        {
            warrior.endSpecialAttack();
        }
    }
Beispiel #7
0
    private void OnSuccess()
    {
        if (!_isFinish)
        {
            if (Sinput.GetButton(InputManager.GetInputName(myButton)))
            {
                if (!_isFinish && state < spriteList.Count - 1)
                {
                    state++;

                    spriteRenderer.sprite = spriteList[state];
                }
            }
            else
            {
                OnFail();
            }
        }
        else
        {
            spriteRenderer.flipX = !spriteRenderer.flipX;
        }
    }
    void CheckInput()
    {
        for (int n = 0; n < buttons.Length; n++)
        {
            if (Sinput.GetButtonDown(buttons[n].name))
            {
                buttons[n].SetState(true);
                buttons[n].events.Pressed?.Invoke();
            }

            if (Sinput.GetButtonUp(buttons[n].name))
            {
                buttons[n].SetState(false);
                buttons[n].events.Released?.Invoke();
            }
        }

        for (int n = 0; n < axes.Length; n++)
        {
            bool state = false;
            for (int i = 0; i < axes[n].names.Length; i++)
            {
                float value = Sinput.GetAxis(axes[n].names[i]);
                state = Mathf.Abs(value) > 0f;
                if (axes[n].sendWhenZeroToo || state)
                {
                    axes[n].AxisValue?.Invoke(value);
                    break;
                }
            }

            bool prevState = axes[n].isPressed;
            axes[n].SetState(state);

            if (state)
            {
                if (!prevState)
                {
                    axes[n].events.Pressed?.Invoke();
                }
            }
            else if (prevState)
            {
                axes[n].events.Released?.Invoke();
            }
        }

        for (int n = 0; n < joysticks.Length; n++)
        {
            bool state = false;
            for (int i = 0; i < joysticks[n].names.Length; i++)
            {
                Vector2 value = Sinput.GetVector(joysticks[n].names[i].x, joysticks[n].names[i].y,
                                                 joysticks[n].normalizationMode != NormalizationMode.NotNormalize);
                state = value.sqrMagnitude > 0f;

                if (state && (joysticks[n].normalizationMode == NormalizationMode.NormalizeWithoutPithagoras))
                {
                    if (Mathf.Abs(value.x) > Mathf.Abs(value.y))
                    {
                        value.x = Mathf.Sign(value.x);
                    }
                    else if (Mathf.Abs(value.x) < Mathf.Abs(value.y))
                    {
                        value.y = Mathf.Sign(value.y);
                    }
                    else
                    {
                        value.x = Mathf.Sign(value.x); value.y = Mathf.Sign(value.y);
                    }
                }

                if (joysticks[n].sendWhenZeroToo || state)
                {
                    joysticks[n].JoystickValue?.Invoke(value);
                    joysticks[n].JoystickMagnitude?.Invoke(value.magnitude);
                    break;
                }
            }

            bool prevState = joysticks[n].isPressed;
            joysticks[n].SetState(state);

            if (state)
            {
                if (!prevState)
                {
                    joysticks[n].events.Pressed?.Invoke();
                }
            }
            else if (prevState)
            {
                joysticks[n].events.Released?.Invoke();
            }
        }

        for (int n = 0; n < buttonStates.Length; n++)
        {
            bool state = true;
            foreach (SButtonState button in buttonStates[n].buttonsState)
            {
                if (Sinput.GetButton(button.name) != button.state)
                {
                    state = false;
                    break;
                }
            }

            bool prevState = buttonStates[n].isPressed;
            buttonStates[n].SetState(state);

            if (state)
            {
                if (!prevState)
                {
                    buttonStates[n].events.Pressed?.Invoke();
                }
            }
            else if (prevState)
            {
                buttonStates[n].events.Released?.Invoke();
            }
        }
    }
Beispiel #9
0
        // Update is called once per frame
        void Update()
        {
            //get player input for motion
            Vector3 motionInput = Sinput.GetVector("Horizontal", "", "Vertical", playerSlot);

            //we want to move like, three times as much as this
            motionInput *= 3f;

            //gravity
            yMotion      -= Time.deltaTime * 10f;
            motionInput.y = yMotion;

            //move our character controller now
            characterController.Move(motionInput * Time.deltaTime);

            //landing/jumping
            if (characterController.isGrounded)
            {
                yMotion = -0.05f;

                if (Sinput.GetButtonDown("Jump", playerSlot))
                {
                    //we pressed jump while on the ground, so we jump!
                    yMotion = 5f;
                }
            }

            //aiming
            Vector3 aimDir = Vector3.zero;

            aimDir.x = Sinput.GetAxisRaw("Horizontal", playerSlot);
            aimDir.z = Sinput.GetAxisRaw("Vertical", playerSlot);
            if (aimDir.magnitude > 0.4f)
            {
                //inputs are strong enough, lets look in the aim direction
                lookDirection = aimDir.normalized;
                Quaternion fromRotation = transform.rotation;
                transform.LookAt(transform.position + lookDirection);
                transform.rotation = Quaternion.Slerp(fromRotation, transform.rotation, Time.deltaTime * 10f);
            }
            //make sure our display text always faces the same way
            playerSlotDisplay.transform.eulerAngles = Vector3.zero;


            //shooting
            bulletCooldown -= Time.deltaTime;
            if (Sinput.GetButton("Fire1", playerSlot) && bulletCooldown <= 0f)
            {
                bulletCooldown = 0.2f;
                GameObject newBullet = (GameObject)GameObject.Instantiate(bulletPrefab);
                newBullet.transform.position = gunTransform.position;
                newBullet.transform.rotation = gunTransform.rotation;
                newBullet.GetComponent <BulletScript>().moveDir = gunTransform.forward;
            }
            if (Sinput.GetButton("Fire2", playerSlot) && bulletCooldown <= 0f)
            {
                bulletCooldown = 0.05f;
                GameObject newBullet = (GameObject)GameObject.Instantiate(bulletPrefab);
                newBullet.transform.position   = gunTransform.position;
                newBullet.transform.rotation   = gunTransform.rotation;
                newBullet.transform.localScale = Vector3.one * 0.3f;
                newBullet.GetComponent <BulletScript>().moveDir   = gunTransform.forward;
                newBullet.GetComponent <BulletScript>().moveSpeed = 30f;
                newBullet.GetComponent <BulletScript>().life      = 0.33f;
            }
        }
    private void UpdateMovement()
    {
        Vector3 input = Vector3.zero;
        float   df    = 0;

        if (isAllowedToMove)
        {
            input = new Vector3(Sinput.GetAxis(strafeAxis), 0, Sinput.GetAxis(forwardsAxis));
            if (input.sqrMagnitude > 1)
            {
                input.Normalize();
            }

            if (input.sqrMagnitude == 0)
            {
                isSprinting = false; // stop sprinting when we stopped trying to move
            }

            df = Sinput.GetAxis(turnAxis) * turnSpeed * Time.fixedDeltaTime;
            transform.Rotate(0, df, 0);

            isSprinting |= Sinput.GetButton(sprintButton); // if we're sprinting stay sprinting

            float   currspeed = walkSpeed * (isSprinting ? sprintMultiplier : 1) * Time.fixedDeltaTime;
            Vector3 dpos      = input * currspeed;

            characterController.SimpleMove(transform.forward * dpos.z + transform.right * dpos.x);
        }
        else
        {
            characterController.SimpleMove(Vector3.zero); // move in place to stop the walking sound effects
        }


        // move leg position!
        if (characterController.velocity.sqrMagnitude > 0.1 || Mathf.Abs(df) > 0 || moveToRestingPosition)
        {
            tiltBody.localRotation = Quaternion.Euler(input.z * tiltMultiplier, 0, -input.x * tiltMultiplier);

            // then we adjust the timer!
            legTimer += Time.fixedDeltaTime;
            legTimer %= timePerLegGroup * legGroups.Count;
            int currLeg = Mathf.FloorToInt(legTimer / timePerLegGroup);
            if (previousLegGroup != currLeg)
            {
                // disable the previous legs
                for (int i = 0; i < legGroups[previousLegGroup].legs.Count; i++)
                {
                    legGroups[previousLegGroup].legs[i].StopLeg();
                }

                // now update the current legs!
                for (int i = 0; i < legGroups[currLeg].legs.Count; i++)
                {
                    legGroups[currLeg].legs[i].MoveLeg(timePerLegGroup); // for now just move it directly
                }

                previousLegGroup = currLeg;
            }
        }
    }