Files
Fishing2/Assets/ThirdParty/Rewired/Documentation/Html/ControllerTemplates.html
2025-05-10 12:49:47 +08:00

387 lines
30 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 | Controller Templates</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" -->Controller Templates
<!-- InstanceEndEditable -->
</h1>
<!-- InstanceBeginEditable name="MainBody" -->
<p>A Controller Template represents a generalized controller layout that applies to all compatible controllers providing a common interface to work with these controllers. When you create a map for a Controller Template, any controller that implements the template will inherit that map automatically without the need for you to create a map specifically for that controller. For example, Rewired comes with a Gamepad Template. When you create a map for this Gamepad Template, you do not need to create individual maps specifically for any of the gamepads <a href="SupportedControllers.html">listed on this page</a> because they are all covered by the Gamepad Template. This makes is much quicker to create pre-defined controller maps for a huge variety of controllers. Additionally, as more controllers are added to the Template in the future, the map you've already created will work with these new controllers as well.</p>
<p>If you have created a map for a Controller Template but still want to make a map for a specific controller that is covered by the Controller Template, just create the map for the specific controller and it will override the map defined in the Template.</p>
<p>See this for more information about <a href="ControllerMaps.html#controller-templates">how Controller Templates relate to Controller Maps</a>.</p>
<p>Controller Templates can also be <a href="#scripting">accessed at runtime through scripting</a> for a variety of purposes. </p>
<p>For information about which controllers are compatible with which Controller Templates, please see <a href="SupportedControllers.html">Supported Controllers</a>. </p>
<p><strong><a name="supported-controller-elements" id="supported-controller-elements"></a>Supported Controller Elements:</strong></p>
<ul>
<li>All controller elements mappable on a Controller Template are not guaranteed to exist on every compatible controller.</li>
<li>All controller elements on a controller are not guaranteed to be supported on every platform and input source. Which elements are supported is up to the specific input API in use for the controller.</li>
<li> If a controller element does not exist on a controller or if that element is not supported on a specific platform and input source, no Action mapping will be created in the <a href="ControllerMaps.html#controller-templates">final runtime Controller Map</a> for that element.</li>
<li>All elements on a controller are not guaranteed to be mappable by a Controller Template. If a controller contains elements that are not supported by the template, you must create a Controller Map for that specific controller, overriding the template, if you want to map Actions to these unsupported elements.</li>
</ul>
<p>&nbsp;</p>
<p><strong><a name="gamepad-template" id="gamepad-template"></a><a name="dual-analog-gamepad-template" id="dual-analog-gamepad-template"></a>Gamepad Template:</strong></p>
<p>The Gamepad Template allows you to make a map which will cover <a href="SupportedControllers.html#gamepads">all of the gamepads listed here</a>.</p>
<p><strong>NOTE:</strong> Do not be confused and assume that the Gamepad Template will apply to and work with every gamepad in existence. The Template only applies to and works with <a href="SupportedControllers.html">recognized gamepads</a> that have controller definitions. There is no possible way to create a system that can automatically recognize and map all gamepads, steering wheels, flight controllers, or any other type of device because the required information to do this simply does not exist in the USB or HID data provided by the device. Only <a href="SupportedControllers.html">devices that have controller definitions</a> can work with the Template system.</p>
<p> The element names of the Gamepad Template are generalized because not all gamepads use the same names for all elements. Note that even though the Template element names are generalized, during gameplay, Rewired will use the controller's element's actual name instead of the generalized name. For example, an XBox 360 controller will report &quot;A&quot; instead of &quot;Action Bottom Row 1&quot; for the green button.</p>
<p>To avoid confusion when mapping the Gamepad Template, refer to the following element naming guide:</p>
<p><img src="files/images/gamepad-template-element-name-guide.png" alt="Rewired Gamepad Template Name Guide" /></p>
<p>Scripting Reference:</p>
<ul>
<li>Interface - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_IGamepadTemplate.htm">IGamepadTemplate</a></li>
<li>Class - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_GamepadTemplate.htm">GamepadTemplate</a></li>
</ul>
<p>&nbsp;</p>
<p><strong><a name="racing-wheel-template" id="racing-wheel-template"></a>Racing Wheel Template:</strong></p>
<p>The Racing Wheel Template allows you to make a map which will cover <a href="SupportedControllers.html#racing-controllers">all of the wheels listed here</a>. No diagram exists showing the elements visually because there is no generally accepted universal racing wheel layout as there is for gamepads. The element names should be straightforward enough to understand what they would map to on a device.</p>
<p>Scripting Reference:</p>
<ul>
<li>Interface - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_IRacingWheelTemplate.htm">IRacingWheelTemplate</a></li>
<li>Class - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_RacingWheelTemplate.htm">RacingWheelTemplate</a></li>
</ul>
<p>&nbsp;</p>
<p><strong><a name="hotas-template" id="hotas-template"></a>Hotas Template:</strong></p>
<p>The HOTAS Template allows you to make a map which will cover <a href="SupportedControllers.html#flight-controllers">all of the HOTAS devices and flight sticks listed here</a>. No diagram exists showing the elements visually because there is no generally accepted universal HOTAS layout as there is for gamepads. The element names should be straightforward enough to understand what they would map to on a device.</p>
<p>Scripting Reference:</p>
<ul>
<li>Interface - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_IHOTASTemplate.htm">IHOTASTemplate</a></li>
<li>Class - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_HOTASTemplate.htm">HOTASTemplate</a></li>
</ul>
<p>&nbsp;</p>
<p><strong><a name="flight-yoke-template" id="flight-yoke-template"></a>Flight Yoke Template:</strong></p>
<p>The Flight Yoke Template allows you to make a map which will cover <a href="SupportedControllers.html#flight-controllers">all of the flight yokes listed here</a>. No diagram exists showing the elements visually because there is no generally accepted universal flight yoke layout as there is for gamepads. The element names should be straightforward enough to understand what they would map to on a device.</p>
<p>Scripting Reference:</p>
<ul>
<li>Interface - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_IFlightYokeTemplate.htm">IFlightYokeTemplate</a></li>
<li>Class - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_FlightYokeTemplate.htm">FlightYokeTemplate</a></li>
</ul>
<p>&nbsp;</p>
<p><strong><a name="flight-pedals-template" id="flight-pedals-template"></a>Flight Pedals Template:</strong></p>
<p>The Flight Pedals Template allows you to make a map which will cover <a href="SupportedControllers.html#flight-controllers">all of the flight pedals listed here</a>. No diagram exists showing the elements visually because there is no generally accepted universal flight pedal layout as there is for gamepads. The element names should be straightforward enough to understand what they would map to on a device.</p>
<p>Scripting Reference:</p>
<ul>
<li>Interface - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_IFlightPedalsTemplate.htm">IFlightPedalsTemplate</a></li>
<li>Class - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_FlightPedalsTemplate.htm">FlightPedalsTemplate</a></li>
</ul>
<p>&nbsp;</p>
<p><strong><a name="6-dof-controller-template" id="6-dof-controller-template"></a>6 DoF Controller Template:</strong></p>
<p>The 6 DoF Controller Template allows you to make a map which will cover <a href="SupportedControllers.html#6-dof-controllers">all of the 6 DoF controllers listed here</a>.</p>
<p>The primary elements of the 6 DoF Controller Template are the 6 axes which can be used to retrieve 3D directional and rotational input:</p>
<ul>
<li>Horizontal<span class="note"> (Position X)</span></li>
<li>Vertical<span class="note"> (Position Y)</span></li>
<li>Forward/Back<span class="note"> (Position Z)</span></li>
<li>Rotate X</li>
<li>Rotate Y</li>
<li>Rotate Z</li>
</ul>
<p>No diagram exists showing the elements visually because there is no generally accepted universal 6 DoF controller layout as there is for gamepads. The element names should be straightforward enough to understand what they would map to on a device.</p>
<p>Scripting Reference:</p>
<ul>
<li>Interface - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_ISixDofControllerTemplate.htm">ISixDofControllerTemplate</a></li>
<li>Class - <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_SixDofControllerTemplate.htm">SixDofControllerTemplate</a></li>
</ul>
<p>&nbsp;</p>
<hr />
<h3><strong><a name="scripting" id="scripting"></a></strong>Scripting</h3>
<p>Generally, you define Controller Maps for the Controller Template in the Rewired Editor, and when a user connects a compatible controller, it just works. You don't need to write any extra code to make Controller Templates work, nor do you even need to be aware they exist outside of creating the Controller Maps in the Rewired Editor. However, for some special cases, it can be useful to have access to the Controller Template at runtime through scripting. You can skip this entire section if you do not anticipate needing to work directly with Controller Templates in code.</p>
<p>Controller Templates can be accessed at runtime through scripting for a variety of purposes such as <a href="HowTos.html#display-glyph-for-action-template-specific">to display generalized Controller Template UI glyphs for a controller</a> or to <a href="#getting-input-directly">get input from the Controller Template elements directly</a>.</p>
<p>&nbsp;</p>
<p><strong>Accessing Controller Templates:</strong></p>
<p>Each <a href="Controller.html">Controller</a> has a list of Controller Templates that it implements. The following shows various ways of accessing them:</p>
<pre class="code">
<span class="comment">// Get the first Controller assigned to the Player that implements Gamepad Template</span>
var controller = player.controllers.GetFirstControllerWithTemplate&lt;IGamepadTemplate&gt;();
<span class="comment">// Get the Gamepad Template from the Controller</span>
var gamepad = controller.GetTemplate&lt;IGamepadTemplate&gt;();
<span class="comment">// Get a list of all Controller Templates of a particular type in all Controllers found on the system</span>
var gamepads = ReInput.controllers.GetControllerTemplates&lt;IGamepadTemplate&gt;();
<span class="comment">// Iterate through all Controller Templates implemented by a Controller</span>
for(int i = 0; i &lt; controller.templateCount; i++) {
Debug.Log(controller.name + &quot; implements the &quot; + controller.Templates[i].name + &quot; Template.&quot;);
} </pre>
<p><strong><a name="determining-if-controller-implements-template" id="determining-if-controller-implements-template"></a>Determining if a Controller implements a particular Controller Template:</strong></p>
<p>Sometimes it can be useful to know whether a Controller implements a particular Controller Template. This can be done as follows:</p>
<pre class="code">
<span class="comment">// Check whether the Controller implements the Controller Template type</span>
if(controller.ImplementsTemplate&lt;IGamepadTemplate&gt;()) {
<span class="comment">// Controller implements IGamepadTemplate</span>
}
<span class="comment">// You can also just try to get the Template directly and check if the result is null</span>
var gamepad = controller.GetTemplate&lt;IGamepadTemplate&gt;();
if(gamepad != null) {
<span class="comment">// Controller implements IGamepadTemplate</span>
}</pre>
<p><strong><a name="getting-input-directly" id="getting-input-directly"></a>Getting input directly from Controller Templates:</strong></p>
<p>Normally, you would use the <a href="HowTos.html#get-input">Player-Action system to get input</a>, but you can also get input values directly from the elements in a Controller Template if you choose. Each Controller Template interface has a list of elements accessible through scripting. The following illustrates the process:</p>
<pre class="code">
<span class="comment">// Get the Gamepad Template from the Controller</span>
IGamepadTemplate gamepad = controller.GetTemplate&lt;IGamepadTemplate&gt;();
<span class="comment">// If the result is null, the Controller does not implement the Gamepad Template</span>
if (gamepad == null) continue;
<span class="comment">// Read values directly from the elements
// Note that most elements on the Gamepad Template have aliases
// available such as a, b, x, y, back, start for elements which correspond to
// Xbox controller naming standards for your convenience.
// The standard names of actionBottomRow1, leftShoulder2, etc., are also available.</span>
Vector2 moveVector = gamepad.leftStick.value;
Vector2 lookVector = gamepad.rightStick.value;
float fire = gamepad.rightTrigger.value;
<span class="comment">// Any Axis can also be queried as a Button using the AsButton convenience property</span>
bool fireJustPressed = gamepad.rightTrigger.AsButton.justPressed;
bool punch = gamepad.b.justPressed;
bool reload = gamepad.y.justPressed;
bool aim = gamepad.leftStick.press.value;
bool jump = gamepad.x.justPressed;
bool start = gamepad.start.justPressed;
bool up = gamepad.dPad.up.value;
bool down = gamepad.dPad.down.value;
Vector2 dPadVector = gamepad.dPad.value;</pre>
<p><strong><a name="interface-vs-concrete-class" id="interface-vs-concrete-class"></a>Interface vs concrete class:</strong></p>
<p>Controller Templates are exposed as both a concrete class and an interface. You should always use the interface when interacting with the API. The concrete class is only exposed for its static members (element identifier id constants, type guid, etc.)</p>
<pre class="code">
<span class="comment"></span><span class="comment">// Each Controller Template concrete class lists public
// constants for accessing the various elements should you need them</span>
int id = GamepadTemplate.elementId_leftStickX;
id = GamepadTemplate.elementId_leftStickY;
id = GamepadTemplate.elementId_rightShoulder;
<span class="comment">// The GUID is also available</span>
Guid guid = GamepadTemplate.typeGuid;</pre>
<p><strong><a name="action-map-to-controller-template-element" id="action-map-to-controller-template-element"></a>Getting a Controller Template Element from a Controller Action mapping:</strong></p>
<p>If you want to determine the Controller Template Element that corresponds to a Player-Action mapping in a Controller Map, it can be converted to a Controller Template Element Target by using the method <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/M_Rewired_IControllerTemplate_GetElementTargets.htm">IControllerTemplate.GetElementTargets</a>.</p>
<pre class="code">int count = template.GetElementTargets(actionElementMap, results);</pre>
<p><span class="comment"> This gets what Controller Template Elements the Action Element Map is pointing to.
Note that this may return two targets in some rare cases where the Action Element Map
binds to multiple elements on the Template such as the Racing Wheel template which has Shifer 1-10 and Reverse Gear, two of which may be bound to the same Controller element.
Two elements would also be returned if two Template Buttons are mapped to both poles of a single Controller Axis.</span></p>
<p>A more complete example can be found in the <a href="Examples.html#gamepad-template-ui">Gamepad Template UI example</a>.</p>
<p><strong>Controller Template Element Sources:</strong></p>
<p>Each Controller Template Element points back to a Controller Element where input values are actually drawn from. This information can be found in the <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/P_Rewired_IControllerTemplateElement_source.htm">IControllerTemplateElement.source</a> property. The source type can be determined using the <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/P_Rewired_IControllerTemplateElementSource_type.htm">IControllerTemplateElementSource.type</a> property and then cast to the appropriate <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_IControllerTemplateAxisSource.htm">IControllerTemplateAxisSource</a> or <a href="https://guavaman.com/projects/rewired/docs/api-reference/html/T_Rewired_IControllerTemplateButtonSource.htm">IControllerTemplateButtonSource</a>.</p>
<p><a name="saving-and-loading-controller-template-mappings" id="saving-and-loading-controller-template-mappings"></a><strong>Saving and loading Controller Template mappings:</strong></p>
<p>Normally, Controller mappings are saved on a per-controller-type basis. However, it is possible to save and load mappings for a Controller Template instead. You would do this if you wanted all Gamepads for example to share saved control mappings instead of each having its own saved data. This would allow you to, for example, map and save on an Xbox 360 Controller, then when plugging in a Sony Dual Shock 4, it would inherit those mappings created for the Xbox 360 Controller.</p>
<p>Controller Maps always exist per-device, but you can convert the Controller Map to a Controller Template Map before saving. After loading, you convert it back to a Controller Map and load it in the Player:</p>
<pre class="code">
<span class="comment">// Quick Example
// Convert Controller Map to a Controller Template Map and then export to XML</span>
string xml = controllerMap.ToControllerTemplateMap&lt;IGamepadTemplate&gt;().ToXmlString();
<span class="comment">// Convert exported Controller Template XML to a Controller Map again</span>
ControllerMap controllerMap = ControllerTemplateMap.FromXml(xml).ToControllerMap(joystick);
<span class="comment">// Load it in the Player</span>
player.controllers.maps.AddMap(joystick, controllerMap);</pre>
<pre class="code">
<span class="comment">// More detailed example below showing using the first implemented Controller Template
// instead of the using Gamepad Template specifically.</span>
<span class="comment">// Saving</span>
if(controller.templateCount &gt; 0) {
<span class="comment">// Get the first Controller Template implemented by this Controller</span>
IControllerTemplate template = controller.Templates[0];
<span class="comment"> // Convert the Controller Map to a Controller Template Map</span>
ControllerTemplateMap templateMap = controllerMap.ToControllerTemplateMap(template.typeGuid);
<span class="comment">// Export the Controller Template Map to XML</span>
string xml = templateMap.ToXmlString();
<span class="comment">// Save the XML</span>
}
<span class="comment">// ...</span>
<span class="comment">// Loading</span>
foreach(Joystick joystick in player.controllers.Joysticks) {
if (joystick.templateCount == 0) continue; <span class="comment">// this Joystick does not implement any Controller Templates</span>
<span class="comment">
// Get the first Controller Template implemented by this Controller</span>
IControllerTemplate template = controller.Templates[0];
<span class="comment">// Call some method to get the Xml for the template</span>
string xml = GetXml(player, joystick.Templates[0]);
<span class="comment">// Create the Controller Template Map from XML</span>
ControllerTemplateMap templateMap = ControllerTemplateMap.FromXml(xml);
if (templateMap == null) continue; <span class="comment">// failed to load from xml, skip</span>
<span class="comment">// Convert to a Controller Map and add it to the Player</span>
player.controllers.maps.AddMap(joystick, templateMap.ToControllerMap(joystick));
}</pre>
<p></p>
<p><a name="viewing-default-controller-template" id="viewing-default-controller-template"></a><strong>Viewing a default Controller Template Map when no Joystick is attached:</strong></p>
<p>If you need to see what a Controller Template's elements are mapped to without a Joystick attached that implements that Template, you can get an instance of a default Controller Template Map as defined in the Rewired Input Manager as follows:</p>
<pre class="code">ReInput.mapping.GetControllerTemplateMapInstance(GamepadTemplate.typeGuid, categoryId, layoutId);</pre>
<p>This will return a Controller Template Map which will show the default bindings in a particular Map Category and Layout. Note that this will not load any data from saved user XML/JSON, so if your users have remapped their controls and you've saved that information, this will not be reflected in the returned map. You would have to load the saved map from data storage in order to see the user-modified bindings.</p>
<p><strong>Limitations:</strong></p>
<ul>
<li>It is not possible to allow the user to map and apply a Controller Template to an Unknown Controller (or any other incompatible Controller) during runtime at this time.</li>
</ul>
<div class="bottom-pager clearfix">
<a class="back-button" href="ControllerMaps.html" title="Map Categories"><span class="button-img"></span>Controller Maps</a>
<a class="forward-button" href="CustomControllers.html" title="Custom Controllers"><span class="button-img"></span></a><a class="forward-button" href="MapCategories.html" title="Map Categories">Map Categories</a> </div>
<!-- InstanceEndEditable -->
</div>
</div>
<div class="footer clearfix">
<p class="left">Copyright &copy;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>