에디터 스크립트에서 ObjectFactory 클래스를 사용하여 새 게임 오브젝트, 컴포넌트와 에셋을 생성하십시오. 이러한 항목을 생성할 때 ObjectFactory
클래스는 자동으로 기본 프리셋을 사용합니다. ObjectFactory
가 이 작업을 처리하므로 스크립트는 기본 프리셋을 검색하여 적용할 필요가 없습니다.
기본적으로 프리셋을 지원하고 활성화하려면 클래스가 다음 중 하나에서 상속받아야 합니다.
프리셋 인스펙터는 사용자가 값을 수정할 수 있도록 클래스의 임시 인스턴스를 만듭니다. 따라서 클래스가 정적 값, 프로젝트 에셋 또는 씬 인스턴스 등 다른 오브젝트에 영향을 주거나 기반하지 않는지 확인하십시오.
팁: CustomEditor 속성 사용은 선택 사항입니다.
프리셋을 사용할 수 있는 설정으로 커스텀 EditorWindow 클래스를 설정하는 경우 다음을 수행하십시오.
ScriptableObject를 사용하여 설정의 복사본을 저장합니다. CustomEditor 속성도 가질 수 있습니다. 프리셋 시스템이 이 오브젝트를 처리합니다.
항상 임시 ScriptableObject
인스펙터를 사용하여 프리셋 설정을 UI에 표시합니다. 이렇게 하면 EditorWindow
에서 그리고 저장된 프리셋을 편집할 때 사용자에게 동일한 UI가 표시됩니다.
Preset 버튼을 노출하고 자체 PresetSelectorReceiver 구현을 사용하여 프리셋이 Select Preset 창에서 선택된 경우 EditorWindow
설정을 최신 상태로 유지합니다.
다음 예제 스크립트는 프리셋 설정을 간단한 EditorWindow
에 추가하는 방법을 보여줍니다.
이 예제 스크립트는 커스텀 창에 설정을 유지하고 표시하는 ScriptableObject를 보여줍니다(Editor/MyWindowSettings.cs 파일에 저장됨).
using UnityEngine;
// Temporary ScriptableObject used by the Preset system
public class MyWindowSettings : ScriptableObject
{
[SerializeField]
string m_SomeSettings;
public void Init(MyEditorWindow window)
{
m_SomeSettings = window.someSettings;
}
public void ApplySettings(MyEditorWindow window)
{
window.someSettings = m_SomeSettings;
window.Repaint();
}
}
커스텀 창에 사용되는 ScriptableObject
를 업데이트하는 PresetSelectorReceiver
의 예제 스크립트입니다(Editor/MySettingsReceiver.cs라고 불리는 파일에 저장됨).
using UnityEditor.Presets;
// PresetSelector receiver to update the EditorWindow with the selected values.
public class MySettingsReceiver : PresetSelectorReceiver
{
Preset initialValues;
MyWindowSettings currentSettings;
MyEditorWindow currentWindow;
public void Init(MyWindowSettings settings, MyEditorWindow window)
{
currentWindow = window;
currentSettings = settings;
initialValues = new Preset(currentSettings);
}
public override void OnSelectionChanged(Preset selection)
{
if (selection != null)
{
// Apply the selection to the temporary settings
selection.ApplyTo(currentSettings);
}
else
{
// None have been selected. Apply the Initial values back to the temporary selection.
initialValues.ApplyTo(currentSettings);
}
// Apply the new temporary settings to our manager instance
currentSettings.ApplySettings(currentWindow);
}
public override void OnSelectionClosed(Preset selection)
{
// Call selection change one last time to make sure you have the last selection values.
OnSelectionChanged(selection);
// Destroy the receiver here, so you don't need to keep a reference to it.
DestroyImmediate(this);
}
}
임시 ScriptableObject 인스펙터와 해당 프리셋 버튼을 사용하여 커스텀 설정을 보여주는 EditorWindow의 예제 스크립트입니다(Editor/MyEditorWindow.cs 파일에 저장됨).
using UnityEngine;
using UnityEditor;
using UnityEditor.Presets;
public class MyEditorWindow : EditorWindow
{
// get the Preset icon and a style to display it
private static class Styles
{
public static GUIContent presetIcon = EditorGUIUtility.IconContent("Preset.Context");
public static GUIStyle iconButton = new GUIStyle("IconButton");
}
Editor m_SettingsEditor;
MyWindowSettings m_SerializedSettings;
public string someSettings
{
get { return EditorPrefs.GetString("MyEditorWindow_SomeSettings"); }
set { EditorPrefs.SetString("MyEditorWindow_SomeSettings", value); }
}
// Method to open the window
[MenuItem("Window/MyEditorWindow")]
static void OpenWindow()
{
GetWindow<MyEditorWindow>();
}
void OnEnable()
{
// Create your settings now and its associated Inspector
// that allows to create only one custom Inspector for the settings in the window and the Preset.
m_SerializedSettings = ScriptableObject.CreateInstance<MyWindowSettings>();
m_SerializedSettings.Init(this);
m_SettingsEditor = Editor.CreateEditor(m_SerializedSettings);
}
void OnDisable()
{
Object.DestroyImmediate(m_SerializedSettings);
Object.DestroyImmediate(m_SettingsEditor);
}
void OnGUI()
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("My custom settings", EditorStyles.boldLabel);
GUILayout.FlexibleSpace();
// create the Preset button at the end of the "MyManager Settings" line.
var buttonPosition = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight, Styles.iconButton);
if (EditorGUI.DropdownButton(buttonPosition, Styles.presetIcon, FocusType.Passive, Styles.iconButton))
{
// Create a receiver instance. This destroys itself when the window appears, so you don't need to keep a reference to it.
var presetReceiver = ScriptableObject.CreateInstance<MySettingsReceiver>();
presetReceiver.Init(m_SerializedSettings, this);
// Show the PresetSelector modal window. The presetReceiver updates your data.
PresetSelector.ShowSelector(m_SerializedSettings, null, true, presetReceiver);
}
EditorGUILayout.EndHorizontal();
// Draw the settings default Inspector and catch any change made to it.
EditorGUI.BeginChangeCheck();
m_SettingsEditor.OnInspectorGUI();
if (EditorGUI.EndChangeCheck())
{
// Apply changes made in the settings editor to our instance.
m_SerializedSettings.ApplySettings(this);
}
}
}
2017–03–27 페이지 게시됨 2018.1의 새 기능 NewIn20181
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.
방문하는 모든 웹사이트의 정보가 브라우저에서 쿠키 형태로 저장되거나 수집될 수 있습니다. 본 정보는 귀하와 귀하의 선호도, 기기에 대한 것이며, 귀하의 선호도에 따라 사이트가 동작하도록 하는 데 사용됩니다. 본 정보는 귀하를 직접적으로 식별하지 않으나 보다 개인화된 웹 경험을 제공하기 위해 사용됩니다. 그러나 일부 쿠키를 거부할 수 있습니다. 더 자세한 정보를 확인하고 기본 설정을 변경하려면 해당 카테고리의 제목을 클릭하세요. 그러나 일부 쿠키를 차단하면 귀하의 사이트 경험과 회사에서 제공하는 서비스에 영향을 미칠 수 있습니다.
추가 정보
본 쿠키는 동영상 및 실시간 채팅과 같은 고급 기능과 개인화를 허용합니다. 쿠키는 회사 또는 회사 페이지에 추가된 제3 서비스 사업자가 설정할 수 있습니다. 쿠키를 허용하지 않으면 일부 기능이 정상 작동하지 않을 수 있습니다.
이 쿠키는 방문자 수, 데이터 트래픽 정보를 확인해 회사 사이트의 성능을 측정하고 개선할 수 있도록 합니다. 또한 가장 인기가 많거나 인기가 적은 페이지를 확인하며 방문자가 사이트를 이동하는 방법을 확인할 수 있도록 합니다. 쿠키가 수집하는 모든 정보는 누적되며 익명 처리됩니다. 쿠키를 허용하지 않으면 귀하가 회사 사이트에 방문한 시기를 알 수 없습니다.
이 쿠키는 회사의 광고 협력사가 회사 사이트에 설정한 것입니다. 해당 협력사는 귀하의 관심사에 대한 프로파일을 만들고 다른 사이트에서도 관련 광고를 표시하기 위해 이 쿠키를 사용합니다. 이 쿠키는 귀하의 브라우저와 기기를 식별함으로써 동작합니다. 이 쿠키를 허용하지 않으면 다른 웹사이트에서 회사가 제공하는 맞춤형 광고를 경험할 수 없습니다.
이 쿠키는 웹사이트의 기능을 위해 필수적이며, 회사 시스템 내에서 종료할 수 없습니다. 이 쿠키는 개인정보 선호도, 로그인 또는 양식 작성과 같은 서비스 요청에 해당하는 귀하의 행위에 따라서만 주로 설정됩니다. 귀하의 브라우저에서 이 쿠키를 차단하거나 쿠키에 대해 알림 설정을 할 수 있지만, 이 경우 해당 사이트의 일부 기능이 동작하지 않을 수 있습니다.