Skip to content

Instantly share code, notes, and snippets.

@TJHeuvel
Created August 1, 2019 07:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TJHeuvel/f74acbbbcfe8e84e59fa41ebff774f35 to your computer and use it in GitHub Desktop.
Save TJHeuvel/f74acbbbcfe8e84e59fa41ebff774f35 to your computer and use it in GitHub Desktop.
using System.Reflection;
using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
[CustomEditor(typeof(TextureImporter))]
[CanEditMultipleObjects]
//https://github.com/Unity-Technologies/UnityCsReference/blob/9034442437e6b5efe28c51d02e978a96a3ce5439/Editor/Mono/ImportSettings/TextureImporterInspector.cs
internal class TextureImporterEditor : AssetImporterEditor
{
#region Original texture importer editor support
private readonly Assembly editorAssembly = Assembly.GetAssembly(typeof(AssetImporterEditor));
private AssetImporterEditor originalEditor;
public override void OnEnable()
{
Editor origAsEditor = originalEditor as Editor;
CreateCachedEditor(targets, editorAssembly.GetType("UnityEditor.TextureImporterInspector"), ref origAsEditor);
originalEditor = origAsEditor as AssetImporterEditor;
originalEditor.OnEnable();
}
public override void OnDisable()
{
originalEditor.OnDisable();
}
public override bool showImportedObject => false;
public override bool HasModified()
{
return originalEditor.HasModified();
}
protected override void ResetValues()
{
callProtectedMethod(originalEditor, nameof(ResetValues));
}
protected override void Apply()
{
callProtectedMethod(originalEditor, nameof(Apply));
}
private void callProtectedMethod(object target, string methodName)
{
//target.GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance).Invoke(target, null);
}
#endregion
bool showAdvancedImporter;
public override void OnInspectorGUI()
{
originalEditor.OnInspectorGUI();
//do your custom UI
}
}
@JulienHeijmans
Copy link

Hi ! Did you manage to make that work for ModelImporter ?

@TJHeuvel
Copy link
Author

Hi Julien, i never tried. But perhaps if you make the CustomEditor attribute use the ModelImporter type (https://docs.unity3d.com/ScriptReference/ModelImporter.html) it would work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment