void LoadJson() { /* * string destination = m_Path + "/inputs.inputactions"; * string jsonString = null; * if(File.Exists(destination)){ * InputManager.controls.asset.LoadFromJson(File.ReadAllText(destination)); * InputActionMap.FromJson(File.ReadAllText(destination)); * } * else * { * Debug.LogWarning("File not found (inputs.inputactions)"); * return null; * } */ string destination = m_Path + "/inputsMaps.inputactions"; if (File.Exists(destination)) { InputActionMap.FromJson(File.ReadAllText(destination)); /* * for (int i = 0; i < InputManager.controls.controlSchemes.Count; i++) * { * Debug.Log("InputManager.controls.controlSchemes: "+InputManager.controls.controlSchemes.ToString()); * for (int j = 0; j < InputManager.controls.Player.Get().bindings.Count; j++) * { * Debug.Log("bindings ("+j+") : "+InputManager.controls.Player.Get().bindings[j]); * } * } */ } else { Debug.LogWarning("File not found (inputsMaps.inputactions)"); } //InputActionAsset.FromJson(jsonString); /* * string destination = m_Path + "/input.dat"; * FileStream file; * * if(File.Exists(destination)) file = File.OpenRead(destination); * else * { * Debug.LogWarning("File not found (input.dat)"); * return null; * } * * BinaryFormatter bf = new BinaryFormatter(); * string data = (string) bf.Deserialize(file); * file.Close(); */ }
public override void OnImportAsset(AssetImportContext ctx) { ////REVIEW: need to check with version control here? // Read file. string text; try { text = File.ReadAllText(ctx.assetPath); } catch (Exception exception) { ctx.LogImportError(string.Format("Could read file '{0}' ({1})", ctx.assetPath, exception)); return; } // Parse JSON. InputActionMap[] maps; try { maps = InputActionMap.FromJson(text); } catch (Exception exception) { ctx.LogImportError(string.Format("Could not parse input actions in JSON format from '{0}' ({1})", ctx.assetPath, exception)); return; } ////TODO: make sure action names are unique // Create asset. var asset = ScriptableObject.CreateInstance <InputActionAsset>(); asset.m_ActionMaps = maps; ctx.AddObjectToAsset("<root>", asset); ctx.SetMainObject(asset); // Create subasset for each action. for (var i = 0; i < maps.Length; ++i) { var set = maps[i]; var haveSetName = !string.IsNullOrEmpty(set.name); foreach (var action in set.actions) { var actionObject = ScriptableObject.CreateInstance <InputActionReference>(); actionObject.m_Asset = asset; actionObject.m_MapName = set.name; actionObject.m_ActionName = action.name; var objectName = action.name; if (haveSetName) { objectName = string.Format("{0}/{1}", set.name, action.name); } actionObject.name = objectName; ctx.AddObjectToAsset(objectName, actionObject); } } // Generate wrapper code, if enabled. if (m_GenerateWrapperCode) { var wrapperFilePath = m_WrapperCodePath; if (string.IsNullOrEmpty(wrapperFilePath)) { var assetPath = ctx.assetPath; var directory = Path.GetDirectoryName(assetPath); var fileName = Path.GetFileNameWithoutExtension(assetPath); wrapperFilePath = Path.Combine(directory, fileName) + ".cs"; } var options = new InputActionCodeGenerator.Options { sourceAssetPath = ctx.assetPath, namespaceName = m_WrapperCodeNamespace, className = m_WrapperClassName }; if (InputActionCodeGenerator.GenerateWrapperCode(wrapperFilePath, maps, options)) { // Inform database that we modified a source asset *during* import. AssetDatabase.ImportAsset(wrapperFilePath); } } // Refresh editors. ActionInspectorWindow.RefreshAll(); }
public override void OnImportAsset(AssetImportContext ctx) { // Parse JSON. var text = File.ReadAllText(ctx.assetPath); var sets = InputActionMap.FromJson(text); ////TODO: catch errors ////TODO: make sure action names are unique // Create asset. var asset = ScriptableObject.CreateInstance <InputActionAsset>(); asset.m_ActionMaps = sets; ctx.AddObjectToAsset("<root>", asset); ctx.SetMainObject(asset); // Create subasset for each action. for (var i = 0; i < sets.Length; ++i) { var set = sets[i]; var haveSetName = !string.IsNullOrEmpty(set.name); foreach (var action in set.actions) { var actionObject = ScriptableObject.CreateInstance <InputActionReference>(); actionObject.m_Asset = asset; actionObject.m_MapName = set.name; actionObject.m_ActionName = action.name; var objectName = action.name; if (haveSetName) { objectName = string.Format("{0}/{1}", set.name, action.name); } actionObject.name = objectName; ctx.AddObjectToAsset(objectName, actionObject); } } // Generate wrapper code, if enabled. if (m_GenerateWrapperCode) { var wrapperFilePath = m_WrapperCodePath; if (string.IsNullOrEmpty(wrapperFilePath)) { var assetPath = ctx.assetPath; var directory = Path.GetDirectoryName(assetPath); var fileName = Path.GetFileNameWithoutExtension(assetPath); wrapperFilePath = Path.Combine(directory, fileName) + ".cs"; } var options = new InputActionCodeGenerator.Options { sourceAssetPath = ctx.assetPath, namespaceName = m_WrapperCodeNamespace, className = m_WrapperClassName }; if (InputActionCodeGenerator.GenerateWrapperCode(wrapperFilePath, sets, options)) { // Inform database that we modified a source asset *during* import. AssetDatabase.ImportAsset(wrapperFilePath); } } }