public override void OnInspectorGUI() { // 'assetEditor' is set only after the editor is enabled so do the // initialization here. if (!m_Initialized) { // Read current asset as backup. if (m_Backup == null) { m_Backup = GetAsset().ToJson(); } m_Initialized = true; } if (GUILayout.Button("Edit asset")) { ActionInspectorWindow.OnOpenAsset(GetAsset().GetInstanceID(), 0); } EditorGUILayout.Space(); // Look up properties on importer object. var generateWapperCodeProperty = serializedObject.FindProperty("m_GenerateWrapperCode"); // Add settings UI. EditorGUILayout.PropertyField(generateWapperCodeProperty, Contents.generateWrapperCode); if (generateWapperCodeProperty.boolValue) { var wrapperCodePathProperty = serializedObject.FindProperty("m_WrapperCodePath"); var wrapperClassNameProperty = serializedObject.FindProperty("m_WrapperClassName"); var wrapperCodeNamespaceProperty = serializedObject.FindProperty("m_WrapperCodeNamespace"); ////TODO: tie a file selector to this EditorGUILayout.PropertyField(wrapperCodePathProperty); EditorGUILayout.PropertyField(wrapperClassNameProperty); if (!CSharpCodeHelpers.IsEmptyOrProperIdentifier(wrapperClassNameProperty.stringValue)) { EditorGUILayout.HelpBox("Must be a valid C# identifier", MessageType.Error); } EditorGUILayout.PropertyField(wrapperCodeNamespaceProperty); if (!CSharpCodeHelpers.IsEmptyOrProperNamespaceName(wrapperCodeNamespaceProperty.stringValue)) { EditorGUILayout.HelpBox("Must be a valid C# namespace name", MessageType.Error); } } ApplyRevertGUI(); }
public override void OnInspectorGUI() { // Button to pop up window to edit the asset. if (GUILayout.Button("Edit asset")) { ActionInspectorWindow.OnOpenAsset(GetAsset().GetInstanceID(), 0); } EditorGUILayout.Space(); // Importer settings UI. var generateWapperCodeProperty = serializedObject.FindProperty("m_GenerateWrapperCode"); EditorGUILayout.PropertyField(generateWapperCodeProperty, m_GenerateWrapperCodeLabel); if (generateWapperCodeProperty.boolValue) { var wrapperCodePathProperty = serializedObject.FindProperty("m_WrapperCodePath"); var wrapperClassNameProperty = serializedObject.FindProperty("m_WrapperClassName"); var wrapperCodeNamespaceProperty = serializedObject.FindProperty("m_WrapperCodeNamespace"); var generateActionEventsProperty = serializedObject.FindProperty("m_GenerateActionEvents"); ////TODO: tie a file selector to this EditorGUILayout.PropertyField(wrapperCodePathProperty); EditorGUILayout.PropertyField(wrapperClassNameProperty); if (!CSharpCodeHelpers.IsEmptyOrProperIdentifier(wrapperClassNameProperty.stringValue)) { EditorGUILayout.HelpBox("Must be a valid C# identifier", MessageType.Error); } EditorGUILayout.PropertyField(wrapperCodeNamespaceProperty); if (!CSharpCodeHelpers.IsEmptyOrProperNamespaceName(wrapperCodeNamespaceProperty.stringValue)) { EditorGUILayout.HelpBox("Must be a valid C# namespace name", MessageType.Error); } EditorGUILayout.PropertyField(generateActionEventsProperty); } ApplyRevertGUI(); }
public CopyPasteUtility(ActionInspectorWindow window) { m_Window = window; m_TreeView = window.m_TreeView; }
public CopyPasteUtility(ActionInspectorWindow window, InputActionListTreeView tree, SerializedObject serializedObject) { m_Window = window; m_TreeView = tree; m_SerializedObject = serializedObject; }
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) { ////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; } // Create asset. var asset = ScriptableObject.CreateInstance <InputActionAsset>(); // Parse JSON. try { ////TODO: make sure action names are unique asset.LoadFromJson(text); } catch (Exception exception) { ctx.LogImportError(string.Format("Could not parse input actions in JSON format from '{0}' ({1})", ctx.assetPath, exception)); DestroyImmediate(asset); return; } ctx.AddObjectToAsset("<root>", asset); ctx.SetMainObject(asset); // Make sure every map and every action has a stable ID assigned to it. var maps = asset.actionMaps; foreach (var map in maps) { if (map.idDontGenerate == Guid.Empty) { // Generate and remember GUID. var id = map.id; ArrayHelpers.Append(ref m_ActionMapGuids, new RememberedGuid { guid = id.ToString(), name = map.name, }); } else { // Retrieve remembered GUIDs. if (m_ActionMapGuids != null) { for (var i = 0; i < m_ActionMapGuids.Length; ++i) { if (string.Compare(m_ActionMapGuids[i].name, map.name, StringComparison.InvariantCultureIgnoreCase) == 0) { map.m_Guid = Guid.Empty; map.m_Id = m_ActionMapGuids[i].guid; break; } } } } foreach (var action in map.actions) { var actionName = string.Format("{0}/{1}", map.name, action.name); if (action.idDontGenerate == Guid.Empty) { // Generate and remember GUID. var id = action.id; ArrayHelpers.Append(ref m_ActionGuids, new RememberedGuid { guid = id.ToString(), name = actionName, }); } else { // Retrieve remembered GUIDs. if (m_ActionGuids != null) { for (var i = 0; i < m_ActionGuids.Length; ++i) { if (string.Compare(m_ActionGuids[i].name, actionName, StringComparison.InvariantCultureIgnoreCase) == 0) { action.m_Guid = Guid.Empty; action.m_Id = m_ActionGuids[i].guid; break; } } } } } } // Create subasset for each action. foreach (var map in maps) { var haveSetName = !string.IsNullOrEmpty(map.name); foreach (var action in map.actions) { var actionReference = ScriptableObject.CreateInstance <InputActionReference>(); actionReference.Set(action); var objectName = action.name; if (haveSetName) { objectName = string.Format("{0}/{1}", map.name, action.name); } actionReference.name = objectName; ctx.AddObjectToAsset(objectName, actionReference); } } // 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, generateEvents = m_GenerateActionEvents, }; if (InputActionCodeGenerator.GenerateWrapperCode(wrapperFilePath, maps, asset.controlSchemes, options)) { // Inform database that we modified a source asset *during* import. AssetDatabase.ImportAsset(wrapperFilePath); } } // Refresh editors. ActionInspectorWindow.RefreshAllAfterImport(); }