Esempio n. 1
0
    void Start()
    {
        HUDmount  = FindObjectOfType <HUDScoreSetter>().transform.Find("HUD_" + name[PlayerNumber] + "/ItemInfoMountPoint").gameObject;
        navPoints = new List <HUDPointer>();

        GameObject g = Instantiate(FindObjectOfType <CommonPunch>().gameObject);

        _currentItem = g.GetComponent <Item>();
        GameObject g2 = Instantiate(g);

        defaultWeapon = g2.GetComponent <Item>();

        //NoFriction = Resources.Load<PhysicMaterial>("Assets/Class Prototype/Physics Materials/NoFriction.physicMaterial");
        _collider = transform.Find("Collision/Foot Collider").gameObject.GetComponent <SphereCollider>();


        _controllerStatus = new ControlStruct();

        _rigidbody = this.GetComponent <Rigidbody>();

        if (attackPoint == null)
        {
            attackPoint = this.transform;
        }

        AnimState = new AnimationStates(anim);
        audio     = FindObjectOfType <AudioManager>();
    }
    private void sendIJKLcontrols()
    {
        ControlStruct c = new ControlStruct();

        c.jump   = Input.GetKey(KeyCode.I);
        c.attack = Input.GetKey(KeyCode.H);
        c.door   = Input.GetKey(KeyCode.Y);
        c.B      = Input.GetKey(KeyCode.Y);
        c.action = Input.GetKey(KeyCode.K);

        c.inGameMenu = Input.GetKey(KeyCode.Backslash);

        if (Input.GetKey(KeyCode.J))
        {
            c.moveLeft = -1;
        }
        else if (Input.GetKey(KeyCode.L))
        {
            c.moveLeft = 1;
        }
        else
        {
            c.moveLeft = 0;
        }

        IJKL_and_H_keys.Invoke(c);
    }
    private void sendArrowcontrols()
    {
        ControlStruct c = new ControlStruct();

        c.jump   = Input.GetKey(KeyCode.UpArrow);
        c.attack = Input.GetKey(KeyCode.RightShift);
        c.door   = Input.GetKey(KeyCode.RightControl);
        c.B      = Input.GetKey(KeyCode.RightControl);
        c.action = Input.GetKey(KeyCode.DownArrow);

        c.inGameMenu = Input.GetKey(KeyCode.Slash);

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            c.moveLeft = -1;
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            c.moveLeft = 1;
        }
        else
        {
            c.moveLeft = 0;
        }

        Arrow_and_Rshift_keys.Invoke(c);
    }
    private void sendWASDcontrols()
    {
        ControlStruct c = new ControlStruct();

        c.jump   = Input.GetKey(KeyCode.W);
        c.attack = Input.GetKey(KeyCode.Space);
        c.door   = Input.GetKey(KeyCode.B);
        c.B      = Input.GetKey(KeyCode.B);
        c.action = Input.GetKey(KeyCode.S);

        c.inGameMenu = Input.GetKey(KeyCode.Escape);

        if (Input.GetKey(KeyCode.A))
        {
            c.moveLeft = -1;
        }
        else if (Input.GetKey(KeyCode.D))
        {
            c.moveLeft = 1;
        }
        else
        {
            c.moveLeft = 0;
        }

        WASD_and_Space_keys.Invoke(c);
    }
    private void updateControl(int currentControl, ControlStruct current, bool state)
    {
        if (state)
        {
            switch (currentControl)
            {
            case jump:
                current.jump = true;
                break;

            case attackButton:
                current.attack = true;
                break;

            case action:
                current.action = true;
                break;

            case door1:
                current.B    = true;
                current.door = true;
                break;

            case door2:
            case door3:
                current.door = true;
                break;

            case start:
                current.inGameMenu = true;
                break;
            }
        }
    }
    private void sendNumPadcontrols()
    {
        ControlStruct c = new ControlStruct();

        c.jump   = Input.GetKey(KeyCode.Keypad8);
        c.attack = Input.GetKey(KeyCode.KeypadEnter);
        c.door   = Input.GetKey(KeyCode.Keypad0);
        c.B      = Input.GetKey(KeyCode.Keypad0);
        c.action = Input.GetKey(KeyCode.Keypad5);

        c.inGameMenu = Input.GetKey(KeyCode.KeypadDivide);

        if (Input.GetKey(KeyCode.Keypad4))
        {
            c.moveLeft = -1;
        }
        else if (Input.GetKey(KeyCode.Keypad6))
        {
            c.moveLeft = 1;
        }
        else
        {
            c.moveLeft = 0;
        }

        NumericPad_and_NumericEnter_keys.Invoke(c);
    }
    private bool isControlUpdated(int currentControl, ControlStruct previous, bool state)
    {
        switch (currentControl)
        {
        case jump:
            if (previous.jump == state)
            {
                return(false);
            }
            break;

        case attackButton:
            if (previous.attack == state)
            {
                return(false);
            }
            break;

        case action:
            if (previous.action == state)
            {
                return(false);
            }
            break;

        default:
            return(false);
        }
        return(true);
    }
Esempio n. 8
0
 public void ControllerListener(ControlStruct controls)
 {
     _controllerStatus = controls;
     //if (controls.jump)
     //    print("player " + PlayerNumber + " received the jump instruction");
     //if (controls.action)
     //    print("player " + PlayerNumber + " received the action instruction");
     //if (controls.attack)
     //    print("player " + PlayerNumber + " received the attack instruction");
     //if (controls.moveLeft != 0)
     //    print("player " + PlayerNumber + " received the move instruction " + controls.moveLeft);
 }
 private bool isControlUpdated(int currentControl, ControlStruct previous, float state)
 {
     switch (currentControl)
     {
     case left:
         if (previous.moveLeft >= state - axisThreshold && previous.moveLeft <= state + axisThreshold)
         {
             return(false);
         }
         break;
     }
     return(true);
 }
Esempio n. 10
0
 public void ControllerListener(ControlStruct controls)
 {
     if (controls.jump)
     {
         print("player " + playerNum + " received the jump instruction");
     }
     if (controls.action)
     {
         print("player " + playerNum + " received the action instruction");
     }
     if (controls.attack)
     {
         print("player " + playerNum + " received the attack instruction");
     }
     if (controls.moveLeft != 0)
     {
         print("player " + playerNum + " received the move instruction " + controls.moveLeft);
     }
 }
    private void updateControl(int currentControl, ControlStruct current, float state)
    {
        //print("current control " + currentControl + " state " + state);

        switch (currentControl)
        {
        case left:
            current.moveLeft = state;
            break;

        case attackAxis1:
        case attackAxis2:
            if (state > axisThreshold)
            {
                current.attack = true;
            }
            break;
        }
        return;
    }
 // Use this for initialization
 void Start()
 {
     tcc = GetComponent<CarController>();
     ccs = new ControlStruct(120f,0f,0f);
 }
    //Update is called once per frame
    void Update()
    {
        //if (!Input.GetKey(KeyCode.LeftShift))
        {
            if (input == null)
            {
                print("input is null");
            }


            //if (input.gamepads.Count == 0)
            //{
            //    print("no gamepads connected");
            //}

            int playerNum = 1;


            foreach (GamepadDevice gamepad in input.gamepads)
            {
                //create a structure for holding controls
                ControlStruct playerControls = new ControlStruct();


                int[] buttonValues = (int[])System.Enum.GetValues(typeof(GamepadButton));


                for (int i = 0; i < buttonValues.Length; i++)
                {
                    //print("Not left shift " + (GamepadButton)buttonValues[i] + ": " + gamepad.GetButton((GamepadButton)buttonValues[i]) + "\n");
                    //print("Not left shift " + i + ": " + gamepad.GetButton((GamepadButton)buttonValues[i]) + "\n");
                    updateControl(i, playerControls, gamepad.GetButton((GamepadButton)buttonValues[i]));
                }

                int[] axisValues = (int[])System.Enum.GetValues(typeof(GamepadAxis));
                for (int i = 0; i < axisValues.Length; i++)
                {
                    if (gamepad.GetAxis((GamepadAxis)axisValues[i]) != 0)
                    {
                        //print("Not left shift " + (GamepadAxis)axisValues[i] + ": " + gamepad.GetAxis((GamepadAxis)axisValues[i]) + "\n");
                        updateControl(i, playerControls, gamepad.GetAxis((GamepadAxis)axisValues[i]));
                    }
                }


                //pass the controls on to the player through an event
                //keep track of gamepads by ID, rather than player number
                //so that if a controller becomes unplugged, it doesn't shift
                //all controllers down an index.
                if (gamepad.deviceId == 0)
                {
                    controller1.Invoke(playerControls);
                }
                if (gamepad.deviceId == 1)
                {
                    controller2.Invoke(playerControls);
                }
                if (gamepad.deviceId == 2)
                {
                    controller3.Invoke(playerControls);
                }
                if (gamepad.deviceId == 3)
                {
                    controller4.Invoke(playerControls);
                }
                playerNum++;
            }
            if (printOnce)
            {
                print("controllers found: " + (playerNum - 1));
                printOnce = false;
            }
        }
    }