Repository navigation
Expand file tree
/
Copy pathConfigureInputfromCode.cs
More file actions
79 lines (70 loc) · 2.33 KB
/
Copy pathConfigureInputfromCode.cs
File metadata and controls
79 lines (70 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
namespace DocCodeSamples.Tests
{
#region declaration
using UnityEngine;
using UnityEngine.InputSystem;
/// <summary>
/// Example script exposing serialized action references.
/// </summary>
public class ExampleScript : MonoBehaviour
{
/// <summary>
/// Reference to the "move" action.
/// </summary>
public InputAction move;
/// <summary>
/// Reference to the "jump" action.
/// </summary>
public InputAction jump;
}
#endregion
class ConfigureInputfromCode : MonoBehaviour
{
const string json = @"
{
""maps"" : [
{
""name"" : ""gameplay"",
""actions"" : [
{ ""name"" : ""fire"", ""type"" : ""button"" }
]
}
]
}";
void ConfigureFromJsonExample()
{
#region configurefromjson
// Load a set of action maps from JSON.
var maps = InputActionMap.FromJson(json);
// Load an entire InputActionAsset from JSON.
var asset = InputActionAsset.FromJson(json);
#endregion
}
void Start()
{
#region configurefromcode
{
// Create free-standing actions.
var lookAction = new InputAction("look", binding: "<Gamepad>/leftStick");
var moveAction = new InputAction("move", binding: "<Gamepad>/rightStick");
moveAction.AddCompositeBinding("1DAxis")
.With("Left", "<Keyboard>/a")
.With("Right", "<Keyboard>/d");
}
{
// Create an action map with actions.
var map = new InputActionMap("Gameplay");
var lookAction = map.AddAction("look");
lookAction.AddBinding("<Gamepad>/leftStick");
}
{
// Create an action asset.
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
var gameplayMap = new InputActionMap("gameplay");
asset.AddActionMap(gameplayMap);
var lookAction = gameplayMap.AddAction("look", binding: "<Gamepad>/leftStick");
}
#endregion
}
}
}