Search Unity

[Released] cInput 2 - Unitys custom inputmanager got improved !

Discussion in 'Assets and Asset Store' started by Roidz99, Apr 4, 2012.

  1. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    That might work, but why create and destroy a bunch of UI elements and GameObjects each time you change keys when you can just update the text on the buttons when there's a change? Try looking at the cInput.OnKeyChanged event to know when to update your UI.

    Also, FYI, cInput.allowDuplicates is false by default. You don't need to explicitly set it to false unless you're changing it to true somewhere else.
     
    KrayonZA likes this.
  2. KrayonZA

    KrayonZA

    Joined:
    Mar 5, 2013
    Posts:
    52
    Thanks Deozaan OnKeyChanged is exactly what I needed its working perfectly with your suggestions.
    I guess I should of read the manual better OnKeyChanged is mentioned in there but i missed it :(

    Code (CSharp):
    1.  
    2. // --------------------------------------------------------------------------------------------------------------------
    3. // <copyright file="GUIControls.cs" company="">
    4. //  
    5. // </copyright>
    6. // --------------------------------------------------------------------------------------------------------------------
    7.  
    8.  
    9.  
    10. using System.Collections.Generic;
    11. using JetBrains.Annotations;
    12. using UnityEngine;
    13. using UnityEngine.UI;
    14.  
    15. //-----------------------------------------------------------------------------------------------------
    16. public class GUIControls : MonoBehaviour
    17. {
    18.     private readonly float _mouseSensitivity = 2.0f;
    19.     public GameObject InputItem;
    20.     private List<GameObject> InputItems = new List<GameObject>();
    21.     public GameObject InputPanel;
    22.     public Color DefaultColor;
    23.     public Color HighLightColor;
    24.  
    25.     // Use this for initialization
    26.     //-----------------------------------------------------------------------------------------------------
    27.     [UsedImplicitly]
    28.     private void Start()
    29.     {
    30.         SetupInput();
    31.         GenerateInputMapper();
    32.         cInput.OnKeyChanged += UpdateText;
    33.     }
    34.  
    35.  
    36.     public void UpdateText()
    37.     {
    38.  
    39.         for (var n = 0; n < cInput.length; n++)
    40.         {
    41.             InputItems[n].transform.FindChild("Primary").FindChild("Text").GetComponent<Text>().text = cInput.GetText(n, 1);
    42.             InputItems[n].transform.FindChild("Primary").GetComponent<Image>().color = DefaultColor;
    43.  
    44.             InputItems[n].transform.FindChild("Secondary").FindChild("Text").GetComponent<Text>().text = cInput.GetText(n, 2);
    45.             InputItems[n].transform.FindChild("Secondary").GetComponent<Image>().color = DefaultColor;
    46.         }
    47.  
    48.     }
    49.  
    50.     //-----------------------------------------------------------------------------------------------------
    51.     public void GenerateInputMapper()
    52.     {
    53.             for (var n = 0; n < cInput.length; n++)
    54.             {
    55.                 var item = Instantiate(InputItem);
    56.  
    57.                 item.transform.SetParent(InputPanel.transform, false);
    58.                 InputItems.Add(item.gameObject);
    59.  
    60.                 item.transform.FindChild("KeyName").GetComponent<Text>().text = cInput.GetText(n, 0);
    61.  
    62.                 item.transform.FindChild("Primary").FindChild("Text").GetComponent<Text>().text = cInput.GetText(n, 1);
    63.                 AddButtonListener(item.transform.FindChild("Primary").GetComponent<Button>(), n, 1);
    64.  
    65.                 item.transform.FindChild("Secondary").FindChild("Text").GetComponent<Text>().text = cInput.GetText(n, 2);
    66.                 AddButtonListener(item.transform.FindChild("Secondary").GetComponent<Button>(), n, 2);
    67.  
    68.                 item.SetActive(true);
    69.             }
    70.     }
    71.  
    72.    //-----------------------------------------------------------------------------------------------------
    73.     private void AddButtonListener(Button button, int id, int type)
    74.     {
    75.         switch (type)
    76.         {
    77.             case 1:
    78.                 button.onClick.AddListener(() => ChangeKeyPrimary(id));
    79.                 break;
    80.  
    81.             case 2:
    82.                 button.onClick.AddListener(() => ChangeKeySecondary(id));
    83.                 break;
    84.         }
    85.     }
    86.  
    87.     //-----------------------------------------------------------------------------------------------------
    88.     public void ChangeKeyPrimary(int id)
    89.     {
    90.         cInput.ChangeKey(id, 1);
    91.         InputItems[id].transform.FindChild("Primary").FindChild("Text").GetComponent<Text>().text = "...";
    92.         InputItems[id].transform.FindChild("Primary").GetComponent<Image>().color = HighLightColor;
    93.     }
    94.  
    95.     //-----------------------------------------------------------------------------------------------------
    96.     public void ChangeKeySecondary(int id)
    97.     {
    98.         cInput.ChangeKey(id, 2);
    99.         InputItems[id].transform.FindChild("Secondary").FindChild("Text").GetComponent<Text>().text = "...";
    100.         InputItems[id].transform.FindChild("Secondary").GetComponent<Image>().color = HighLightColor;
    101.     }
    102.  
    103.     //-----------------------------------------------------------------------------------------------------
    104.     private void SetupInput()
    105.     {
    106.         cInput.SetKey("Forward", Keys.W, Keys.ArrowUp);
    107.         cInput.SetKey("Backward", Keys.S, Keys.ArrowDown);
    108.         cInput.SetKey("Strafe Left", Keys.A, Keys.ArrowLeft);
    109.         cInput.SetKey("Strafe Right", Keys.D, Keys.ArrowRight);
    110.         cInput.SetKey("Crouch", Keys.LeftControl, Keys.RightControl);
    111.         cInput.SetKey("Jump", Keys.Space, Keys.None);
    112.         cInput.SetKey("Prone", Keys.C, Keys.None);
    113.         cInput.SetKey("Run", Keys.LeftShift, Keys.RightShift);
    114.         cInput.SetKey("Primary", Keys.Mouse0, Keys.None);
    115.         cInput.SetKey("Secondary", Keys.Mouse1, Keys.None);
    116.         cInput.SetKey("Reload", Keys.R, Keys.None);
    117.         cInput.SetKey("Knife", Keys.Q, Keys.None);
    118.         cInput.SetKey("Next Weapon", Keys.MouseWheelUp, Keys.None);
    119.         cInput.SetKey("Previous Weapon", Keys.MouseWheelDown, Keys.None);
    120.         cInput.SetKey("Camera Rotate Left", Keys.MouseLeft, Keys.None);
    121.         cInput.SetKey("Camera Rotate Right", Keys.MouseRight, Keys.None);
    122.         cInput.SetKey("Camera Rotate Up", Keys.MouseDown, Keys.None);
    123.         cInput.SetKey("Camera Rotate Down", Keys.MouseUp, Keys.None);
    124.         cInput.SetKey("Menu", Keys.Escape, Keys.None);
    125.         cInput.SetKey("Scores", Keys.Tab, Keys.None);
    126.         cInput.SetKey("Buy", Keys.B, Keys.None);
    127.         cInput.SetAxis("Horizontal", "Strafe Left", "Strafe Right");
    128.         cInput.SetAxis("Vertical", "Backward", "Forward");
    129.         cInput.SetAxis("MouseX", "Camera Rotate Left", "Camera Rotate Right");
    130.         cInput.SetAxis("MouseY", "Camera Rotate Up", "Camera Rotate Down");
    131.         cInput.SetAxis("Switch Weapon", "Previous Weapon", "Next Weapon");
    132.         cInput.SetAxisSensitivity("MouseX", _mouseSensitivity);
    133.         cInput.SetAxisSensitivity("MouseY", _mouseSensitivity);
    134.         cInput.SetAxisGravity("MouseX", 1000);
    135.         cInput.SetAxisGravity("MouseY", 1000);
    136.     }
    137. }
    138.  
     
    Last edited: Jun 2, 2015
  3. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    Hey there, I'm trying to get the iOS keyboard working for Sproggiwood via cInput. Unity seems to see it, but when I try to use the command binding API it doesn't seem to pick up keyboard presses at all (though it picks up my MFi controller just fine). Am I missing something obvious I need to configure?

    Keyboard bindings work perfectly fine on desktop builds.
     
  4. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Are you talking about a hardware (physical) keyboard or a software (virtual) keyboard? Which "command binding API" are you talking about? Do you mean that when you try to use ChangeKey() nothing seems to happen?

    Are you getting any errors? If so, will you please share the complete error message?

    Can you share some of the code you're using where it seems to fail?
     
  5. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    Replied to your e-mail, but for posterity:

    Sure; I'm using an Anker bluetooth keyboard "A7726" http://www.amazon.com/Anker-Bluetoo...id=1433649392&sr=8-6&keywords=anker+keyboards

    Unity can see it; if I bring up a gui with an input text field I can type into it just fine via the keyboard.

    I'm just using this code:

    cInput.ChangeKey( Item, n, false, false, true, true, true );

    and then waiting for .scanning to return false, but it never does. Nothing seems to show up, and I don't see anything in the logs as far as I can tell; at least nothing's poping up in the unity debug console when running it from the iPad attached via XCode. I can get into bare-metal debugging if there's nothing obvious to you about why this should be breaking. Everything else seems to work fine, including controllers & keybaords on desktop as well as MFi controllers, but this bluetooth keyboard on iOS doesn't seem to be working at all. I just upgraded to the latest cInput as well (imported the latest asset bundle, going from 2.7.0 to 2.8.5)

    I'll update the thread again when we get it worked out.
     
  6. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    So it looks like iOS keyboards simply don't work with Unity (and thus cInput's) input schema.

    https://keyholesoftware.com/2013/06/24/writing-games-with-unity-3d-part-3-mobile/

    • iOS – with Android devices, you can pair a bluetooth keyboard (I used aZagg), choose the keyboard setting (see the next section) and play using the keyboard instead of the touch screen & accelerometer. iOS on the other hand refuses to relay the keyboard events to Unity, so this does not work. I don’t know if it is iOS or Unity’s fault, but the end result is the same – iOS users are locked out of this useful feature.
    It seems that their API supports only keydown events: http://forum.unity3d.com/threads/icade-for-unity-plug-in.95865/

    ...and thus the only option seems to be going up against this low level API: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIKeyCommand_class/index.html
     
  7. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Thanks for posting the update of your findings as we discussed via email.
     
  8. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    One other question, more minor; are there any resources easily available for mapping input values (i.e. button 1) to the proper button images/names cross platform? I've got a mapping for xbox controllers on PC that works perfectly fine, but it's askew on Mac and MFi. I can certainly sit down and manually map them (which I did for PC, and am about to do for MFi/Mac/Linux), but if there's an easier set of info or code to do it already, that'd make things less painful. :)
     
  9. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Well, cInput attempts to do this for the Xbox 360 controller for you with the Keys class. But we don't have anything like that for other gamepads.
     
  10. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    I'm having trouble getting my G25 Logitech Steering Wheel working.

    The pedals work fine on Axis 2 but the steering doesn't work (very stiff), the motors don't turn on etc.

    If I use the Logitech SDK and initialise the controller the motor (force feedback I presume) turns on and I can use Axis 1 to retrieve the steering perfectly but after that the throttle works fine but if I don't have the throttle down the brake always reports as -1 so with no pedals down I'm essentially going in reverse.

    Have you seen this behaviour before?
     
  11. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    Don't worry about the steering wheel problem, I've solved it but I do have some feature requests to help make this package a little more extensible.

    • "AddKey" & "RemoveKey" so it acts much the same way as primary and secondary inputs work.

      On Android you may want to use a bluetooth controller or something similar and if you want your game to also work on android emulator platforms like BlueStacks (has 90million users) then you'll need to map the keyboard inputs as well... So moving Forward would be "W + UpArrow + Joy Axis 2"

    • Return a float when using GetButton, when using a joystick a lot of the time you want the analog value; to provide a better experience for those that use things like pedals and analog sticks etc.

      At the moment there is no way to add UpArrow & Joy Axis 2 into a shared "Key" if you want to return the float value of Joy Axis 2. In my racing game we are happy for the throttle to 1 when using the keyboard, but we want to offer a more realistic experience for people using analog devices.

      It could work if you added GetButtonValue instead.

    • Range values for SetKey and SetAxis, for example, my Steering Wheel pedal returns 1 for not depressed and -1 for depressed, some controllers might actually return crazy numbers too.

      If you could pass through the expected value for "UP" or "NOT DEPRESSED" then the value for "DOWN" or "PRESSED" you can figure out what percentage the value should be that is returned as 0-1.

    • Add multiplier to returned value, some controllers might have a really long range by default or design, like a steering wheel that turns on itself 2 times. This can obviously be calibrated if you have the driver installed but sometimes you may want to just multiply the return value so everyone with default configurations (noobs) get a good first experience with your controls.
     
    Last edited: Jun 12, 2015
  12. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Hi trooper,

    Sorry for my delayed reply. I have been away from my computer for about two weeks and somehow I missed the email notification that there was a post here.

    Your initial request should be solved with the Calibrate function. But you said you already got it fixed, so I'll move on to your other points, one by one:

    I'm not sure I understand this one. How would AddKey or RemoveKey work the same way as primary and secondary inputs?

    In cInput, GetButton/GetKey allows you to use an analog input as a digital input. GetAxis allows you to use a digital input as an analog input. If you want analog inputs, use axes.

    That is to say, GetButton/GetKey returns an int, while GetAxis returns a float.

    Again, this should already be taken care of with the Calibrate function.

    Isn't this what Axis Sensitivity is for?
     
  13. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Hi everyone,

    I just wanted to let you know that the Asset Store has a new feature called paid upgrades, which we've used to allow people who bought cInput to upgrade to cInput Pro by simply paying the difference between the two versions.
     
    schmosef likes this.
  14. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    I bought them both on sale so I guess I broke even! Thanks for the great asset.
     
  15. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    Does anyone know of a concrete way of designing a menu that works with CInput with the new UI yet?
     
  16. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I can't really give a concrete answer to that question. There are many ways to design a UI. The general idea of one such approach is described in the cInput Reference Manual:
     
  17. sacher

    sacher

    Joined:
    Jun 10, 2014
    Posts:
    6
    Good evening, my name is Angel and thank you very much for this forum.
    Let me share the following problem and I appreciate if someone can help me. Connect a "dancing pad" to the computer via USB to test the asset "cinput2" and working properly, I can reconfigure the buttons ... But when I take a tablet-android and connected via a miniUSB connector, the two buttons each upper corner(select and start), no work and can not be used. Can anyone suggest is happening ?. I'm using the default game that brings the project Cinput2..thanks and sorry for my bad english.

    sample dancingPad i am use.

    http://www.eltop.com.ua/product_12430.html
     
  18. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    That's very odd.

    What inputs do the Select and Start buttons map to on your computer?
     
    sacher likes this.
  19. sacher

    sacher

    Joined:
    Jun 10, 2014
    Posts:
    6
    thank you, on my computer show "joystickButton8 and JoystickButton9".. but on android no show.
     
    Last edited: Jun 23, 2015
  20. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Try making a test script in your scene with this code in it:
    Code (csharp):
    1. void Update() {
    2.     for (int i = (int)KeyCode.None; i <= (int)KeyCode.Joystick4Button19; i++) {
    3.         if (Input.GetKey((KeyCode)i)) {
    4.             Debug.Log(((KeyCode)i).ToString());
    5.         }
    6.     }
    7. }
    Then run that on your Android device and check your logcat to see what inputs (if any) are being pushed when you use the Select & Start buttons. If nothing shows up, it means that Unity doesn't support those buttons on Android, and cInput will only work on inputs that Unity itself will detect.

    If something does show up, then it will give us the next clue on how to get it working with cInput.
     
    sacher likes this.
  21. sacher

    sacher

    Joined:
    Jun 10, 2014
    Posts:
    6
    No show anything when pushed buttons select and start.....please suggest something more? or maybe you know any application to map these buttons to keys? ... thanks for all your time and help.
     
  22. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Just to double check: Did you check the logcat on your Android device? Debug.Log will NOT show up on the screen on Android by default, like it will in the Editor. You have to read the logfile to see the logs.

    If you did that correctly and you're absolutely sure Select and Start on the dance pad aren't doing anything, then I'm afraid I can't personally help you further. I'd try googling the brand name and model of your dance pad to see if anyone else had success getting those buttons to work on Andrdoid.

    You may also want to submit a bug report to Unity and see if they can/will fix it. As I said, if Unity doesn't detect the input on Android, then neither can cInput.

    Good luck!
     
  23. sacher

    sacher

    Joined:
    Jun 10, 2014
    Posts:
    6
    Thank you very muchs.. Deozaan.. have good ningth.
     
  24. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Hi folks,

    Fixes for issues introduced in 2.8.4 as well as a small improvement should soon be available for cInput, if not already.

    cInput changelog:

    v2.8.5p1

    • Fixed more gravity/sensitivity/deadzone errors caused by changes in 2.8.4. (Thanks Doghelmer)
    • cInput now warns when trying to change inputs for keys that haven't been defined. (Thanks Joshmond)
     
  25. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    Hi Deozaan,

    I am enjoying cInput, but I have ran into a couple of problems.
    I am using cInput with ORK Framework. I have the setup script in the first scene and ORK is taking the keys without a problem. But when I open the GUI the Unity3d cursor arrow is not visible and I can't use the GUI to change inputs.

    Further, I have noticed that when I make changes to the setup script, they are not immediately reflected in the (visible but unreachable) GUI, but did update once when I was able to activate the DEFAULTS button.

    I would appreciate any insight you can provide.






    Unity 5.1.1f1
     
    Last edited: Jun 25, 2015
  26. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    It sounds like ORK is hiding the mouse cursor. You may need to set the cursor to visible and possibly unlock it as well in order to use the mouse while the menu is opened.

    http://docs.unity3d.com/ScriptReference/Cursor.html

    The reason you're not seeing your changes in the setup script until you press the Defaults button is because cInput automatically loads its previous settings if they exist. You can avoid this during development by putting a cInput.ResetInputs() in your setup script. But note that this will override any customizations you've made to your controls in-game each time you run this script.
     
  27. riverdore

    riverdore

    Joined:
    Jul 21, 2012
    Posts:
    25
    Greetings,

    I recently purchased your asset, its quite wonderful. but i seem to have some issues integrating it into the project and make it work with UFPS.

    i followed ur steps exactly, but when i switched one of my scripts to cInput i got no call backs at all.
    i need ur assistance urgently.

    below are screen shots of the project files and paste bin links to the scripts.

    my problem:

    i am not getting call backs for all keys i defined in Cinput. for example i define a key called interact which is E. i check for input in C_interactionHandler and it is never detected. however, on my pet project were i was prototyping things seemed fine so i am not sure what's wrong.

    Setup Cinput - Cinput for UFPS: http://pastebin.com/rpfH844m
    Modified Vp_Input (Input handler for UFPS) - Cinput for UFPS - http://pastebin.com/nQ2WmMgu
    A custom script from our project using Cinput - http://pastebin.com/3Dd4uuyH
     

    Attached Files:

  28. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Thanks for the kind words and for purchasing cInput! We appreciate it very much.

    One thing that stands out to me in your C_InteractionHandler.cs file is that you have an Input bool which I'm not sure when or if that is ever set to true. So on line 32 when you check if(Input && cInput.GetKeyDown("Interact")), even if cInput.GetKeyDown("Interact") is true, if Input is not true, then you won't get inside that block of code.

    If you got it to work in your test project, and it's not working in your actual project, then check and see what you did differently.
     
  29. BuckeyeStudios

    BuckeyeStudios

    Joined:
    Oct 24, 2013
    Posts:
    104
    I used the code that @NightShade2109 posted above to make a ui using the new UGUI system it works great except that it wont save your button changes on after you restart anyone have an idea
     
  30. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Are you saying that cInput is resetting the inputs to default each time you restart your game? Or is it just the UI that is showing the default inputs even though the changed inputs are actually still being used?

    If it's the former, then it sounds like a bug in cInput that needs to be fixed. If it's the latter, then you probably just need to run your UpdateText() function again after cInput has finished loading.
     
  31. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Hi folks,

    An update to cInput has been submitted to the Asset Store. If you bought cInput from the Asset Store then the update should be live within a few (business) days. If you bought cInput from our website, then the update is available immediately.

    cInput changelog:

    v2.8.6

    • Forbidden keys are now completely ignored when changing input.
    • You can now forbid axes using ForbidAxis. (Thanks Dan)
    • cInput setup no longer requires restarting the Unity Editor
    • Fixed more gravity/sensitivity/deadzone errors caused by changes in 2.8.4. (Thanks Doghelmer)
    • cInput now warns when trying to change inputs for keys that haven't been defined. (Thanks Joshmond)
     
  32. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    I bought this asset off a sale a couple of Ludum Dare Jams ago. I haven't done anything serious with it, but I have two things to say. One, I appreciate the effort here. I totally understand the original pain that made you create cInput in the first place. In fact, I have made something similar for GMStudio(kbinput) because I felt the same pain when using it.

    Two, a suggestion. I see that you currently can set any specific key to be a modifier, using the Keys class as well. And the Keys Class contains strings for all the joysticks(etc...) that you support, meaning I should be able to use those as modifiers as well. I haven't tested this, but I assume it would work fine. The suggestion though, is to be able to somehow simply detect and return the next pressed input. This would likely have to work via callback or event of some sort. The point is that you currently have the functionality already since you are using it to receive input choices by the game players. If you gave us access to that directly, we could then use it to let the player directly press the button/key that they want to use for a modifier. This would work for example if I'm playing a game that needs more buttons than my joystick has. I could choose a should button as a modifier, and then in effect I have almost doubled the amount of inputs(minus the one used for modifier) available, and I got to easily choose the key/button for this purpose instead of depending on the ones currently chosen for me.
     
  33. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Thanks for your kind words, and for your suggestion. It's well thought out and I can see how beneficial it would be.

    While this isn't exactly the same thing, you can already do something similar to what you described. You can just make an action called "Modifier" and let the player customize the modifier using the UI. Then have your code check for both of them like so:

    Code (csharp):
    1. if (cInput.GetKey("Modifier") && cInput.GetKey("Action")) {
    2.     // do some stuff here
    3. }
     
  34. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    Yup, that method works sort of, but indeed, it isn't the same. In any case, thanks for paying attention to the suggestion. Good luck!
     
  35. SinisterCycle

    SinisterCycle

    Joined:
    May 7, 2015
    Posts:
    1
    I desire to allow axis sensitivity modification at runtime with calls to public static void SetAxisSensitivity(string,float), have the changes stored and then restored upon re-execution.

    However, cInput v2.8.5 does not appear to save any changes to axis sensitivity, gravity or deadzone when set with that method nor does there appear to be any public call that allows manually saving of all the axis arrays: _individualAxisSens[], _individualAxisGrav[], or _individualAxisDead[] after they have been modified. The only time cInput::_SaveAxis() appears to be called is within cInput::_SetAxis(int,string,int,int).

    Unfortunately just adding private static void cInput::_SaveAxis() to the bottom of the public static void cInput::SetAxisSensitivity(string,float) method, nor calling public static int cInput::SetAxis(string,string,float,float,float) cause private static void _LoadInputs() to restore axis sensitivity, gravity or deadzone values upon re-execution.

    I believe this is because private static void _LoadInputs() stomps the "cInput_indAxSens", "cInput_indAxGrav", and "cInput_indAxDead" PlayerPrefs strings when it gets the "cInput_axis" string within the if (PlayerPrefs.HasKey("cInput_axis")) call block.

    I have added a saveAxis bool parameter to cInput::_SetAxis which controls if _SaveAxis() gets called and modified _LoadInputs() to prevent stomping the axis arrays. However it also appears that there is an array indexing issue within
    public static int SetAxis() , the first axis pos/neg string data appear to be stored in _individualAxisSens[0] and _individualAxisSens[1] yet _FindKeyByDescription(negInput) returns 1 and _FindKeyByDescription(positiveInput) returns 2 and those values are used to index and store the data.
     
  36. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Thanks for reporting this. I'm out of town and won't be able to get to my computer to look deeper into this issue for another week. Sorry! I'll be sure to look into this when I get back and follow up with a solution then.
     
  37. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Hello,

    I use cInput with RFPS for my game and, can you tell me what video tutorial i need to look for implemented cInput with RFPS please ?

    Thanks :)
     
  38. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Hello,

    I have start all Tutorial, and start to change some input (play with Cinput ^^)

    I have take the code @NightShade2109 but that don't works for me :s



    What i need to drop in :

    Input Item
    and
    Input Panel

    Panel is the canvas no ?

    Thanks :)
     
  39. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Hi Defcon44,

    I don't know what RFPS is, and I couldn't find any related results on the Asset Store when doing a search for that term. Additionally, I'm not sure what your screenshot is of, and I don't know what Input Item or Input Panel would be. Maybe you should ask whoever makes RFPS, since it seems like it's probably related to that.

    I'm going to be looking into this now. Thanks for your patience.
     
  40. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Hi,

    Thanks for you'r reply :)

    Sorry, usually I puts links of RFPS.

    This is not a RFPS script / items, i take this script, made by @NightShade2109 :

    Code (CSharp):
    1.  
    2. // --------------------------------------------------------------------------------------------------------------------
    3. // <copyright file="GUIControls.cs" company="">
    4. //
    5. // </copyright>
    6. // --------------------------------------------------------------------------------------------------------------------
    7. using System.Collections.Generic;
    8. using JetBrains.Annotations;
    9. using UnityEngine;
    10. using UnityEngine.UI;
    11. //-----------------------------------------------------------------------------------------------------
    12. public class GUIControls : MonoBehaviour
    13. {
    14.     private readonly float _mouseSensitivity = 2.0f;
    15.     public GameObject InputItem;
    16.     private List<GameObject> InputItems = new List<GameObject>();
    17.     public GameObject InputPanel;
    18.     public Color DefaultColor;
    19.     public Color HighLightColor;
    20.     // Use this for initialization
    21.     //-----------------------------------------------------------------------------------------------------
    22.     [UsedImplicitly]
    23.     private void Start()
    24.     {
    25.         SetupInput();
    26.         GenerateInputMapper();
    27.         cInput.OnKeyChanged += UpdateText;
    28.     }
    29.     public void UpdateText()
    30.     {
    31.         for (var n = 0; n < cInput.length; n++)
    32.         {
    33.             InputItems[n].transform.FindChild("Primary").FindChild("Text").GetComponent<Text>().text = cInput.GetText(n, 1);
    34.             InputItems[n].transform.FindChild("Primary").GetComponent<Image>().color = DefaultColor;
    35.             InputItems[n].transform.FindChild("Secondary").FindChild("Text").GetComponent<Text>().text = cInput.GetText(n, 2);
    36.             InputItems[n].transform.FindChild("Secondary").GetComponent<Image>().color = DefaultColor;
    37.         }
    38.     }
    39.     //-----------------------------------------------------------------------------------------------------
    40.     public void GenerateInputMapper()
    41.     {
    42.             for (var n = 0; n < cInput.length; n++)
    43.             {
    44.                 var item = Instantiate(InputItem);
    45.                 item.transform.SetParent(InputPanel.transform, false);
    46.                 InputItems.Add(item.gameObject);
    47.                 item.transform.FindChild("KeyName").GetComponent<Text>().text = cInput.GetText(n, 0);
    48.                 item.transform.FindChild("Primary").FindChild("Text").GetComponent<Text>().text = cInput.GetText(n, 1);
    49.                 AddButtonListener(item.transform.FindChild("Primary").GetComponent<Button>(), n, 1);
    50.                 item.transform.FindChild("Secondary").FindChild("Text").GetComponent<Text>().text = cInput.GetText(n, 2);
    51.                 AddButtonListener(item.transform.FindChild("Secondary").GetComponent<Button>(), n, 2);
    52.                 item.SetActive(true);
    53.             }
    54.     }
    55.    //-----------------------------------------------------------------------------------------------------
    56.     private void AddButtonListener(Button button, int id, int type)
    57.     {
    58.         switch (type)
    59.         {
    60.             case 1:
    61.                 button.onClick.AddListener(() => ChangeKeyPrimary(id));
    62.                 break;
    63.             case 2:
    64.                 button.onClick.AddListener(() => ChangeKeySecondary(id));
    65.                 break;
    66.         }
    67.     }
    68.     //-----------------------------------------------------------------------------------------------------
    69.     public void ChangeKeyPrimary(int id)
    70.     {
    71.         cInput.ChangeKey(id, 1);
    72.         InputItems[id].transform.FindChild("Primary").FindChild("Text").GetComponent<Text>().text = "...";
    73.         InputItems[id].transform.FindChild("Primary").GetComponent<Image>().color = HighLightColor;
    74.     }
    75.     //-----------------------------------------------------------------------------------------------------
    76.     public void ChangeKeySecondary(int id)
    77.     {
    78.         cInput.ChangeKey(id, 2);
    79.         InputItems[id].transform.FindChild("Secondary").FindChild("Text").GetComponent<Text>().text = "...";
    80.         InputItems[id].transform.FindChild("Secondary").GetComponent<Image>().color = HighLightColor;
    81.     }
    82.     //-----------------------------------------------------------------------------------------------------
    83.     private void SetupInput()
    84.     {
    85.         cInput.SetKey("Forward", Keys.W, Keys.ArrowUp);
    86.         cInput.SetKey("Backward", Keys.S, Keys.ArrowDown);
    87.         cInput.SetKey("Strafe Left", Keys.A, Keys.ArrowLeft);
    88.         cInput.SetKey("Strafe Right", Keys.D, Keys.ArrowRight);
    89.         cInput.SetKey("Crouch", Keys.LeftControl, Keys.RightControl);
    90.         cInput.SetKey("Jump", Keys.Space, Keys.None);
    91.         cInput.SetKey("Prone", Keys.C, Keys.None);
    92.         cInput.SetKey("Run", Keys.LeftShift, Keys.RightShift);
    93.         cInput.SetKey("Primary", Keys.Mouse0, Keys.None);
    94.         cInput.SetKey("Secondary", Keys.Mouse1, Keys.None);
    95.         cInput.SetKey("Reload", Keys.R, Keys.None);
    96.         cInput.SetKey("Knife", Keys.Q, Keys.None);
    97.         cInput.SetKey("Next Weapon", Keys.MouseWheelUp, Keys.None);
    98.         cInput.SetKey("Previous Weapon", Keys.MouseWheelDown, Keys.None);
    99.         cInput.SetKey("Camera Rotate Left", Keys.MouseLeft, Keys.None);
    100.         cInput.SetKey("Camera Rotate Right", Keys.MouseRight, Keys.None);
    101.         cInput.SetKey("Camera Rotate Up", Keys.MouseDown, Keys.None);
    102.         cInput.SetKey("Camera Rotate Down", Keys.MouseUp, Keys.None);
    103.         cInput.SetKey("Menu", Keys.Escape, Keys.None);
    104.         cInput.SetKey("Scores", Keys.Tab, Keys.None);
    105.         cInput.SetKey("Buy", Keys.B, Keys.None);
    106.         cInput.SetAxis("Horizontal", "Strafe Left", "Strafe Right");
    107.         cInput.SetAxis("Vertical", "Backward", "Forward");
    108.         cInput.SetAxis("MouseX", "Camera Rotate Left", "Camera Rotate Right");
    109.         cInput.SetAxis("MouseY", "Camera Rotate Up", "Camera Rotate Down");
    110.         cInput.SetAxis("Switch Weapon", "Previous Weapon", "Next Weapon");
    111.         cInput.SetAxisSensitivity("MouseX", _mouseSensitivity);
    112.         cInput.SetAxisSensitivity("MouseY", _mouseSensitivity);
    113.         cInput.SetAxisGravity("MouseX", 1000);
    114.         cInput.SetAxisGravity("MouseY", 1000);
    115.     }
    116. }
    And i see @dustinwloring1988 take this script, and that work for him :s
     
  41. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    The best that I can tell is that the InputPanel is a reference to a UI panel and the InputItem is a reference to a UI prefab, probably a button with a label so it can show the name of the input and be clicked to change the input.

    Sorry that I don't know what the script is or how it works for sure. I can't provide support for things made by other people.
     
  42. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I believe I have all of this fixed internally, pending the next cInput release, but I'm not sure I fully understand this last part. In my tests, FindKeyByDescription is returning the correct value used to store and retrieve the data. Or maybe I fixed it while working on another part of cInput without realizing it...
     
  43. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Hello,

    I was trying cInput for the first time with Unity's basic 2D Robot Character and I've noticed what I believe is a bug using an Xbox One controller on a Windows 10 PC connected with USB.

    I assign the basic controls like here (following the reference manual instructions):
    Code (CSharp):
    1.  
    2. void Start () {
    3.      cInput.SetKey("Right", Keys.XboxDPadRight, Keys.RightArrow);
    4.      cInput.SetKey("Left", Keys.XboxDPadLeft, Keys.LeftArrow);
    5.      cInput.SetKey("Up", Keys.XboxDPadUp, Keys.UpArrow);
    6.      cInput.SetKey("Down", Keys.XboxDPadDown, Keys.DownArrow);
    7.      cInput.SetAxis("Horizontal Movement", "Left", "Right");
    8.      cInput.SetAxis("Vertical Movement", "Up", "Down");
    9.  
    10.      cInput.SetKey("Jump", Keys.XboxA, Keys.Space);
    11. }
    Up and down works OK but for some reason Left and Right are mapped to the Right Trigger and not Left/Right on the DPad. If I don't press the RT the character moves to the left, if I press RT it moves to the right and if I keep the RT at the middle it stops.

    Haven't tried with a Xbox 360 for windows controller. Can you reproduce this error?
     
  44. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Hello,

    It's working as expected in my tests, but I'm using an Xbox 360 controller which is what the Keys.Xbox[whatever] was set up with. I don't have an Xbox One gamepad to test with, so my initial hunch would be that the Xbox One gamepad has different axis configurations than the Xbox 360 controller.

    However, from what I can tell after a bit of googling, both the Xbox One and Xbox 360 gamepads should have the same input mappings for the DPad and Triggers. Puzzling...

    When you open the GUI to change inputs, what does it show you the values are for the Xbox DPad controls?

    I see Axis 6+/- for left and right and Axis 7+/- for up and down. And for the triggers, I'm getting Axis 9+ and Axis 10+.
     
  45. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    I'm not at home right now but I'll do some tests later and hopefully come up with a table of values returned by the Xbox One controller. I guess it could be usefull for you since Windows 10 comes with out of the box drivers for this pad and it will probably become the new standard for PC gamepads
     
  46. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Ok, so I've created a brand new Unity project (3D) and just imported from the asset store cInput Pro and opened the cInput demo scene.

    Changing the default buttons with the Xbox One controller here's what I've got:
    • Dpad Left / Right: Joy1 Axis 7- / 7+
    • Dpad Up / Down: Joy1 Axis 8+ / 8- (NOTICE 8+ is up, not 8- )
    • Left Analog Stick Left / Right: Joy1 Axis 4- / 4+
    • Left Analog Stick Up / Down: Joy1 Axis 5- / 5+
    • Right Analog Stick Left / Right: Joy1 Axis 1- / 1+
    • Right Analog Stick Up / Down: Joy1 Axis 2- / 2+
    • A: Joystick1Button0
    • B: Joystick1Button1
    • X: Joystick1Button2
    • Y: Joystick1Button3
    • LB: Joystick1Button4
    • RB: Joystick1Button5
    • Left stick down: Joystick1Button8
    • Right stick down: Joystick1Button9
    • "Select" (well, what used to be select, now it's 2 squares): Joystick1Button6
    • "Start" (Now 3 horizontal lines... menu?) : Joystick1Button7
    And now the weird thing:
    When pressing LT the values would change between Joy1 Axis 3- OR Axis 9+.

    Furthermore, with RT those values are either Axis 6-, 6+ OR 10+.

    Also worth noticing: Sometimes other axis (such as Dpad directions) would register as Joy1 Axis 3-. After pressing again they will return to their more common values listed above but that problem dissapeared after calibrating the controls from the in-game option.

    Hope it can help you
     
  47. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Thanks for this. It's very helpful.

    Triggers were weird with the Xbox 360 gamepad as well. Both triggers were/are mapped to Axis 3, which means if you press them both down equally Axis 3 reads as having a 0 value since each trigger cancels the other one out. That's obviously not an intelligent system. Fortunately, the triggers also map to axes 9+ and 10+ so you can use them both at the same time. cInput tries to detect this if is the case when detecting inputs by checking if both Axis 3 and Axis 9 or 10 are being used at the same time, and if so, it tries to default to 9 or 10. But admittedly it doesn't always work. As far as I can tell this is due to bugs with how Unity detects gamepads, and especially Xbox controllers, as cInput isn't the only custom input manager that exhibits these symptoms

    A more thorough and detailed explanation written by the creator of InControl can be found here.

    So yeah, it looks like I'll need to add some more checks to cInput to get the right values for the Xbox One gamepad. I may also need to invest in an Xbox One gamepad for myself for testing purposes.

    Thanks again!
     
    Last edited: Sep 21, 2015
  48. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Looking around I've found this article from MSDN. Don't know if it helps: http://blogs.msdn.com/b/uk_faculty_...r-support-and-input-to-your-unity3d-game.aspx

    Any Xbox One controller work with the pc, there's no "for windows" version. Any micro USB cable can be used (The "for windows" version just includes a cable so aim for the standard controller)
     
  49. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    That article doesn't say anything about the Xbox One gamepad having different input values than the Xbox 360 gamepad. And it only goes into detail about the Xbox 360 controller's inputs, so I'm afraid it's not that useful. Thanks though.

    As for the Xbox One controller "for Windows," the nice thing about it is that the cable is 9 feet long, so it can stretch pretty far! And in my searches, it seems as though the one with the cable for Windows is cheaper than the ones without.

    Anyway, thanks again!
     
  50. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Hi folks,

    An update to cInput has been submitted to the Asset Store. If you bought cInput from the Asset Store then the update should be live within a few (business) days. If you bought cInput from our website, then the update is available immediately.

    cInput changelog:

    v2.8.7

    • Loading no longer "stomps" axis sensitivity, gravity, and deadzone settings. (Thanks SinisterCycle)
    • cInput only loads settings once on startup.
    • Modifiers now do some sanity checking.
    • Fixed input values not updating while scanning during key rebind. (Thanks Sascha)
    • Other minor bugfixes.