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")) { AssetInspectorWindow.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"); var generateInterfacesProperty = serializedObject.FindProperty("m_GenerateInterfaces"); ////TODO: tie a file selector to this EditorGUILayout.PropertyField(wrapperCodePathProperty, m_WrapperCodePathLabel); EditorGUILayout.PropertyField(wrapperClassNameProperty, m_WrapperClassNameLabel); if (!CSharpCodeHelpers.IsEmptyOrProperIdentifier(wrapperClassNameProperty.stringValue)) { EditorGUILayout.HelpBox("Must be a valid C# identifier", MessageType.Error); } EditorGUILayout.PropertyField(wrapperCodeNamespaceProperty, m_WrapperCodeNamespaceLabel); if (!CSharpCodeHelpers.IsEmptyOrProperNamespaceName(wrapperCodeNamespaceProperty.stringValue)) { EditorGUILayout.HelpBox("Must be a valid C# namespace name", MessageType.Error); } EditorGUILayout.PropertyField(generateActionEventsProperty, m_GenerateActionEventsLabel); EditorGUILayout.PropertyField(generateInterfacesProperty); } ApplyRevertGUI(); }
public override void OnInspectorGUI() { 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() { // ScriptedImporterEditor in 2019.2 now requires explicitly updating the SerializedObject // like in other types of editors. serializedObject.Update(); // Button to pop up window to edit the asset. if (GUILayout.Button("Edit asset")) { InputActionEditorWindow.OnOpenAsset(GetAsset().GetInstanceID(), 0); } EditorGUILayout.Space(); // Importer settings UI. var generateWrapperCodeProperty = serializedObject.FindProperty("m_GenerateWrapperCode"); EditorGUILayout.PropertyField(generateWrapperCodeProperty, m_GenerateWrapperCodeLabel); if (generateWrapperCodeProperty.boolValue) { var wrapperCodePathProperty = serializedObject.FindProperty("m_WrapperCodePath"); var wrapperClassNameProperty = serializedObject.FindProperty("m_WrapperClassName"); var wrapperCodeNamespaceProperty = serializedObject.FindProperty("m_WrapperCodeNamespace"); EditorGUILayout.BeginHorizontal(); var assetPath = AssetDatabase.GetAssetPath(GetAsset()); var defaultFileName = Path.ChangeExtension(assetPath, ".cs"); wrapperCodePathProperty.PropertyFieldWithDefaultText(m_WrapperCodePathLabel, defaultFileName); if (GUILayout.Button("…", EditorStyles.miniButton, GUILayout.MaxWidth(20))) { var fileName = EditorUtility.SaveFilePanel("Location for generated C# file", Path.GetDirectoryName(defaultFileName), Path.GetFileName(defaultFileName), "cs"); if (!string.IsNullOrEmpty(fileName)) { if (fileName.StartsWith(Application.dataPath)) { fileName = "Assets/" + fileName.Substring(Application.dataPath.Length + 1); } wrapperCodePathProperty.stringValue = fileName; } } EditorGUILayout.EndHorizontal(); wrapperClassNameProperty.PropertyFieldWithDefaultText(m_WrapperClassNameLabel, CSharpCodeHelpers.MakeTypeName(GetAsset().name)); if (!CSharpCodeHelpers.IsEmptyOrProperIdentifier(wrapperClassNameProperty.stringValue)) { EditorGUILayout.HelpBox("Must be a valid C# identifier", MessageType.Error); } wrapperCodeNamespaceProperty.PropertyFieldWithDefaultText(m_WrapperCodeNamespaceLabel, "<Global namespace>"); if (!CSharpCodeHelpers.IsEmptyOrProperNamespaceName(wrapperCodeNamespaceProperty.stringValue)) { EditorGUILayout.HelpBox("Must be a valid C# namespace name", MessageType.Error); } } // Using ApplyRevertGUI requires calling Update and ApplyModifiedProperties around the serializedObject, // and will print warning messages otherwise (see warning message in ApplyRevertGUI implementation). serializedObject.ApplyModifiedProperties(); ApplyRevertGUI(); }
public override void OnInspectorGUI() { // Button to pop up window to edit the asset. if (GUILayout.Button("Edit asset")) { AssetInspectorWindow.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"); var generateInterfacesProperty = serializedObject.FindProperty("m_GenerateInterfaces"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(wrapperCodePathProperty, m_WrapperCodePathLabel); if (GUILayout.Button("...", EditorStyles.miniButton, GUILayout.MaxWidth(20))) { var assetPath = AssetDatabase.GetAssetPath(GetAsset()); var defaultFileName = Path.ChangeExtension(assetPath, ".cs"); var fileName = EditorUtility.SaveFilePanel("Location for generated C# file", Path.GetDirectoryName(defaultFileName), Path.GetFileName(defaultFileName), "cs"); if (!string.IsNullOrEmpty(fileName)) { if (fileName.StartsWith(Application.dataPath)) { fileName = "Assets/" + fileName.Substring(Application.dataPath.Length + 1); } wrapperCodePathProperty.stringValue = fileName; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(wrapperClassNameProperty, m_WrapperClassNameLabel); if (!CSharpCodeHelpers.IsEmptyOrProperIdentifier(wrapperClassNameProperty.stringValue)) { EditorGUILayout.HelpBox("Must be a valid C# identifier", MessageType.Error); } EditorGUILayout.PropertyField(wrapperCodeNamespaceProperty, m_WrapperCodeNamespaceLabel); if (!CSharpCodeHelpers.IsEmptyOrProperNamespaceName(wrapperCodeNamespaceProperty.stringValue)) { EditorGUILayout.HelpBox("Must be a valid C# namespace name", MessageType.Error); } EditorGUILayout.PropertyField(generateActionEventsProperty, m_GenerateActionEventsLabel); EditorGUILayout.PropertyField(generateInterfacesProperty); } ApplyRevertGUI(); }