Version: 2022.1

Preset.excludedProperties

切换到手册
public string[] excludedProperties ;

描述

List of properties to ignore when applying the Preset to an object.

Sets the list of properties or parent properties to ignore when applying the Preset to an object.

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; } }

Note: If every properties get ignored on a Preset, ApplyTo will always return false. This is also the case when using ApplyTo(Object, string[]) and the specified list of properties to apply are all ignored.

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; } }