一个预设包含一个对象的默认值。
Preset 类包含创建对象时所用的对象类型以及含此对象的每个已序列化属性/值对的列表。 此类可用于在 Editor 中存储任何已序列化对象的信息,并可将这些信息重新应用到此对象或同类型的其他任何对象。 此外,还可以使用 .preset 扩展名将预设另存为资源。
using UnityEditor; using UnityEditor.Presets; using UnityEngine;
public static class PresetUsageExample { // This method uses a Preset to copy the serialized values from the source to the target and return true if the copy succeed. public static bool CopyObjectSerialization(Object source, Object target) { Preset preset = new Preset(source); return preset.ApplyTo(target); }
// This method creates a Preset from a given Object and save it as an asset in the project. public static void CreatePresetAsset(Object source, string name) { Preset preset = new Preset(source); AssetDatabase.CreateAsset(preset, "Assets/" + name + ".preset"); } }
excludedProperties | List of properties to ignore when applying the Preset to an object. |
PropertyModifications | 返回此预设所拥有的 PropertyModification 数组的副本。 |
Preset | 从给定的对象中构造新的预设。 |
ApplyTo | 将此预设应用到目标对象。 |
CanBeAppliedTo | 如果此预设可应用到目标对象,则返回 true。 |
DataEquals | 确定目标对象是否具有与预设相同的序列化值。 |
GetPresetType | 返回预设的 PresetType。 |
GetTargetFullTypeName | 返回此预设目标完整类型的可读字符串,包括命名空间。 |
GetTargetTypeName | 返回此预设目标类型的可读字符串。 |
IsValid | 如果此预设的预设类型有效,则返回 true。 |
UpdateProperties | 使用给定对象的值来更新此预设的属性。给定对象的类型必须与此预设的类型相匹配。 |
GetAllDefaultTypes | Returns all the PresetType that have at least one DefaultPreset entry in the default Presets list. |
GetDefaultPresetsForObject | 获取在应用于目标时设置默认值的预设的有序列表。 |
GetDefaultPresetsForType | 获取基于指定 PresetType 的 DefaultPreset 的有序列表。 |
IsEditorTargetAPreset | Returns true if the given target is a temporary UnityEngine.Object instance created from inside a PresetEditor. |
RemoveFromDefault | 删除项目中具有默认值的预设。 |
SetDefaultPresetsForType | 使用特定 PresetType 的过滤器设置默认预设列表。 |
GetInstanceID | Gets the instance ID of the object. |
ToString | 返回对象的名称。 |
Destroy | 移除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | 在加载新的 Scene 时,请勿销毁 Object。 |
FindAnyObjectByType | Retrieves any active loaded object of Type type. |
FindFirstObjectByType | Retrieves the first active loaded object of Type type. |
FindObjectsByType | Retrieves a list of all loaded objects of Type type. |
Instantiate | 克隆 original 对象并返回克隆对象。 |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.