public static Object ObjectField (Object obj, Type objType, bool allowSceneObjects, params GUILayoutOption[] options);
public static Object ObjectField (string label, Object obj, Type objType, bool allowSceneObjects, params GUILayoutOption[] options);
public static Object ObjectField (GUIContent label, Object obj, Type objType, bool allowSceneObjects, params GUILayoutOption[] options);

Parameters

label(可选)字段前的标签。
obj字段显示的对象。
objType可以分配的对象类型。
allowSceneObjectsAllow assigning Scene objects. See Description for more info.
options一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。 另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight

Returns

Object 用户已设置的对象。

Description

生成一个可接收任何对象类型的字段。

您可以通过拖放或使用对象选择器选择对象来分配对象。

Ensure that the allowSceneObjects parameter is false if the object reference is stored as part of an asset, since assets can't store references to objects in a Scene.

If the ObjectField is part of a custom Editor for a script component, use EditorUtility.IsPersistent() to check if the component is on an asset or a Scene object.

有关更多信息,请参阅 Editor 类中的示例。


Search for a help page by selecting the GameObject in the Object Field.

// EditorScript that quickly searches for a help page
// about the selected Object.
//
// If no such page is found in the Manual it opens the Unity forum.

using UnityEditor; using UnityEngine; using System.Collections;

public class ExampleClass : EditorWindow { public Object source;

[MenuItem("Example/ObjectField Example _h")] static void Init() { var window = GetWindowWithRect<ExampleClass>(new Rect(0, 0, 165, 100)); window.Show(); }

void OnGUI() { EditorGUILayout.BeginHorizontal(); source = EditorGUILayout.ObjectField(source, typeof(Object), true); EditorGUILayout.EndHorizontal();

if (GUILayout.Button("Search!")) { if (source == null) ShowNotification(new GUIContent("No object selected for searching")); else if (Help.HasHelpForObject(source)) Help.ShowHelpForObject(source); else Help.BrowseURL("http://forum.unity3d.com/search.php"); } } }

public static void ObjectField (SerializedProperty property, params GUILayoutOption[] options);
public static void ObjectField (SerializedProperty property, GUIContent label, params GUILayoutOption[] options);
public static void ObjectField (SerializedProperty property, Type objType, params GUILayoutOption[] options);
public static void ObjectField (SerializedProperty property, Type objType, GUIContent label, params GUILayoutOption[] options);

Parameters

property字段显示的对象引用属性。
objType可以分配的对象类型。
label(可选)字段前的标签。传递 GUIContent.none 以隐藏标签。
options一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。
另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight

Description

生成一个可接收任何对象类型的字段。

已弃用