如果给定的目标是从 PresetEditor 内部创建的临时 UnityEngine.Object 实例,则返回 true。
此方法必须在 CustomEditor 内部使用,才能更改在 Preset 上下文中显示的值。某些 CustomEditor(例如全局设置的 CustomEditor)与可以是 Preset 部分的序列化值以及项目之间共享的不可序列化的全局值混合在一起。在 Preset 检查器中,应隐藏或至少禁用这些全局值,因为在 Preset 中更改它们实际上会全局更改它们。
using UnityEditor; using UnityEditor.Presets; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements;
[CustomEditor(typeof(SomeSettings))] class SomeSettingsEditor : Editor { public override VisualElement CreateInspectorGUI() { var root = new VisualElement();
// create UI for serialized data var aFloat = new PropertyField(serializedObject.FindProperty("m_AFloat")); root.Add(aFloat);
// We are adding another field with an EditorPref data that we want to be excluded from the Preset UI. if (!Preset.IsEditorTargetAPreset(target)) { var global = new FloatField("Global Pref"); global.value = EditorPrefs.GetFloat("SomeGlobalSetting", 0.0f); global.RegisterCallback<ChangeEvent<float>>(evt => EditorPrefs.SetFloat("SomeGlobalSetting", evt.newValue)); root.Add(global); }
return root; } }
class SomeSettings : ScriptableObject { public float m_AFloat; }