295 lines
19 KiB
HTML
295 lines
19 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/BasicTemplate.dwt" codeOutsideHTMLIsLocked="false" -->
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<!-- InstanceBeginEditable name="doctitle" -->
|
|
<title>Rewired Documentation | Quick Start</title>
|
|
<!-- InstanceEndEditable -->
|
|
<!-- InstanceParam name="isRoot" type="boolean" value="false" -->
|
|
<!-- InstanceParam name="wide" type="boolean" value="false" -->
|
|
<link href="files/css/styles.css" rel="stylesheet" type="text/css" />
|
|
<!-- Favicons -->
|
|
<link rel="icon" type="image/x-icon" href="/projects/rewired/files/images/favicon.ico?v=1" />
|
|
<!-- Apple Icons -->
|
|
<!-- For iPad with high-resolution Retina display running iOS = 7: -->
|
|
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="files/images/favicon_152x152.png?v=1">
|
|
<!-- For iPad with high-resolution Retina display running iOS = 6: -->
|
|
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="files/images/favicon_144x144.png?v=1">
|
|
<!-- For iPhone with high-resolution Retina display running iOS = 7: -->
|
|
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="files/images/favicon_120x120.png?v=1">
|
|
<!-- For iPhone with high-resolution Retina display running iOS = 6: -->
|
|
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="files/images/favicon_114x114.png?v=1">
|
|
<!-- For the iPad mini and the first- and second-generation iPad on iOS = 7: -->
|
|
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="files/images/favicon_76x76.png?v=1">
|
|
<!-- For the iPad mini and the first- and second-generation iPad on iOS = 6: -->
|
|
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="files/images/favicon_72x72.png?v=1">
|
|
<!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
|
|
<link rel="apple-touch-icon-precomposed" href="files/images/favicon_57x57.png?v=1">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
<div class="container">
|
|
|
|
<div class="google-search-bar">
|
|
<script>
|
|
(function() {
|
|
var cx = '007961148920562332911:oocvtwz5jce';
|
|
var gcse = document.createElement('script');
|
|
gcse.type = 'text/javascript';
|
|
gcse.async = true;
|
|
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
|
|
var s = document.getElementsByTagName('script')[0];
|
|
s.parentNode.insertBefore(gcse, s);
|
|
})();
|
|
</script>
|
|
<gcse:search></gcse:search>
|
|
</div>
|
|
|
|
<div class="content">
|
|
|
|
|
|
|
|
<div class="page-body">
|
|
|
|
|
|
|
|
|
|
<div class="sidebar-nav">
|
|
<h4><a href="Documentation.html">Documentation</a></h4>
|
|
<ul>
|
|
<li><a href="Overview.html">Overview</a></li>
|
|
<li><a href="ReleaseNotes.txt">Release Notes</a></li>
|
|
</ul>
|
|
<strong>Essentials:</strong>
|
|
<ol>
|
|
<li><a href="Installation.html">Installation</a></li>
|
|
<li><a href="QuickStart.html">Quick Start</a></li>
|
|
<li><a href="BasicUsage.html">Basic Usage</a></li>
|
|
<li><a href="Deployment.html">Deployment</a></li>
|
|
<li><a href="BestPractices.html">Best Practices</a></li>
|
|
<li><a href="RewiredEditor.html">Rewired Editor</a></li>
|
|
<li><a href="http://guavaman.com/projects/rewired/docs/api-reference" target="_blank">API Reference</a></li>
|
|
</ol>
|
|
<strong>Concepts:</strong>
|
|
<ul>
|
|
<li><a href="InputManager.html">Input Manager</a></li>
|
|
<li><a href="Players.html">Players</a></li>
|
|
<li><a href="Actions.html">Actions</a></li>
|
|
<li><a href="InputBehaviors.html">Input Behaviors</a></li>
|
|
<li><a href="Controllers.html">Controllers</a></li>
|
|
<li><a href="ControllerMaps.html">Controller Maps</a></li>
|
|
<li><a href="ControllerTemplates.html">Controller Templates</a></li>
|
|
<li><a href="MapCategories.html">Map Categories</a></li>
|
|
<li><a href="Layouts.html">Layouts</a></li>
|
|
<li><a href="LayoutManager.html">Layout Manager</a></li>
|
|
<li><a href="MapEnabler.html">Map Enabler</a></li>
|
|
<li><a href="CustomControllers.html">Custom Controllers</a></li>
|
|
</ul>
|
|
<strong>Extras:</strong>
|
|
<ul>
|
|
<li><a href="ControlMapper.html" title="Control Mapper">Control Mapper</a></li>
|
|
<li><a href="Glyphs.html" title="Glyphs">Glyphs</a></li>
|
|
<li><a href="TouchControls.html" title="Touch Controls">Touch Controls</a></li>
|
|
<li><a href="UnityInputOverride.html" title="Unity Input Override">Unity Input Override</a></li>
|
|
</ul>
|
|
<strong>Misc:</strong>
|
|
<ul>
|
|
<li><a href="RewiredStandaloneInputModule.html">Rewired Standalone Input Module</a></li>
|
|
<li><a href="ComponentControls.html" title="Component Controls">Component Controls</a></li>
|
|
<li><a href="PlayerControllers.html" title="Player Controllers">Player Controllers</a></li>
|
|
<li><a href="InputMapper.html" title="Input Mapper">Input Mapper</a></li>
|
|
<li><a href="UserDataStore.html" title="User Data Store">User Data Store</a></li>
|
|
<li><a href="CustomPlatforms.html" title="User Data Store">Custom Platforms</a></li>
|
|
<li><a href="Localization.html" title="Localization">Localization</a></li>
|
|
</ul>
|
|
<strong>How To's:</strong>
|
|
<ul>
|
|
<li><a href="HowTos.html">See all topics...</a></li>
|
|
</ul>
|
|
<strong>Help:</strong>
|
|
<ul>
|
|
<li><a href="SupportedControllers.html" title="Supported Controllers">Supported Controllers</a></li>
|
|
<li><a href="Overview.html#tested-platforms" title="Tested Platforms">Tested Platforms</a></li>
|
|
<li><a href="Troubleshooting.html" title="Troubleshooting">Troubleshooting</a></li>
|
|
<li><a href="KnownIssues.html">Known Issues</a></li>
|
|
<li><a href="SpecialPlatformSupport.html" title="Special Platform Support">Special Platform Support</a></li>
|
|
<li><a href="Examples.html" title="Examples">Examples</a></li>
|
|
<li><a href="Integration.html">Integrations</a></li>
|
|
<li><a href="Updating.html" title="Updating Rewired">Updating Rewired</a></li>
|
|
</ul>
|
|
<strong>FAQ</strong>
|
|
<ul>
|
|
<li><a href="FAQ.html">See all topics...</a></li>
|
|
</ul>
|
|
<strong>Unity Help:</strong>
|
|
<ul>
|
|
<li><a href="http://docs.unity3d.com/Manual/" target="_blank">Unity Manual</a></li>
|
|
<li><a href="http://docs.unity3d.com/ScriptReference/" target="_blank">Unity Script Reference</a></li>
|
|
<li><a href="http://unity3d.com/learn/tutorials/modules" target="_blank">Unity Tutorials</a></li>
|
|
</ul>
|
|
<strong>Links:</strong>
|
|
<ul>
|
|
<li><a href="http://guavaman.com/projects/rewired">Rewired Website</a></li>
|
|
<li><a href="http://guavaman.com/projects/rewired/docs">Web Documentation</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
<div class="main-body">
|
|
<div class="logo"><a href="http://guavaman.com/projects/rewired" title="Rewired"><img src="files/images/rewired-logo.png" width="173" height="139" alt="Rewired" /></a></div>
|
|
|
|
<h1>
|
|
<!-- InstanceBeginEditable name="PageHeader" -->Quick Start
|
|
<!-- InstanceEndEditable -->
|
|
</h1>
|
|
|
|
<!-- InstanceBeginEditable name="MainBody" -->
|
|
|
|
<p>This guide will show you how to create a Rewired Input Manager and set up basic input for a 1-player game.</p>
|
|
<hr />
|
|
<p>1. Install Rewired. Refer to <a href="Installation.html">Installation</a> for more information.</p>
|
|
<p>2. Create a Rewired Input Manager in the scene from the menu:<br />
|
|
Window -> Rewired -> Create -> Input Manager (in scene).</p>
|
|
<p><img src="files/images/quickstart_menu_createinputmanager.png" alt="Create Input Manager" /></p>
|
|
<hr />
|
|
<p>3. Select the Rewired Input Manager from the scene Hierarchy.</p>
|
|
<p><img src="files/images/quickstart_inputmanagerinhierarchy.png" alt="Input Manager in Hierarchy" /></p>
|
|
<hr />
|
|
<p>4. In the Inspector, click "Launch Rewired Editor." (See <a href="RewiredEditor.html">Rewired Editor</a> for detailed usage information.)</p>
|
|
<p><img src="files/images/quickstart_inputmanagerinspector.png" alt="Launch Rewired Editor" /></p>
|
|
<hr />
|
|
<p>5. In the navigation bar at the top of the Rewired Editor window, click "Players".</p>
|
|
<p><img src="files/images/quickstart_editor_players1.png" alt="Players" /></p>
|
|
<hr />
|
|
<p>6. You must have at least one Player to use input. Add a new Player by clicking the "New" button below the Players box.</p>
|
|
<p><img src="files/images/quickstart_editor_players2.png" alt="Add new Player" /></p>
|
|
<hr />
|
|
<p>7. We will come back to Players later to assign controller maps, but first you need to create some Actions. Click the "Actions" button in the navigation bar and create a new Action by clicking the "New" button below the Actions box.</p>
|
|
<p><img src="files/images/quickstart_editor_actions1.png" alt="Actions" /></p>
|
|
<hr />
|
|
<p>8. For each input you will need for your game, create one Action. Create a few actions such as pictured in the example below. The selected Action's properties can be edited in the fields to the right under "Properties." For movement actions, change the Type to "Axis". You can give each action a Name, a Descriptive Name, and if the Type is Axis, also give it a Positive Name and a Negative Name. Hover the mouse over each property label to see a description of that property.</p>
|
|
<p>Note: Actions can be categorized by first creating Action Categories (or later moved into categories), but to keep this example simple, we will just leave all actions in the Default category.</p>
|
|
<p><img src="files/images/quickstart_editor_actions2.png" alt="Actions" /></p>
|
|
<hr />
|
|
<p>9. Each Action can be assigned an Input Behavior which determines how keyboard keys, buttons, and mouse axes behave. By default, all actions are assigned the "Default" Input Behavior. If you wish to tweak any of the settings or create new Input Behaviors, click the "Input Behaviors" button in the navigation bar. Hover the mouse over each property label for a description. For this guide's purposes, we will just leave the default behavior as is.</p>
|
|
<p><img src="files/images/quickstart_editor_inputbehaviors1.png" alt="Input Behaviors" /></p>
|
|
<hr />
|
|
<p>10. Now let's create a Joystick map. Click "Joystick Maps" in the navigation bar.</p>
|
|
<p><img src="files/images/quickstart_editor_joystickmaps1.png" alt="Joystick Maps" /></p>
|
|
<hr />
|
|
<p>11. You can create maps for any of the fully-supported controllers individually, or to save time, just create a map for the Gamepad Template and all controllers that use that template will automatically have maps created for them. (Any Joystick preceeded by [T] is a template.) Select the "[T] Gamepad Template", then click "Create Map."</p>
|
|
<p><img src="files/images/quickstart_editor_joystickmaps2.png" alt="Create Joystick Map" /></p>
|
|
<hr />
|
|
<p>12. Now you will need to create elements and assign actions to them. Click "New" under the "Element" box to create an element. Element Properties will appear to the right for the selected element. Assign a joystick element by clicking the drop-down "Element." Select an action to assign to this element under "Action." Create an element for each Action you created in step 8 and assign one Action to each element.</p>
|
|
<p><img src="files/images/quickstart_editor_joystickmaps3.png" alt="Create Joystick Map elements" /></p>
|
|
<hr />
|
|
<p>13. Now we will do the same thing, only this time for the keyboard. Click "Keyboard Maps" in the nagivation bar, create a map by clicking "Create Map", then create some elements by clicking the "New" button below the "Element" box. Assign actions to each element as you did with the Joystick map above. For movement actions that use an axis, since a keyboard key acts like a button and not an axis, you will use the "Axis Contribution" setting to determine whether the key contributes a positive or negative value to the final axis. For example, if the "W" key should move the character up, the Action should be set to "Move Vertical" and the "Axis Contribution" should be "Positive". For the "S" key which should move the character down, the Action should also be "Move Vertical", but the "Axis Contribution" should be "Negative."</p>
|
|
<p><img src="files/images/quickstart_editor_keyboardmaps1.png" alt="Keyboard Maps" /></p>
|
|
<hr />
|
|
<p>14. If you want to create a Mouse Map, repeat the same steps as above for keyboard and joystick, but this time click "Mouse Maps" in the navigation bar.</p>
|
|
<p><img src="files/images/quickstart_editor_mousemaps1.png" alt="Mouse Maps" /></p>
|
|
<hr />
|
|
<p>15. Now that we have created joystick, mouse, and keyboard maps, we need to assign them to the Player. Click back to the "Players" page in the navigation bar and select the Player to which you want to assign the maps.</p>
|
|
<p><img src="files/images/quickstart_editor_players3.png" alt="Players" /></p>
|
|
<hr />
|
|
<p>16. Assign a joystick map to the player by clicking the "Add Joystick Map" button. If you have more than one joystick map to assign, you can add as many as you need. For this demo, just add the map you created above. To choose a different joystick map, change the Category and Layout drop-downs. Ensure "Start Enabled" is checked so this joystick map will be active by default. When gameplay begins, if any joysticks are assigned to this Player, it will load the proper map for that joystick.</p>
|
|
<p><img src="files/images/quickstart_editor_players4.png" alt="Add Joystick Map" /></p>
|
|
<hr />
|
|
<p>17. Do the same for any keyboard maps you have created. Note: For keyboard control, ensure the "Assign Keyboard on Start" checkbox is checked, otherwise the Player will not be assigned the keyboard unless you assign it manually through scripting.</p>
|
|
<p><img src="files/images/quickstart_editor_players5.png" alt="Add Keyboard Map" width="1015" height="763" /></p>
|
|
<hr />
|
|
<p>18. Do the same for mouse maps. Note: For mouse control, ensure the "Assign Mouse on Start" checkbox is checked, otherwise the Player will not be assigned the mouse unless you assign it manually through scripting.</p>
|
|
<p><img src="files/images/quickstart_editor_players6.png" alt="Add Mouse Map" /></p>
|
|
<hr />
|
|
<p>19. Close the Rewired Editor and save the scene.</p>
|
|
<p>20. Now you will need to create a script to process input for your character. Since the script could vary significantly based on the type of game you're making, this example will just show the basics of how to get input from Rewired. </p>
|
|
<p>21. Create a new script in your project, for example, MyCharacter.cs, and attach the script to your character game object.</p>
|
|
<p>NOTE: This example is not meant for use in your project. It serves no purpose other than to teach you how to get input from a Player. You will have to write your own scripts to move your characters/objects around the scene.</p>
|
|
<pre class="code">
|
|
<span class="comment">// MyCharacter.cs - A simple example showing how to get input from Rewired.Player</span>
|
|
|
|
using UnityEngine;
|
|
using System.Collections;
|
|
using Rewired;
|
|
|
|
[RequireComponent(typeof(CharacterController))]
|
|
public class MyCharacter : MonoBehaviour {
|
|
|
|
<span class="comment"> // The Rewired player id of this character</span>
|
|
public int playerId = 0;
|
|
|
|
<span class="comment">// The movement speed of this character</span>
|
|
public float moveSpeed = 3.0f;
|
|
|
|
<span class="comment">// The bullet speed</span>
|
|
public float bulletSpeed = 15.0f;
|
|
|
|
<span class="comment">// Assign a prefab to this in the inspector.
|
|
// The prefab must have a Rigidbody component on it in order to work.</span>
|
|
public GameObject bulletPrefab;
|
|
|
|
private Player player; <span class="comment">// The Rewired Player</span>
|
|
private CharacterController cc;
|
|
private Vector3 moveVector;
|
|
private bool fire;
|
|
|
|
void Awake() {
|
|
<span class="comment">// Get the Rewired Player object for this player and keep it for the duration of the character's lifetime</span>
|
|
player = ReInput.players.GetPlayer(playerId);
|
|
|
|
<span class="comment">// Get the character controller</span>
|
|
cc = GetComponent<CharacterController><CharacterController>();
|
|
}
|
|
|
|
void Update () {
|
|
GetInput();
|
|
ProcessInput();
|
|
}
|
|
|
|
private void GetInput() {
|
|
<span class="comment">// Get the input from the Rewired Player. All controllers that the Player owns will contribute, so it doesn't matter</span>
|
|
<span class="comment">// whether the input is coming from a joystick, the keyboard, mouse, or a custom controller.</span>
|
|
|
|
moveVector.x = player.GetAxis("Move Horizontal"); <span class="comment">// get input by name or action id</span>
|
|
moveVector.y = player.GetAxis("Move Vertical");
|
|
fire = player.GetButtonDown("Fire");
|
|
}
|
|
|
|
private void ProcessInput() {
|
|
<span class="comment">// Process movement</span>
|
|
if(moveVector.x != 0.0f || moveVector.y != 0.0f) {
|
|
cc.Move(moveVector * moveSpeed * Time.deltaTime);
|
|
}
|
|
|
|
<span class="comment">// Process fire</span>
|
|
if(fire) {
|
|
GameObject bullet = (GameObject)Instantiate(bulletPrefab, transform.position + transform.right, transform.rotation);
|
|
bullet.GetComponent<Rigidbody>().AddForce(transform.right * bulletSpeed, ForceMode.VelocityChange);
|
|
}
|
|
}
|
|
}</pre>
|
|
|
|
<p>22. That's it! You've leared how to set up basic input for a single player game using Rewired. There's a whole lot more powerful features available in Rewired, so be sure to read the rest of the <a href="Documentation.html">documentation</a> for more advanced topics.</p>
|
|
|
|
<div class="bottom-pager clearfix">
|
|
<a class="back-button" href="Installation.html" title="Installation"><span class="button-img"></span>Installation</a>
|
|
<a class="forward-button" href="BasicUsage.html" title="Basic Usage"><span class="button-img"></span>Basic Usage</a>
|
|
</div>
|
|
|
|
<!-- InstanceEndEditable -->
|
|
</div>
|
|
|
|
</div>
|
|
<div class="footer clearfix">
|
|
<p class="left">Copyright ©2014-2021 <a href="http://guavaman.com" title="Guavaman Enterprises">Guavaman Enterprises</a>. All rights reserved. No materials may be reproduced without permission.</p>
|
|
<p class="right"><a href="http://guavaman.com/projects/rewired" title="Return to Rewired Website">Return to Rewired Website</a></p>
|
|
</div>
|
|
<!-- end .content --></div>
|
|
<!-- end .container --></div>
|
|
|
|
|
|
</body>
|
|
<!-- InstanceEnd --></html>
|