Ejemplo n.º 1
0
    /// <summary>
    /// Returns input value while the user holds down the key.
    /// </summary>
    /// <returns>Input value if button or axis is still active.</returns>
    /// <param name="exactKeyModifiers">If set to <c>true</c> check that only specified key modifiers are active, otherwise check that at least specified key modifiers are active.</param>
    /// <param name="axis">Specific actions for axis (Empty by default).</param>
    /// <param name="device">Preferred input device.</param>
    public float GetValue(bool exactKeyModifiers = false, string axis = "", InputDevice device = InputDevice.Any)
    {
        float res = 0;
        float cur;

        cur = mPrimaryInput.GetInput(exactKeyModifiers, axis, device);

        if (cur > res)
        {
            res = cur;
        }

        cur = mSecondaryInput.GetInput(exactKeyModifiers, axis, device);

        if (cur > res)
        {
            res = cur;
        }

        cur = mThirdInput.GetInput(exactKeyModifiers, axis, device);

        if (cur > res)
        {
            res = cur;
        }

        return(res);
    }
Ejemplo n.º 2
0
        // Update is called once per frame
        protected void Update()
        {
            if (!levelCompleted)
            {
                UserInput userInput = input.GetInput();

                if (CharacterCoinController.CoinCount > 100)
                {
                    coinController.Reset();
                    character.AddLives(1);
                }

                if (character.IsDead & !characterDied)
                {
                    SoundGenerator soundGenerator = GameObject
                                                    .FindGameObjectsWithTag("MusicGenerator")[0]
                                                    .GetComponent <SoundGenerator>();

                    if (character.Health <= 0)
                    {
                        soundGenerator.PlayPlayerIsDead(true);
                    }
                    else
                    {
                        soundGenerator.PlayPlayerIsDead();
                    }

                    if (cameraController != null)
                    {
                        Destroy(this.cameraController);
                    }

                    characterDied = true;
                }

                character.Move(userInput.move, userInput.status);
            }
        }
Ejemplo n.º 3
0
    void Start()
    {
        currentButtonSelected = 0;
        ChangeSelectedButton(currentButtonSelected);
        settingsPannel.SetActive(false);
        creditsPannel.SetActive(false);
        keyBindsPannel.SetActive(true);

        soundVolume.value  = PlayerPrefs.GetFloat("MasterVolume", 1);
        playerName[0].text = PlayerPrefs.GetString("Player1", "Player1");
        playerName[1].text = PlayerPrefs.GetString("Player2", "Player2");

        // Initialise tous les boutons en fonction des binds actuels
        // Ceux du P1
        buttonsP1[0].GetComponentInChildren <Text>().text           = CustomInput.GetInput("Horizontal", false);
        buttonsP1[0].GetComponentInChildren <Button>().interactable = CustomInput.isPlayer1UsingKeyboard;
        buttonsP1[1].GetComponentInChildren <Text>().text           = CustomInput.GetInput("Horizontal", true);
        buttonsP1[1].GetComponentInChildren <Button>().interactable = CustomInput.isPlayer1UsingKeyboard;
        buttonsP1[2].GetComponentInChildren <Text>().text           = CustomInput.GetInput("Jump", true);
        buttonsP1[3].GetComponentInChildren <Text>().text           = CustomInput.GetInput("Fire1", true);
        buttonsP1[4].GetComponentInChildren <Text>().text           = CustomInput.GetInput("item_1", true);
        buttonsP1[5].GetComponentInChildren <Text>().text           = CustomInput.GetInput("item_2", true);
        buttonsP1[6].GetComponentInChildren <Text>().text           = CustomInput.GetInput("item_3", true);
        buttonsP1[7].GetComponentInChildren <Toggle>().isOn         = CustomInput.isPlayer1UsingKeyboard;

        // Ceux du P2
        buttonsP2[0].GetComponentInChildren <Text>().text           = CustomInput.GetInput("HorizontalAlt", false);
        buttonsP2[0].GetComponentInChildren <Button>().interactable = CustomInput.isPlayer2UsingKeyboard;
        buttonsP2[1].GetComponentInChildren <Text>().text           = CustomInput.GetInput("HorizontalAlt", true);
        buttonsP2[1].GetComponentInChildren <Button>().interactable = CustomInput.isPlayer2UsingKeyboard;
        buttonsP2[2].GetComponentInChildren <Text>().text           = CustomInput.GetInput("JumpAlt", true);
        buttonsP2[3].GetComponentInChildren <Text>().text           = CustomInput.GetInput("Fire1Alt", true);
        buttonsP2[4].GetComponentInChildren <Text>().text           = CustomInput.GetInput("item_1Alt", true);
        buttonsP2[5].GetComponentInChildren <Text>().text           = CustomInput.GetInput("item_2Alt", true);
        buttonsP2[6].GetComponentInChildren <Text>().text           = CustomInput.GetInput("item_3Alt", true);
        buttonsP2[7].GetComponentInChildren <Toggle>().isOn         = CustomInput.isPlayer2UsingKeyboard;
    }
Ejemplo n.º 4
0
    /// <summary>
    /// the main fuction that makes the script look like it does and works like it should in the editor
    /// </summary>
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        EditorGUILayout.LabelField("Custom Input");

        m_target = target as CustomInput;
        int arraySize = 0;

        int previousArraySize;

        if (m_target.m_mappings == null)
        {
            previousArraySize = 0;
        }
        else
        {
            previousArraySize = m_target.m_mappings.Length;
        }

        if (previousArraySize != 0)
        {
            arraySize = previousArraySize;
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Array Size");
        arraySize = Mathf.Max(0, EditorGUILayout.IntField(arraySize));
        EditorGUILayout.EndHorizontal();

        // resize and init the array
        if (arraySize != previousArraySize)
        {
            if (arraySize > m_maxArraySize)
            {
                arraySize = m_maxArraySize;
            }

            CustomInput.InputEvent[] tempMappings = new CustomInput.InputEvent[m_target.m_mappings.Length];

            // copy over the existing array to perserve data after the change
            for (int i = 0; i < tempMappings.Length; ++i)
            {
                tempMappings[i]             = new CustomInput.InputEvent();
                tempMappings[i]             = m_target.m_mappings[i];
                tempMappings[i].m_axisEvent = m_target.m_mappings[i].m_axisEvent;

                tempMappings[i].m_axis1Dir = m_target.m_mappings[i].m_axis1Dir;
                tempMappings[i].m_axis2Dir = m_target.m_mappings[i].m_axis2Dir;

                tempMappings[i].m_axis1Tolerance = m_target.m_mappings[i].m_axis1Tolerance;
                tempMappings[i].m_axis2Tolerance = m_target.m_mappings[i].m_axis2Tolerance;
            }

            Debug.Log("Resizing array");
            m_target.m_mappings = new CustomInput.InputEvent[arraySize];

            for (int i = 0; i < arraySize; ++i)
            {
                m_target.m_mappings[i] = new CustomInput.InputEvent();

                if (i < tempMappings.Length)
                {
                    m_target.m_mappings[i] = tempMappings[i];
                }
            }
        }

        previousArraySize = arraySize;

        // create the array for the property fields
        m_eventProp = new SerializedProperty[arraySize];

        // create the serialized objects for each event
        for (int i = 0; i < arraySize; ++i)
        {
            string temp = "";
            if (m_target.m_mappings[i].m_category == CustomInput.InputCategory.kAxis && m_target.m_mappings[i].m_type == CustomInput.InputType.kStandard)
            {
                temp           = "m_mappings.Array.data[" + i + "].m_axisEvent";
                m_eventProp[i] = serializedObject.FindProperty(temp);
            }
            else
            {
                temp           = "m_mappings.Array.data[" + i + "].m_event";
                m_eventProp[i] = serializedObject.FindProperty(temp);
            }
        }

        m_foldOut = EditorGUILayout.Foldout(m_foldOut, "Array", true);

        if (m_foldOut)
        {
            // draw everything for the array
            for (int i = 0; i < arraySize; ++i)
            {
                if (m_eventProp[i] == null)  // error checking
                {
                    break;
                }

                CustomInput.InputEvent current = m_target.m_mappings[i];

                // display the rest of the layout for the array
                EditorGUILayout.BeginHorizontal();
                current.m_input    = EditorGUILayout.TextField(current.m_input);
                current.m_category = (CustomInput.InputCategory)EditorGUILayout.EnumPopup(current.m_category, GUILayout.MaxWidth(55));
                current.m_type     = (CustomInput.InputType)EditorGUILayout.EnumPopup(current.m_type, GUILayout.MaxWidth(70));

                if (current.m_category == CustomInput.InputCategory.kButton)
                {
                    if (current.m_type != CustomInput.InputType.kSequence)
                    {
                        if (GUILayout.Button("Assign Key"))
                        {
                            if (EditorApplication.isPlaying)
                            {
                                // since UnityEditor.GameView is internal this is how I managed to get its type
                                System.Reflection.Assembly assembly = typeof(EditorWindow).Assembly;
                                Type type = assembly.GetType("UnityEditor.GameView");
                                EditorWindow.FocusWindowIfItsOpen(type);
                            }
                            SetInput(ref current);
                            m_target.GetInput(i);
                        }
                        if (GUILayout.Button("Clear Key"))
                        {
                            current.m_input = "None";
                            m_lastInput     = "None";
                        }
                    }
                    else
                    {
                        GUIContent content = new GUIContent("Time Limit", "Time Limit is in seconds." + '\n' + "Negative value means no time limit.");
                        EditorGUILayout.LabelField(content, GUILayout.MaxWidth(70));
                        current.m_timeLimit = EditorGUILayout.FloatField(current.m_timeLimit, GUILayout.MaxWidth(50));
                    }
                }
                else
                {
                    if (current.m_type == CustomInput.InputType.kCombo)
                    {
                        if (current.m_input.Contains(", "))  // if there are two axis entered for the combo add the tolerance and direction for both axis
                        {
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                            current.m_axis1Dir = (CustomInput.AxisDirection)EditorGUILayout.EnumPopup(current.m_axis1Dir, GUILayout.MaxWidth(70));
                            if (current.m_axis1Dir != CustomInput.AxisDirection.kNeutral)
                            {
                                current.m_axis1Tolerance = EditorGUILayout.Slider(current.m_axis1Tolerance, 0, 1, GUILayout.MaxWidth(175));
                                Rect tempRect = GUILayoutUtility.GetLastRect();
                                tempRect.x -= 20;
                                GUI.Label(tempRect, new GUIContent("", "Axis Tolerance is from 0 to 1." + '\n' + "Determines how far the joystick"
                                                                   + '\n' + "must be moved to activate."));
                            }
                            else
                            {
                                current.m_axis1Tolerance = 0;
                            }

                            current.m_axis2Dir = (CustomInput.AxisDirection)EditorGUILayout.EnumPopup(current.m_axis2Dir, GUILayout.MaxWidth(70));
                            if (current.m_axis2Dir != CustomInput.AxisDirection.kNeutral)
                            {
                                current.m_axis2Tolerance = EditorGUILayout.Slider(current.m_axis2Tolerance, 0, 1, GUILayout.MaxWidth(175));
                                Rect tempRect = GUILayoutUtility.GetLastRect();
                                tempRect.x -= 20;
                                GUI.Label(tempRect, new GUIContent("", "Axis Tolerance is from 0 to 1." + '\n' + "Determines how far the joystick"
                                                                   + '\n' + "must be moved to activate."));
                            }
                            else
                            {
                                current.m_axis2Tolerance = 0;
                            }
                        }
                        else
                        {
                            current.m_axis1Dir = (CustomInput.AxisDirection)EditorGUILayout.EnumPopup(current.m_axis1Dir, GUILayout.MaxWidth(70));
                            if (current.m_axis1Dir != CustomInput.AxisDirection.kNeutral)
                            {
                                current.m_axis1Tolerance = EditorGUILayout.Slider(current.m_axis1Tolerance, 0, 1, GUILayout.MaxWidth(175));
                                Rect tempRect = GUILayoutUtility.GetLastRect();
                                tempRect.x -= 20;
                                GUI.Label(tempRect, new GUIContent("", "Axis Tolerance is from 0 to 1." + '\n' + "Determines how far the joystick" + '\n' + "must be moved to activate."));
                            }
                            else
                            {
                                current.m_axis1Tolerance = 0;
                            }
                        }
                    }
                    else if (current.m_type == CustomInput.InputType.kSequence)
                    {
                        GUIContent content = new GUIContent("Time Limit", "Time Limit is in seconds." + '\n' + "Negative value means no time limit.");
                        EditorGUILayout.LabelField(content, GUILayout.MaxWidth(70));
                        current.m_timeLimit = EditorGUILayout.FloatField(current.m_timeLimit, GUILayout.MaxWidth(50));

                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("Axis Tolerance", GUILayout.MaxWidth(100));
                        current.m_axis1Tolerance = EditorGUILayout.Slider(current.m_axis1Tolerance, 0, 1, GUILayout.MaxWidth(175));
                        Rect tempRect = GUILayoutUtility.GetLastRect();
                        tempRect.x -= 20;
                        GUI.Label(tempRect, new GUIContent("", "Axis Tolerance is from 0 to 1." + '\n' + "Determines how far the joystick"
                                                           + '\n' + "must be moved to activate."));

                        current.m_axis2Tolerance = EditorGUILayout.Slider(current.m_axis2Tolerance, 0, 1, GUILayout.MaxWidth(175));
                        tempRect    = GUILayoutUtility.GetLastRect();
                        tempRect.x -= 20;
                        GUI.Label(tempRect, new GUIContent("", "Axis Tolerance is from 0 to 1." + '\n' + "Determines how far the joystick"
                                                           + '\n' + "must be moved to activate."));
                    }
                }
                EditorGUILayout.EndHorizontal();

                // unity event required stuff for custom editors
                serializedObject.Update();
                EditorGUILayout.PropertyField(m_eventProp[i], true);
                serializedObject.ApplyModifiedProperties();
            }
        }

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Save"))
        {
            SaveInput();
        }
        if (GUILayout.Button("Load"))
        {
            LoadInput();
        }

        EditorGUILayout.EndHorizontal();

        // get the input to assign keys at editor time
        Event e = Event.current;

        if (e.keyCode != KeyCode.None || e.shift)
        {
            m_lastInput = e.keyCode.ToString();
        }
    }
Ejemplo n.º 5
0
    void Update()
    {
        if (keyClicked != null && isBindingKey)
        {
            foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
            {
                if (Input.GetKeyDown(kcode))
                {
                    if (keyClicked != null)
                    {
                        keyClicked.transform.GetChild(0).GetComponent <Text>().text = kcode.ToString();
                        switch (keyClicked.name)
                        {
                        case "ButtonLeft":
                            CustomInput.AddImput("Horizontal", CustomInput.GetInput("Horizontal", true), kcode.ToString());
                            break;

                        case "ButtonRight":
                            CustomInput.AddImput("Horizontal", kcode.ToString(), CustomInput.GetInput("Horizontal", false));
                            break;

                        case "ButtonJump":
                            CustomInput.AddImput("Jump", kcode.ToString(), "");
                            break;

                        case "ButtonAttack":
                            CustomInput.AddImput("Fire1", kcode.ToString(), "");
                            break;

                        case "ButtonItem1":
                            CustomInput.AddImput("item_1", kcode.ToString(), "");
                            break;

                        case "ButtonItem2":
                            CustomInput.AddImput("item_2", kcode.ToString(), "");
                            break;

                        case "ButtonItem3":
                            CustomInput.AddImput("item_3", kcode.ToString(), "");
                            break;

                        case "ButtonLeftAlt":
                            CustomInput.AddImput("HorizontalAlt", CustomInput.GetInput("HorizontalAlt", true), kcode.ToString());
                            break;

                        case "ButtonRightAlt":
                            CustomInput.AddImput("HorizontalAlt", kcode.ToString(), CustomInput.GetInput("HorizontalAlt", false));
                            break;

                        case "ButtonJumpAlt":
                            CustomInput.AddImput("JumpAlt", kcode.ToString(), "");
                            break;

                        case "ButtonAttackAlt":
                            CustomInput.AddImput("Fire1Alt", kcode.ToString(), "");
                            break;

                        case "ButtonItem1Alt":
                            CustomInput.AddImput("item_1Alt", kcode.ToString(), "");
                            break;

                        case "ButtonItem2Alt":
                            CustomInput.AddImput("item_2Alt", kcode.ToString(), "");
                            break;

                        case "ButtonItem3Alt":
                            CustomInput.AddImput("item_3Alt", kcode.ToString(), "");
                            break;
                        }
                        keyClicked   = null;
                        isBindingKey = false;
                        es.SetSelectedGameObject(lastButtonSelected);
                    }
                }
            }
        }
        else if (keyClicked != null && !isBindingKey)
        {
            isBindingKey = true;
        }
    }