Пример #1
0
 static bool ApplyImportSettingsBeforeSavingPreset(ref Preset preset, Object target)
 {
     // make sure modifications to importer get applied before creating preset.
     foreach (InspectorWindow i in InspectorWindow.GetAllInspectorWindows())
     {
         ActiveEditorTracker activeEditor = i.tracker;
         foreach (Editor e in activeEditor.activeEditors)
         {
             var editor = e as AssetImporterEditor;
             if (editor != null && editor.target == target && editor.HasModified())
             {
                 if (EditorUtility.DisplayDialog("Unapplied import settings", "Apply settings before creating a new preset", "Apply", "Cancel"))
                 {
                     editor.SaveChanges();
                     // after reimporting, the target object has changed, so update the preset with the newly imported values.
                     preset.UpdateProperties(editor.target);
                     return(false);
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #2
0
        private static bool ApplyImportSettingsBeforeSavingPreset(ref Preset preset, UnityEngine.Object target)
        {
            InspectorWindow[] allInspectorWindows = InspectorWindow.GetAllInspectorWindows();
            bool result;

            for (int i = 0; i < allInspectorWindows.Length; i++)
            {
                InspectorWindow     inspectorWindow = allInspectorWindows[i];
                ActiveEditorTracker tracker         = inspectorWindow.tracker;
                Editor[]            activeEditors   = tracker.activeEditors;
                int j = 0;
                while (j < activeEditors.Length)
                {
                    Editor editor = activeEditors[j];
                    AssetImporterEditor assetImporterEditor = editor as AssetImporterEditor;
                    if (assetImporterEditor != null && assetImporterEditor.target == target && assetImporterEditor.HasModified())
                    {
                        if (EditorUtility.DisplayDialog("Unapplied import settings", "Apply settings before creating a new preset", "Apply", "Cancel"))
                        {
                            assetImporterEditor.ApplyAndImport();
                            preset.UpdateProperties(assetImporterEditor.target);
                            result = false;
                            return(result);
                        }
                        result = true;
                        return(result);
                    }
                    else
                    {
                        j++;
                    }
                }
            }
            result = false;
            return(result);
        }