@@ -30,6 +30,9 @@ public class AssetImporterOptionsEditor : Editor
30
30
protected TextureImporter defaultTextureImport ;
31
31
protected ModelImporter defaultMeshImporter ;
32
32
33
+ protected GenericMenu importerMenu = new GenericMenu ( ) ;
34
+
35
+
33
36
private void OnEnable ( )
34
37
{
35
38
_opts = target as AssetImporterOptions ;
@@ -48,11 +51,9 @@ private void OnEnable()
48
51
49
52
defaultMeshImporter = AssetImporter . GetAtPath ( meshasset ) as ModelImporter ;
50
53
defaultTextureImport = AssetImporter . GetAtPath ( textureasset ) as TextureImporter ;
51
- }
52
-
53
- private void OnDisable ( )
54
- {
55
54
55
+ importerMenu . AddItem ( new GUIContent ( "Texture" ) , false , AddNewTypeofPreset , defaultTextureImport ) ;
56
+ importerMenu . AddItem ( new GUIContent ( "Mesh" ) , false , AddNewTypeofPreset , defaultMeshImporter ) ;
56
57
}
57
58
58
59
protected void AddNewPreset ( Preset p )
@@ -80,48 +81,58 @@ public void AddNewTypeofPreset(object obj)
80
81
{
81
82
Object unityObj = obj as Object ;
82
83
Preset newPreset = new Preset ( unityObj ) ;
83
-
84
-
85
- //if (unityObj == defaultTextureImport)
86
- //{
87
- // int count = 0;
88
- // while (count < newPreset.PropertyModifications.Length)
89
- // {
90
- // defaultTextureImport.
91
- // if (newPreset.PropertyModifications[count].propertyPath.Contains("sourceTextureInformation"))
92
- // {
93
- // ArrayUtility.RemoveAt(ref newPreset.PropertyModifications, count);
94
- // }
95
- // }
96
- //}
97
-
84
+
98
85
AddNewPreset ( newPreset ) ;
99
86
EditorUtility . SetDirty ( _opts ) ;
100
87
}
101
88
102
- public override void OnInspectorGUI ( )
89
+ public void RemovePreset ( int index )
103
90
{
104
- //TODO : move the generic menu out of that to build it only once
105
- if ( EditorGUILayout . DropdownButton ( new GUIContent ( "New Preset" ) , FocusType . Passive ) )
106
- {
107
- GenericMenu menu = new GenericMenu ( ) ;
91
+ var opt = _opts . importOptions [ index ] ;
92
+
93
+ ArrayUtility . RemoveAt ( ref _opts . importOptions , index ) ;
94
+ ArrayUtility . RemoveAt ( ref m_InspectorsFade , index ) ;
108
95
109
- menu . AddItem ( new GUIContent ( "Texture" ) , false , AddNewTypeofPreset , defaultTextureImport ) ;
110
- menu . AddItem ( new GUIContent ( "Mesh" ) , false , AddNewTypeofPreset , defaultMeshImporter ) ;
96
+ string assetpath = AssetDatabase . GetAssetPath ( opt . preset ) ;
97
+ DestroyImmediate ( opt . preset , true ) ;
98
+ AssetDatabase . ImportAsset ( assetpath ) ;
99
+ AssetDatabase . Refresh ( ) ;
100
+ }
111
101
112
- menu . DropDown ( GUILayoutUtility . GetLastRect ( ) ) ;
102
+ public override void OnInspectorGUI ( )
103
+ {
104
+ if ( EditorGUILayout . DropdownButton ( new GUIContent ( "New Preset" ) , FocusType . Passive , GUILayout . Width ( 100 ) ) )
105
+ {
106
+ importerMenu . ShowAsContext ( ) ;
113
107
}
114
108
115
109
if ( _opts . importOptions != null )
116
110
{
117
111
Editor ed = null ;
112
+ bool deletionHappened = false ;
118
113
for ( int i = 0 ; i < _opts . importOptions . Length ; ++ i )
119
114
{
115
+ deletionHappened = false ;
116
+
117
+ EditorGUILayout . BeginHorizontal ( ) ;
120
118
m_InspectorsFade [ i ] = EditorGUILayout . Foldout ( m_InspectorsFade [ i ] , "Preset : " + _opts . importOptions [ i ] . preset . GetTargetTypeName ( ) + " on " + _opts . importOptions [ i ] . nameFilter ) ;
121
119
120
+ if ( GUILayout . Button ( "Delete" , GUILayout . Width ( 100 ) ) )
121
+ {
122
+ if ( EditorUtility . DisplayDialog ( "Confirm" , "Are you sure you want to delete that preset rule?" ,
123
+ "Delete" , "Cancel" ) )
124
+ {
125
+ RemovePreset ( i ) ;
126
+ i -- ;
127
+ deletionHappened = true ;
128
+ }
129
+ }
130
+
131
+ EditorGUILayout . EndHorizontal ( ) ;
132
+
122
133
EditorGUI . BeginChangeCheck ( ) ;
123
134
124
- if ( m_InspectorsFade [ i ] )
135
+ if ( ! deletionHappened && m_InspectorsFade [ i ] )
125
136
{
126
137
_opts . importOptions [ i ] . nameFilter =
127
138
EditorGUILayout . TextField ( "Filter" , _opts . importOptions [ i ] . nameFilter ) ;
0 commit comments