Version: 2020.2

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; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961