cInput is a custom input manager for Unity. It replaces Unity's built-in input manager and allows game input controls to be changed at runtime, with an easy HUD. It works with gamepads, steering wheels, and of course, the keyboard and mouse.

Kudos to GIL, who added custom input origin settings in ORK Framework 2.3.0 so we can easily integrate cInput. For you programmers, it uses reflection to call a static function of a class. For the rest of us, it means we can integrate cInput with ORK mostly in the Framework window, and with two short scripts that non-programmers can handle. Yes, you can.

The instructions that come with cInput are good. You should look at the cInput documentation and tutorials, which is how I figured it out, but I will walk you through my implementation so you can hear it from a fellow Orkanite.

I use the regular ORK Tutorial and our old friend Brown Pants to keep it simple and familiar. I use cInput Pro which I bought off the asset store, probably when on sale. If you don't need source code, (I don't use it), you can buy cInput 2 for $15 which is exactly the same as Pro but without the source code. If you can't afford the $15, email them and plead your case for a break. Now, to work!

Step 1. You need ORK framework 2.3.0 or higher installed in a Unity3d project. Before you ask, I am already using cInput with Unity 5.0.

Step 2. Download cInput from the Asset Store and import into your project. Then use the "Edit -> Project Settings -> cInput -> Replace InputManager.asset file" menu command in the Unity Editor to create an InputManager.asset file designed to work with cInput. Must do this.

Step 3. Two Set-up Scripts. I place mine in a project folder named "scripts" inside the main "Assets" folder.

Step 3 A. Create a new empty Unity game object in the 0 Main Menu scene (game object -> create empty), and name it cInputOrkTutSetup. This game object is going to hold our default key setup script. Below is the setup script, in C#. Create this script in your project window in the scripts folder and then drag this setup script from your scripts folder onto the cInputOrkTutSetup game object you just created in the 0 Main Menu scene, and of course, save the scene.

using UnityEngine;
using System.Collections;
using ORKFramework;
using ORKFramework.Behaviours;

public class cInputOrkTutSetup : MonoBehaviour // Script name must match class name
{
public GUISkin guiSkin; //inspector drag on for skin
public Color menuColor = new Color(0.09f, 0.77f, 1, 1); //inspector for change color

void Start()
{

cInput.Init(); // initialize cInput

cGUI.cSkin = guiSkin; // cGUI setup commands
cGUI.bgColor = menuColor;

cGUI.windowMaxSize = new Vector2(1024, 600); //defaults to 1024x600

// Pause key
cInput.SetKey("Pause", "P"); // sets the 'Pause' default input to "P"

//Keys for the movement axes
cInput.SetKey("Left", "A", "LeftArrow"); // 'Left' inputs are 'A' or 'LeftArrow'
cInput.SetKey("Right", "D", Keys.RightArrow); //can define by string or Key Class
cInput.SetKey("Up", "W", Keys.UpArrow);
cInput.SetKey("Down", "S", Keys.DownArrow);

// Now we define the axes:
cInput.SetAxis("Horizontal", "Left", "Right"); // 'Horizontal' axis takes 'Left' and 'Right'
cInput.SetAxis("Vertical", "Up", "Down"); // 'Vertical' axis 'Up' and 'Down' as inputs.

// (Note: Later you may discover you need to invert one of your axes.
// GIL gave us a check box under Key Settings for that purpose.)

//The rest of the default ORK tutorial keys I used.
cInput.SetKey("Accept","Mouse1"); // 3: Accept in Ork tut demo
cInput.SetKey ("Cancel","RightControl"); // 4: Cancel
cInput.SetKey ("Battle Menu","LeftControl"); // 5: Battle Menu
cInput.SetKey ("Attack","Mouse0"); // 6: Attack
cInput.SetKey("Menu","Escape"); // 8: Menu
cInput.SetKey("Jump","Space"); //Jump default is Space key

}
}


Step 3B. The second C# script is much shorter. Name it "cInputOrkTut" and place it in your project scripts folder with the other script.

using UnityEngine;
using System.Collections;
using ORKFramework;
using ORKFramework.Behaviours;

public class cInputOrkTut : MonoBehaviour {

void Update()
{
// We use Unity's Input class here (instead of cInput) for calling the HUD
// because we don't want the player to accidentally change (and maybe forget)
// which key opens the cInput GUI menu, ("doh!").

if (Input.GetKeyDown(KeyCode.K) && !cInput.scanning)
{
cGUI.ToggleGUI();
}
}
}

Drag this script from the scripts folder in the project window onto your Brown Pants prefab in the ORK Tutorial Resources folder, under Prefabs, under Combatants. At this point I saved the project, and for good measure, the scene again. Extra saving, always good.

Step 4. Setting up ORK custom input keys.

Note: Before we start, let me mention one thing that you will see below. When setting up ORK custom inputs, we enter Unity3d "function" names. For the horizontal and vertical axes we use "GetAxis", for individual key pressing we will use "GetKeyDown" If and when you add Sprint to your game, the function name will be "GetKey" because we want Sprint to continue the entire time the key is held down. So for Sprint, use "GetKey" and not "GetKeyDown".

Go to the Unity menu and open the Ork Framework window: windows -> ORK Framework.

Click on Base/Control, and then click on Input Keys

We need to set-up the Horizontal and Vertical axes, and the rest of the keys, to match with the defaults we set up in our cInputOrkTutSetup script. These keys are already setup in the ORK Tutorial, but we are going to change them to "Custom" inputs.

Click on 1: Horizontal and change it to:

Name: Horizontal
Input Origin: Custom
Class Name: cInput
Under Custom Axis Function change the name to: GetAxis
Click the Add Parameter button (under Custom Axis Function NOT under Custom Button Function) and change the type and string value to:
Parameter Type: String
String Value: Horizontal

Note: if you remember our setup script, you may have noticed that we are not doing much more than plugging the information from the script key defaults into the areas GIL has provided for us.

Click on 2 Vertical and change it to:

Name: Vertical
Input Origin: Custom
Class Name: cInput
Under Custom Axis Function change the name to: GetAxis
Click the Add Parameter button and change the type and string value to:
Parameter Type: String
String Value: Vertical

Click on "3: Accept" and change the settings to:

Name: Accept
Input Origin: Custom
Class Name: cInput
Under Custom Button Function, (now it's Button, not Axis), change the name to: GetKeyDown
Click Add Parameter and change the parameter and string to:
Parameter Type: String
String Value: Accept

Do the same for every other button you listed in the cInputOrkTutSetup script, being:
Cancel
Battle Menu
Attack
Menu
Jump (note: While the Ork Tutorial did not, I set up Jump in the Ork Framework window under Base Control -> Game Controls -> Player Controls, Jump Settings. Just check the box "Use Jump" and change the "Jump Key" name to the custom key you added, which we named "Jump". The other defaults under Jump Settings are good for now.

If you have not already, save Settings and Confirm at the bottom of the Ork Framework Window.

In the immortal words of GIL, "Time to Test!"

Close the ORK Framework window, load scene 0 Main Menu, click start and when your character appears in the Town scene hit the "k" key, which we set under standard Unity input to open the cInput GUI. It should come right up. To change a key, mouse click on the key then hit the new key. That's it.

All your inputs should work, including Jump, which we did set up. Of course, if you are not using the finished Ork Tutorial, and you have not reached the lesson on Menu, nothing will come up when you hit the LeftControl (Menu) key. Just common sense.

If you pause Unity and look in the hierarchy window, you will see the "cObject" that was automatically added to your scene. If you un-pause and walk your player through the Ork scene changer to the Field scene you will be pleased to discover that the inputs continue to work despite the scene change, and with no additional programming on our part, thanks to cInput.

That's it for now. This is a draft. If you know a really easy and reliable way to get my windows snipping tool image shots into this forum post, please let me know. Enjoy!
Sign In or Register to comment.