public void SaveToJSON() { InputActionAsset actionAssetToUse; if (_inputActionAsset == null) { actionAssetToUse = _inputActionAsset; } else { // Create an Action Asset. InputActionAsset _newActionAsset = ScriptableObject.CreateInstance <InputActionAsset>(); var gameplayMap = new InputActionMap("gameplay"); _newActionAsset.AddActionMap(gameplayMap); var lookAction = gameplayMap.AddAction("look", InputActionType.Button); actionAssetToUse = _newActionAsset; } var actionMaps = InputActionMap.ToJson(actionAssetToUse.actionMaps); if (usePersistentDataPath || string.IsNullOrEmpty(_filePath)) { System.IO.File.WriteAllText(Application.persistentDataPath + "/" + _fileName + ".json", actionMaps); } else if (Directory.Exists(_filePath)) { System.IO.File.WriteAllText(_filePath + "/" + _fileName + ".json", actionMaps); } else { Debug.Log("Invalid File path: " + _filePath); } }
public void Editor_CanPrettyPrintJSON() { var map = new InputActionMap("map"); var action = map.AddAction("action", binding: "<Gamepad>/leftStick"); var json = InputActionMap.ToJson(new[] { map }); var prettyJson = StringHelpers.PrettyPrintJSON(json); var expected = string.Format( @"{{ ""maps"" : [ {{ ""name"" : ""map"", ""id"" : ""{0}"", ""actions"" : [ {{ ""name"" : ""action"", ""id"" : ""{1}"", ""expectedControlLayout"" : """", ""bindings"" : [ ] ", map.id, action.id); Assert.That(prettyJson, Does.StartWith(expected)); // Doing it again should not result in a difference. prettyJson = StringHelpers.PrettyPrintJSON(prettyJson); Assert.That(prettyJson, Does.StartWith(expected)); }