Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

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

  1. Goblox

    Goblox

    Joined:
    Nov 3, 2012
    Posts:
    178
    Perfect, That's solved it. Thanks.
     
  2. 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 changes:

    v2.5.9
    • Fixed SetAxis overload function not working properly. (Thanks Goblox)
    Additionally, I just received notification that cInput v2.5.8 has been accepted and should be available for download on the Asset Store.
     
  3. Goblox

    Goblox

    Joined:
    Nov 3, 2012
    Posts:
    178
    It does work fine on the web demo.

    I calibrated the same way in my app but I get exceptions when attempting to assign.

    I'm assuming my issue is related to this:

    Code (csharp):
    1. Failed to get any cases for Joy1 Axis 1. Using main raw value of 0. This should never happen, in theory.
    2. UnityEngine.Debug:LogError(Object)
    3. cInput:_GetCalibratedAxisInput(String) (at Assets/Plugins/cMonkeys/cInput.cs:529)
    4. cInput:_InputScans() (at Assets/Plugins/cMonkeys/cInput.cs:1925)
    5. cInput:Update() (at Assets/Plugins/cMonkeys/cInput.cs:187)
    I get an exception for each axis of each joystick cInput looks at except for joy2 axis > 3 (1 2 and 3 give exceptions.)

    Joy2 axis 3 (The axis that is instantly detected) gives something slightly different:

    Code (csharp):
    1. Failed to get any cases for Joy2 Axis 3. Using main raw value of 1. This should never happen, in theory.
    2. UnityEngine.Debug:LogError(Object)
    3. cInput:_GetCalibratedAxisInput(String) (at Assets/Plugins/cMonkeys/cInput.cs:529)
    4. cInput:_InputScans() (at Assets/Plugins/cMonkeys/cInput.cs:1925)
    5. cInput:Update() (at Assets/Plugins/cMonkeys/cInput.cs:187)
    It has a "Main raw value of 1" instead of 0. All other exception messages say "0" for raw value.
     
    Last edited: Oct 2, 2013
  4. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    cInput v2.5.8 should have fixed those exceptions from occurring (but not necessarily the calibration issue you're talking about).

    The problem seems to be that, as you said, the pedals are reversed. Not pushing the pedal gives a value of 1, which Unity (and cInput) take to mean that it is in fact being pushed. This is why it is instantly selected when you try to change inputs using the GUI. It sees it as being pushed. The calibration function used to take this into account, but now it seems to work in every case except when assigning an input using the GUI.

    Interesting. I'll be looking into a fix for this. Thanks.
     
  5. Goblox

    Goblox

    Joined:
    Nov 3, 2012
    Posts:
    178
    Isn't it odd that this wheel appears to work fine in your webdemo?
     
  6. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Not exactly. As I said, the calibration function used to take this into account. But then we made some pretty big changes to the internals of cInput and apparently this got broken in the process. The webdemo actually hasn't been updated to the latest cInput version. Hence the different graphics and GUI and all that. Thanks for the reminder to update the webdemo.
     
  7. Goblox

    Goblox

    Joined:
    Nov 3, 2012
    Posts:
    178
    Let me know when you've got something; I'd love to try it.

    And if you had an ETA or a workaround in the mean time, I'd appreciate it. This pretty much means I can't use my beloved G25 at the moment.
     
    Last edited: Oct 4, 2013
  8. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I just received notification that cInput 2.5.9 is now live on the Asset Store.

    I sent you a PM a few days ago with a potential fix that I'd like you to test for me. If you got it and it's working fine, please let me know so I can submit the update. If you didn't get it, please send me a PM with an e-mail address I can send an updated script to for you to test with.

    Thanks!
     
  9. Goblox

    Goblox

    Joined:
    Nov 3, 2012
    Posts:
    178
    Ha - I've been checking this thread multiple times a day and didn't see the teeny tiny notification =/

    The link expired though, resend it and I'll check it out.
     
  10. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    PM Sent. (c:
     
  11. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hi Deozaan,

    I'm wondering whether you managed to fix the gamepad joystick/mouse issue I found a few pages back? I've got a very similar setup to the person using it then:

    Code (csharp):
    1.  
    2. cInput.SetKey("Look Up", "Mouse Up", "Joy1 Axis 5-");
    3. cInput.SetKey("Look Down", "Mouse Down", "Joy1 Axis 5+");
    4. cInput.SetKey("Look Left", "Mouse Left", "Joy1 Axis 4-");
    5. cInput.SetKey("Look Right", "Mouse Right", "Joy1 Axis 4+");
    6.  
    7. cInput.SetAxis("Look Horizontal", "Look Left", "Look Right");
    8. cInput.SetAxis("Look Vertical", "Look Down", "Look Up");
    9.  
    But when I use GetAxisRaw neither the mouse nor the game pad work. Removing the Mouse inputs makes the game pad work, but the mouse doesn't seem to work if I remove the game pad inputs. Any ideas are appreciated!
     
  12. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    115
    I was curious if there's a way to let players assign modifiers?

    I'm looking for an input manager for my game, and this seems promising. But I'd like players too be able to press "Left Shift + Space bar" and have that be bound to a key. Trying out the web player demo it only allowed single key inputs to be bound.

    I know you can set permanent modifiers using SetKey, but I was wondering if this is capable of doing that at runtime from player input.
     
  13. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I think I must have missed it being mentioned. I don't have a fix for it, but I'll look into it. I've got it duplicated. It seems as though GetAxis works, but GetAxisRaw always returns 0.

    Yes, cInput does support modifiers. But in order for cInput to know whether or not "Left Shift" should be allowed as a key by itself or as a modifier, you need to set up which keys should be designated as modifiers in your code.

    The reason this didn't work for you in the web player demo is because we have neglected to update the web player demo since the very initial release of cInput 2.0! Thanks for the reminder. I've just updated it to the most recent version (2.5.9) which shows off using a modifier for the "Shoot" button.
     
  14. 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 changes:

    v2.6.0
    • Fixed immediately selecting an axis that gives non-zero value by default. (Thanks Goblox)
    • Fixed cases where GetAxisRaw always returned 0. (Thanks gumboots)
    • Fixed cases where GetAxis would sometimes return twice the value it should have. (Thanks Goblox)
    • Fixed some issues with axis calibration.
     
  15. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    Hello, i didnt find from your site / documentation if cInput supports two player split-screen? I mean for example handling keyboard for player1 and joystick for player2. Cant really imagine why it wouldn't, but just to be sure :)
     
  16. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Yes, it does support multiple players. (c:
     
  17. MarkN

    MarkN

    Joined:
    Sep 24, 2013
    Posts:
    10
    Hi. I bought cInput yesterday and got the basics working in no time. Nice job guys.

    However I later managed to break things in a really confusing manner (for someone who is lousy at debugging and a newcomer to Unity/MonoDevelop, at least). MonoDevelop was flagging cInput.cs as the problem when the error was in my script, so I thought I'd post what happened in case it's of use.

    Basically, everything going well until I started setting up a simple state system in my player script (c#) with an enum and an int.

    Code (csharp):
    1. enum states {dormant, spawning, normal}
    2. int state;
    In Start() I then accidentally tried to set states to a value rather than state.

    Code (csharp):
    1. states = (int)states.dormant;
    MonoDevelop then flagged line 321 of cInput.cs as an issue with the message - Default parameter specifiers are not permitted.

    Code (csharp):
    1. private static void _SetKey(int _num, string _name, string _input1, string _input2 = "") {
    I tried removing the default = "", and that just escalated things with more errors, and since I'd had a glass of wine or two I wisely decided to leave it alone at that point.

    This morning I spotted the actual problem in my code and fixed it without a hitch (also spotted Unity was telling me where the bug was correctly, whilst MonoDevelop was still maintaining it was cInput).

    Anyway - thought this might be of use if you get any other folk hitting the same issue.
     
  18. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    Last edited: Oct 23, 2013
  19. MarkN

    MarkN

    Joined:
    Sep 24, 2013
    Posts:
    10
    Sorted! Many thanks.
     
  20. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    There seams to be a problem with using Mouse Wheel Up and Mouse Wheel Down with GetKeyUp and GetKeyDown. None seam to work anymore. I was using scroll up/down to zoom in/out, which no longer works. I see the binding is still there and no errors are thrown when using the keys either. Any idea what's going on? Is the usage changed in latest release? Broken somehow perhaps? I also know my code is working fine, because if I bind to say arrow up and arrow down it zooms in and out perfectly fine again.
     
    Last edited: Oct 27, 2013
  21. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I've been able to duplicate the issue and am working on a fix. Thanks.
     
  22. KeithT

    KeithT

    Joined:
    Nov 23, 2011
    Posts:
    83
    2.6.0 does not seem to have an inputmanager in it.

    Can you check please ?

    I also can't get the editor menu item to appear, when trying to use the replace input manager funtion.
     
    Last edited: Nov 4, 2013
  23. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    The menu item should be in Edit -> Project Settings -> cInput.

    If the menu item isn't working for some reason, just go into your Assets/cMonkeys/cInput/Editor folder and copy cInput.dat into your ProjectSettings folder, then rename it to InputManager.asset, overwriting the existing InputManager.asset file.
     
  24. PrimeAlly

    PrimeAlly

    Joined:
    Jan 2, 2013
    Posts:
    35
    Any status update on using the mouse scroll wheel? I just bought this package on the asset store and can't find any keys for mouse scrolling..
     
  25. PrimeAlly

    PrimeAlly

    Joined:
    Jan 2, 2013
    Posts:
    35
    Ok just realized MouseWheelDown/MouseWheelUp works. I thought they referred to pressing the mouse wheel button but apparently its scrolling :)
     
  26. PrimeAlly

    PrimeAlly

    Joined:
    Jan 2, 2013
    Posts:
    35
    Just noticed that there is no mouse acceleration in cInput. Unity's Input class uses mouse acceleration by default and has no option for turning it off (AFAIK).

    Most FPS games (and some other) offer an option of turning mouse acceleration on/off. Would this be possible with cInput? Alternatively could you add an option for this to the API?
     
  27. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I've fixed the issue with Mouse Scroll Wheel. The next release of cInput will have it.

    Mouse Wheel Button is typically Mouse2 (the third mouse button, starting from 0).

    AFAIK cInput uses Unity's Input class to get the mouse axis values, but clamps the values between -1 and 1 to maintain compatibility across axes.
     
  28. KeithT

    KeithT

    Joined:
    Nov 23, 2011
    Posts:
    83
    Caps-Lock key does not work in the WebPlayer on a Mac, tested on several macbooks and a Mini-Mac. Same code works fine on a PC.

    I think this is a CInput2 issue, any suggestions ?
     
  29. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    What do you mean when you say it doesn't work? It doesn't give a value? Or it doesn't bind in the GUI?

    Does the capslock key work (give a value) using Unity's input system (i.e. Input.GetKeyDown(KeyCode.CapsLock))?
     
  30. KeithT

    KeithT

    Joined:
    Nov 23, 2011
    Posts:
    83
    Don't know answers to some of this, just have clients moaning about it at the moment, so need to do more investigation.

    Very simple code involved:

    In the setup class:
    cInput.SetKey(EquipmentHold, Keys.CapsLock);

    In Update()

    if(cInput.GetKeyDown(inputSetup.EquipmentHold))
    {
    Do our stuff, which is show a GUI.Label
    }
     
  31. PrimeAlly

    PrimeAlly

    Joined:
    Jan 2, 2013
    Posts:
    35
    Ok I tested commenting out the clamping in cInput.cs on rows 563, 570, 1018 and 1019 which seems to work fine.

    However, I don't like hacking "core" and would like to suggest that you add an option to turn clamping on/off via a property. That way I can keep compatibility with your code and also upgrade to new releases.
    What do you think?
     
  32. PrimeAlly

    PrimeAlly

    Joined:
    Jan 2, 2013
    Posts:
    35
    Ok I tested commenting out the clamping in cInput.cs on rows 563, 570, 1018 and 1019 which seems to work fine.

    However, I don't like hacking "core" and would like to suggest that you add an option to turn clamping on/off via a property. That way I can keep compatibility with your code and also upgrade to new releases.
    What do you think?
     
  33. PrimeAlly

    PrimeAlly

    Joined:
    Jan 2, 2013
    Posts:
    35
    Hmm, happened to post twice as I didn't see my first post. Maybe an admin can remove it?
     
  34. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    hey Lorodion. This is actually not a bad idea. Deozaan and me will see if and how we can implement this the best way in cInput.

    Thanks for your suggestion !
     
  35. 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 changes:

    v2.6.1

    • Corrected installation instructions in readme file.
    • Fixed GetKeyUp and GetKeyDown always returning false for Mouse Wheel. (Thanks Krileon)
    • Replaced cInput.dat with plaintext version.
     
  36. KeithT

    KeithT

    Joined:
    Nov 23, 2011
    Posts:
    83
    On a Macbook Pro 13" Mid-2010, OSX Mountain Lion, Unity 4.2.2f1) it's impossible to detect if the user has pressed the CapsLock key using any of the following functions: Input.GetKey(), Input.GetKeyDown(), Input.GetKeyUp().

    So guess this is a Unity not CInput issue
     
  37. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    That's a strange issue. Be sure to file a bug report with Unity and hopefully it will get fixed.
     
  38. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Edit: Never mind. Stupid error on our part. cInput works very well! :)
     
    Last edited: Nov 20, 2013
  39. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    We are well on our way to implement cInput in our relatively complex project. One worry I have though is that we are setting up a lot of keys and axis in the project. I would guess we will have 5-6 axis and 40ish keys. (Do not ask why ;-) ).

    I have noticed cInput polls everything every frame. Will this become a performance issue with this number of controls to poll?
    Had we implemented a system of our own we would have just polled a subset of the actions each frame (as they are not all active at once).

    Any basis for my concern? Thanks in advance!
     
  40. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I don't have Unity Pro, so I can't do any profiling, but as far as I'm aware polling 40 different keys each frame isn't a big deal. If you're using cInput terms when you say 5-6 axes and 40ish keys, then you're really only polling the "keys" each frame and cInput is generating the axes based on the values from the keys. But if you're talking about 40ish keyboard keys and 5-6 gamepad/mouse axes, then that's still 50-ish things to poll each frame which I believe any modern PC should handle easily.

    But I suppose the caveat is that, like I said, I don't have Unity Pro, so I can't do any profiling to actually see the effect cInput has. But I don't think it will be a problem.
     
  41. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Thanks for the reply!

    We will profile it as soon as we have the complete system up and running and if it turns out to be a problem we will implement a solution. Our case might be special since we have context sensitive control modes (think Battlefield for example where you have "on foot" controls that differs from "in vehicle" etc.). So looping through lots of keys that are not relevant to the current context just feels bad.

    The solution (if you would be interested in implementing it for others) would be to keep a record of which keys to poll, and update that based on the context. So instead of looping through cInput itself you would loop through another record that is updated on the fly. Looks very easy to implement as an option in cInput.
    But as I said, maybe it is not worth the time at all. I will let you know our profiler results as soon as we have them. :)
     
  42. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    I finally bought cInput couple days ago, and tested it today. Indeed, there is no any problem having two player settings with any combination with keyboard and multiple pads. It didnt took too long to set up cInput to existing inputcontrol code i had.

    There were couple things to figure out, and i think you might want to fix your docs and vids. In your tutorial video at the time (http://www.youtube.com/watch?v=pd5Q9VBYz6w#t=96) you talking about inputmanager.zip, but i didnt find it. Okay, in Readme.txt its explained:

    I understand its new version of script, and earlier tutorial video is older, but If only two files is still needed, why would i want to import demoscene and all ..and risk to mess my project.. so i tried to go how it is instructed in tutorial. Okay, so without EditorScript in Editor folder, there is no menuitem in Edit -> Project Settings (to add ..or replace this InputManager.asset file) So (not a big thing) i had to figure out where this InputManager.zip or InputManager.asset is, and i found out its a file named cInput.dat. It would have been much easier to find, if it was named InputManager.asset like it is in Unity's project folder. Just saying, keep it simple, dont try to make it too pro, after all we are just developers trying to make games :)

    Anyway, i want to say: this is best asset i ever bought.

    If there is anyone out there who does not like unity builtin input system, get cInput and you will sleep better.
     
  43. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    I believe you could also get similar functionality by temporarily changing the bindings to Keys.None when they're out of context. But I'm not sure if what would be easier to do than what you've got in mind.

    Thanks for your feedback. We tried to include it with that filename when we first launched cInput 2 on the Asset Store, but for some reason importing a .unitypackage file that contained a .asset file made Unity crash. That's why we zipped it up.

    I'll make some changes to the documentation and see if I can add some annotations to the video tutorial to clarify things.

    Thank you for the endorsement. If you haven't already, and you'd like to, you could also leave your recommendation for cInput as a review on the Asset Store page, where others are more likely to see it.

    Thanks!
     
  44. morten_nost

    morten_nost

    Joined:
    Nov 28, 2013
    Posts:
    6
    I don't seem to be able to set the sensitivity of an axis. Neither within the SetAxis-function nor the SetAxisSensitivity-function.

    "cInput.SetAxis("GUICursorHorizontal", "GUICursorLeft", "GUICursorRight", sensitivityFloat);" does nothing.
    "cInput.SetAxisSensitivity("GUICursorHorizontal", sensitivityFloat);" returns an IndexOutOfRangeException in cInput.cs (line 455).

    So, the axis cannot be found in the cInput-array, and thus the sensitivity cannot be set..

    Anyone have any ideas?
     
  45. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    We are aware of a bug in the sensitivty/gravity/deadzone settings and are working on a fix.

    In the mean time you can set it if you set all 3 settigns in setaxis:

    cInput.SetAxis(GUICursorHorizontal", "GUICursorLeft", "GUICursorRight", 100f, 0 ,0);

    - We will bring out a fix asap
     
  46. morten_nost

    morten_nost

    Joined:
    Nov 28, 2013
    Posts:
    6
    Thanks! I will give that a go :)
     
  47. KarnEdge

    KarnEdge

    Joined:
    Nov 16, 2013
    Posts:
    3
    Is it possible to set more than 2 inputs for one key?

    e.g.;
    cInput.SetKey("Left", "A", "LeftArrow", "Mouse Left", "Joy1 Axis 1-");
    cInput.SetKey("Right", Keys.D, Keys.RightArrow, "Mouse Right", "Joy1 Axis 1+");
    cInput.SetAxis("Horizontal Movement", "Left", "Right");

    The only time I can see this would be needed is for directions since you may have 2 sets of directions on the Keyboard and a gamepad with a directional pad and a joystick on it. I would like to make it so the gamepad is already setup if you plug it in with defaults that runs in parallel with the keyboard and mouse. Unity's Input Manager already does this since you define the same GetButton name and just have different keys set for it.

    Also, I noticed (at least with your demo) it's not possible to get to the menu with a gamepad. I imagine you could do a SetKey for user defined access to the menu along with the default: Esc. Problem I would see in the future would be if the game was ported to XBox (or whatever) and they could accidently prevent their own access to the menu like you've pointed out before. Do you guys have any ideas on what you would do to prevent that?

    EDIT: Actually, with that last question, I think a good way would be to keep your Esc menu access no matter the medium and the developer set up a auto swap of buttons. They would use "#if UNITY_XBOX" conditional and grab an array of all the buttons on the gamepad, and if one button is set, another one is swapped out. This would make it impossible to set menu to None. Another option would be if you guys to add a method like ForbidKey but used with .ChangeButton to require an input before its saved.

    So, I guess what I'm asking is it possible to add a method like .ChangeButtonRequired and it would not allow None to be saved and it would clear to some predefined defaults.
     
    Last edited: Nov 30, 2013
  48. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    The short answer is no, but there's a workaround.

    The longer answer is that since cInput uses strings to label keys and axes, we can't allow multiple with the same name or else we won't know which one to change when ChangeKey is called. We recommend if you need more than 2 inputs for an input or an axis, that you just make a second set and then refer to both of them in your code. For example:

    Code (csharp):
    1.  
    2. cInput.SetKey("Left", "A," "LeftArrow");
    3. cInput.SetKey("Right", "D", "RightArrow");
    4. cInput.SetKey("Left2", "Mouse Left", "Joy1 Axis 1-");
    5. cInput.SetKey("Right2", "Mouse Right", "Joy1 Axis 1+");
    6.  
    7. cInput.SetAxis("Horizontal", "Left", "Right");
    8. cInput.SetAxis("Horizontal2", "Left2", "Right2");
    9.  
    10. // elsewhere in your code....
    11. // check for both Lefts to see if there's any input on them
    12. if (cInput.GetKey("Left") || cInput.GetKey("Left2")) {
    13.     // move left
    14. }
    15.  
    16. // check both horizontal axes to see if there's any input
    17. if (cInput.GetAxis("Horizontal") != 0) || cInput.GetAxis("Horizontal2") != 0) {
    18.   // handle axis movement
    19. }
    20.  
    Alternatively, you can also have some preset mappings for keyboard or gamepad controls, and just use ChangeKey() to swap your "Left" and "Right" inputs from keyboard controls to mouse or gamepad controls.

    The demo can't access the menu from a gamepad because we didn't code it to bring up the menu with a gamepad. But you could very easily do that. What we do in the demo is we use Unity's built in Input class to bring up the menu. i.e.:

    Code (csharp):
    1. if (Input.GetKey(KeyCode.Esc)) {
    2.     //toggle menu
    3. }
    This prevents the menu button from even showing in the cInput GUI, and thus prevents the player from changing it. You could do something similar with a gamepad button, and use ForbidKey to keep the user from binding that key to something else.

    Final note: I wrote all the above code here in the forum reply box, so I didn't have the luxury of auto-complete making sure there were no syntax errors or other problems. Copy and paste at your own risk. (c:
     
  49. KarnEdge

    KarnEdge

    Joined:
    Nov 16, 2013
    Posts:
    3
    This will work for now. Is there a possibility for more than 2 in the future?

    This sounds better than the first option since you will never use more than one controller type as that would be silly. I hate to ask but do you have an example of how you would have default SetKeys for keyboard and ones for a gamepad?

    Only thing I can think of would be to have a SetKey for whatever default input you want: Keyboard/Mouse. And then have a Drop Down Box in the GUI menu to switch to Gamepad and it would call a function that would ChangeKey on all options at once.

    Maybe better suggestion than allowing more than 2 inputs would be to allow different sets of input defaults to PlayerPrefs.

    Something to the effect of this:
    Code (csharp):
    1. cInput.AddType("Keyboard");
    2. cInput.AddType("Gamepad");
    3.  
    4. cInput.SetKey("Keyboard", "Pause", "P");
    5. cInput.SetKey("Gamepad", "Pause", Keys.JoystickButton7);
    6.  
    7. cInput.ChangeKey("Keyboard", "Pause", 1);
    AddType would work like AddModifier. Sorry, this is probably making the scope of your Plugin way too complicated lol. Not to mention backwards compatibility would be an issue here unless you made it completely separate.

    I only bring this up because on game systems, they won't have access to Esc, but it still risky to set a hardcoded gamepad button to the menu.

    Thank you for your time, I hope you can consider a possibility for more than 2 inputs!

    cInput is fantastic!
     
  50. Deozaan

    Deozaan

    Joined:
    Oct 27, 2010
    Posts:
    707
    That's very unlikely because as I said, if you have two inputs named "Left" and you call ChangeKey("Left") then how is cInput supposed to know which Left you want to change?


    Something like this:

    Code (csharp):
    1.  
    2. void Start() {
    3.     // initialize the controls with the default input method, which is keyboard in this example
    4.     cInput.SetKey("Left", "A", "LeftArrow");
    5.     cInput.SetKey("Right", "D", "RightArrow");
    6.     cInput.SetKey("Jump", Keys.Space);
    7.     cInput.SetKey("Shoot", "Z");
    8.  
    9.     cInput.SetAxis("Horizontal", "Left", "Right");
    10. }
    11.  
    12. // call this function to set the inputs to keyboard
    13. void UseKeyboard() {
    14.     cInput.ChangeKey("Left", "A", "LeftArrow");
    15.     cInput.ChangeKey("Right", "D", "RightArrow");
    16.     cInput.ChangeKey("Jump", Keys.Space);
    17.     cInput.ChangeKey("Shoot", "Z");
    18. }
    19.  
    20. // call this function to set the inputs to gamepad
    21. void UseGamePad() {
    22.     cInput.ChangeKey("Left", "Joy1 Axis 1-");
    23.     cInput.ChangeKey("Right", "Joy1 Axis 1+");
    24.     cInput.ChangeKey("Jump", Keys.JoystickButton1);
    25.     cInput.ChangeKey("Shoot", Keys.JoystickButton2);
    26. }
    27.  
    With code similar to what is shown above, you could have a dropdown menu or whatever you'd like to allow the player to choose which input method to use. And when they select a certain input method, call the corresponding function to set the keys to the appropriate input method.

    As for making sure there's a key assigned to the menu button, you could do something like:

    Code (csharp):
    1. if (cInput.GetText("Menu") == "None") {
    2.     cInput.ChangeKey("Menu", Keys.Escape);
    3. }
    This will ensure that your menu key is always assigned to something.