I have written an editor script that generates a custom .asset file. The asset file is created using a ScriptableObject
and then sub-assets are added using AssetDatabase.AddObjectToAsset
.
I would like to add an inspector GUI that is shown when the asset file is selected. For some reason the inspector GUI is not showing up when the asset file is selected. Instead I have to expand the asset file in project panel and then select the the same asset name again.
[CustomEditor(typeof(TestAsset))]
public class TestAssetEditor : UnityEditor.Editor {
public override void OnInspectorGUI() {
if (GUILayout.Button("Test"))
Debug.Log("TEST");
}
[MenuItem("Test/Test")]
public static void Test() {
Object asset = ScriptableObject.CreateInstance<TestAsset>();
asset.name = "Test Name";
AssetDatabase.CreateAsset(asset, "Assets/Test.asset");
Mesh test = new Mesh();
test.name = "test_mesh";
test.vertices = new Vector3[] {
new Vector3(0, 0, 0),
new Vector3(0, 1, 0),
new Vector3(1, 1, 0)
};
test.uv = new Vector2[] {
new Vector2(0, 0),
new Vector2(0, 1),
new Vector2(1, 1)
};
test.triangles = new int[] { 0, 1, 2 };
test.RecalculateNormals();
AssetDatabase.AddObjectToAsset(test, asset);
AssetDatabase.ImportAsset("Assets/Test.asset");
}
}
[System.Serializable]
public class TestAsset : ScriptableObject {
public int test = 0;
}