Experimental: this API is experimental and might be changed or removed in the future.

AssetImporterEditor

class in UnityEditor.Experimental.AssetImporters

/

다음으로부터 상속:Editor

매뉴얼로 전환

설명

Default editor for all asset importer settings.

Use the default editor to edit the import settings for assets. You can define a custom import settings editor for a specific asset type. To do this, create a new class that inherits from AssetImporterEditor and uses a CustomEditorAttribute that refers to a ScriptedImporter.

The following example shows how to make a custom ScriptedImporterEditor for a ScriptedImporter with a custom layout.

using System.IO;
using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;

[CustomEditor(typeof(TransformImporter))] [CanEditMultipleObjects] public class TransformImporterEditor : ScriptedImporterEditor { // Stored SerializedProperty to draw in OnInspectorGUI. SerializedProperty m_GenerateChild;

public override void OnEnable() { base.OnEnable(); // Once in OnEnable, retrieve the serializedObject property and store it. m_GenerateChild = serializedObject.FindProperty("generateChild"); }

public override void OnInspectorGUI() { // Update the serializedObject in case it has been changed outside the Inspector. serializedObject.Update();

// Draw the boolean property. EditorGUILayout.PropertyField(m_GenerateChild);

// Apply the changes so Undo/Redo is working serializedObject.ApplyModifiedProperties();

// Call ApplyRevertGUI to show Apply and Revert buttons. ApplyRevertGUI(); } }

[ScriptedImporter(0, ".transform")] public class TransformImporter : ScriptedImporter { public bool generateChild;

public override void OnImportAsset(AssetImportContext ctx) { GameObject root = ObjectFactory.CreateGameObject(Path.GetFileNameWithoutExtension(ctx.assetPath)); if (generateChild) { GameObject child = ObjectFactory.CreateGameObject("child"); child.transform.SetParent(root.transform); } ctx.AddObjectToAsset("main", root); ctx.SetMainObject(root); } }

The following example demonstrates a specific case where the user cannot change settings and the Apply/Revert buttons are hidden with needsApplyRevert.

using System.IO;
using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;

[CustomEditor(typeof(EmptinessImporter))] [CanEditMultipleObjects] public class EmptinessImporterEditor : ScriptedImporterEditor { //Let the parent class know that the Apply/Revert mechanism is skipped. protected override bool needsApplyRevert => false;

public override void OnInspectorGUI() { // Draw some information EditorGUILayout.HelpBox("Because this Importer doesn't have any settings, the Apply/Revert buttons are hidden.", MessageType.None); } }

[ScriptedImporter(0, ".emptiness")] public class EmptinessImporter : ScriptedImporter { public override void OnImportAsset(AssetImportContext ctx) { GameObject root = ObjectFactory.CreateGameObject(Path.GetFileNameWithoutExtension(ctx.assetPath)); ctx.AddObjectToAsset("main", root); ctx.SetMainObject(root); } }

The following example shows how to use extraDataType to read or save settings that are not part of the ScriptedImporter serialization, in the custom AssetImporterEditor.

using System;
using System.IO;
using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
using Object = UnityEngine.Object;

[CustomEditor(typeof(BooleanImporter))] [CanEditMultipleObjects] public class BooleanImporterEditor : ScriptedImporterEditor { // Property to show in the custom OnInspectorGUI. SerializedProperty m_BooleanProperty;

// override extraDataType to return the type that will be used in the Editor. protected override Type extraDataType => typeof(BooleanClass);

// override InitializeExtraDataInstance to set up the data. protected override void InitializeExtraDataInstance(Object extraTarget, int targetIndex) { var boolean = (BooleanClass)extraTarget; // Read the boolean value from the text file and fill the extraTarget object with the data. string fileContent = File.ReadAllText(((AssetImporter)targets[targetIndex]).assetPath); if (!bool.TryParse(fileContent, out boolean.boolean)) { boolean.boolean = false; } }

protected override void Apply() { base.Apply(); // After the Importer is applied, rewrite the file with the custom value. for (int i = 0; i < targets.Length; i++) { string path = ((AssetImporter)targets[i]).assetPath; File.WriteAllText(path, ((BooleanClass)extraDataTargets[i]).boolean.ToString()); } }

public override void OnEnable() { base.OnEnable(); // In OnEnable, retrieve the importerUserSerializedObject property and store it. m_BooleanProperty = extraDataSerializedObject.FindProperty("boolean"); }

public override void OnInspectorGUI() { // Note: you don't need to call serializedObject.Update or serializedObject.ApplyModifiedProperties // because you are not changing the target (serializedObject) itself.

// Update the importerUserSerializedObject in case it has been changed outside the Inspector. extraDataSerializedObject.Update();

// Draw the boolean property. EditorGUILayout.PropertyField(m_BooleanProperty);

// Apply the changes so Undo/Redo is working. extraDataSerializedObject.ApplyModifiedProperties();

// Call ApplyRevertGUI to show Apply and Revert buttons. ApplyRevertGUI(); } }

public class BooleanClass : ScriptableObject { public bool boolean; }

[ScriptedImporter(0, ".boolean")] public class BooleanImporter : ScriptedImporter { public override void OnImportAsset(AssetImportContext ctx) { string fileContent = File.ReadAllText(ctx.assetPath); var booleanObj = ObjectFactory.CreateInstance<BooleanClass>(); if (!bool.TryParse(fileContent, out booleanObj.boolean)) { booleanObj.boolean = false; } ctx.AddObjectToAsset("main", booleanObj); ctx.SetMainObject(booleanObj); Debug.Log("Imported Boolean value: " + booleanObj.boolean); } }

You can also use ScriptedImporter settings and extraData in the same AssetImporterEditor:

using UnityEditor;
using UnityEditor.Experimental.AssetImporters;

[CustomEditor(typeof(SomeScriptedImporter))] [CanEditMultipleObjects] public class SomeImporterEditor : ScriptedImporterEditor { // ...

public override void OnInspectorGUI() { serializedObject.Update(); extraDataSerializedObject.Update();

// Use propertyDrawers and custom GUI for any property from both serializedObject and extraDataSerializedObject.

extraDataSerializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();

ApplyRevertGUI(); } }

[ScriptedImporter(0, ".someFile")] public class SomeScriptedImporter : ScriptedImporter { public override void OnImportAsset(AssetImportContext ctx) { // ... } }

변수

extraDataSerializedObjectA SerializedObject that represents the extraDataTarget or the extraDataTargets of the AssetImporterEditor.
extraDataTargetThe extra data object associated with the Editor.target.
extraDataTargetsAn array of objects associated with each Editor.targets.
extraDataTypeOverride this property to return a type that inherits from ScriptableObject. This makes the AssetImporterEditor aware of serialized data outside of the Importer.
needsApplyRevertWhether the ApplyRevertGUI method is required to draw in the Inspector.
showImportedObjectShould imported object be shown as a separate editor?
useAssetDrawPreviewDetermines if the asset preview is handled by the AssetEditor or the Importer DrawPreview

Public 함수

HasModifiedDetermine if the import settings have been modified.
OnDisableThis function is called when the editor object goes out of scope.
OnEnableThis function is called when the object is loaded.
OnInspectorGUIOverride this method to create your own Inpsector GUI for a ScriptedImporter.

보호되는 함수

ApplySaves any changes from the Editor's control into the asset's import settings object.
ApplyAndImportSaves the changes from the editor UI to the settings object and imports the asset.
ApplyButtonImplements the 'Apply' button of the inspector.
ApplyRevertGUIAdd's the 'Apply' and 'Revert' buttons to the editor.
AwakeThis function is called when the Editor script is started.
InitializeExtraDataInstanceThis method is called during the initialization process of the Editor, after Awake and before OnEnable.
OnApplyRevertGUIProcess the 'Apply' and 'Revert' buttons.
ResetValuesReset the import settings to their last saved values.
RevertButtonImplements the 'Revert' button of the inspector.

상속된 멤버

변수

serializedObjectA SerializedObject representing the object or objects being inspected.
targetThe object being inspected.
targetsAn array of all the object being inspected.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public 함수

CreateInspectorGUIImplement this method to make a custom UIElements inspector.
DrawDefaultInspectorDraws the built-in inspector.
DrawHeaderCall this function to draw the header of the editor.
DrawPreviewThe first entry point for Preview Drawing.
GetInfoStringImplement this method to show asset information on top of the asset preview.
GetPreviewTitleOverride this method if you want to change the label of the Preview area.
HasPreviewGUIOverride this method in subclasses if you implement OnPreviewGUI.
OnInteractivePreviewGUIImplement to create your own interactive custom preview. Interactive custom previews are used in the preview area of the inspector and the object selector.
OnPreviewGUIImplement to create your own custom preview for the preview area of the inspector, the headers of the primary editor, and the object selector.
OnPreviewSettingsOverride this method if you want to show custom controls in the preview header.
RenderStaticPreviewOverride this method if you want to render a static preview.
RepaintRedraw any inspectors that shows this editor.
RequiresConstantRepaintChecks if this editor requires constant repaints in its current state.
UseDefaultMarginsOverride this method in subclasses to return false if you don't want default margins.
GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the object.

보호되는 함수

ShouldHideOpenButtonReturns the visibility setting of the "open" button in the Inspector.

정적 함수

CreateCachedEditorOn return previousEditor is an editor for targetObject or targetObjects. The function either returns if the editor is already tracking the objects, or destroys the previous editor and creates a new one.
CreateCachedEditorWithContextCreates a cached editor using a context object.
CreateEditorMake a custom editor for targetObject or targetObjects.
CreateEditorWithContextMake a custom editor for targetObject or targetObjects with a context object.
DrawFoldoutInspectorDraws the inspector GUI with a foldout header for target.
DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateClones the object original and returns the clone.
CreateInstanceCreates an instance of a scriptable object.

연산자

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.

메시지

OnSceneGUIEnables the Editor to handle an event in the Scene view.
OnDestroyThis function is called when the scriptable object will be destroyed.

Events

finishedDefaultHeaderGUIAn event raised while drawing the header of the Inspector window, after the default header items have been drawn.