版本:Unity 6 (6000.0)
语言English
  • C#

Preset.excludedProperties

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实阅读了用户提出的每个更改建议,并在适用时进行更新。

关闭

提交失败

由于某些原因,您的更改建议无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

public string[] excludedProperties;

描述

将预设应用于对象时要忽略的属性列表。

设置在将预设应用于对象时要忽略的属性或父属性列表。

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