将预设应用于对象时要忽略的属性列表。
设置在将预设应用于对象时要忽略的属性或父属性列表。
using UnityEngine; using UnityEditor.Presets;
static class PresetsExample { public static bool ApplyToWithExclusion(Preset preset, Transform target, string[] exclusion) { var current = preset.excludedProperties; preset.excludedProperties = exclusion; var success = preset.ApplyTo(target); preset.excludedProperties = current; return success; }
public static void ApplyTransformPresetWithoutPosition(Preset preset, Transform target) { if (ApplyToWithExclusion(preset, target, new[] { "m_LocalPosition" })) { Debug.Log("The Preset has been applied and the position hasn't changed"); } else { Debug.Log("The Preset was not applied"); } } }
using UnityEngine; using UnityEditor.Presets;
static class PresetsExample { public static bool ApplyOnlyTheYPosition(Preset preset, Transform target) { var current = preset.excludedProperties; preset.excludedProperties = new[] { "m_LocalPosition.x", "m_LocalPosition.z" }; var success = preset.ApplyTo(target, new[] { "m_LocalPosition" }); preset.excludedProperties = current; return success; } }
注意:如果预设上的所有属性都被忽略,则 ApplyTo 将始终返回 false。当使用 ApplyTo(Object, string[]) 且指定要应用的属性列表都被忽略时,也会出现这种情况。
using UnityEngine; using UnityEditor.Presets;
static class PresetsExample { public static bool ApplyAlwaysReturnFalse(Preset preset, Transform target) { var current = preset.excludedProperties; preset.excludedProperties = new[] { "m_LocalPosition" }; var success = preset.ApplyTo(target, new[] { "m_LocalPosition" }); // always false because we try to apply only the ignored property. preset.excludedProperties = current; return success; } }