EditorGUILayout.ObjectField 物体字段

static function ObjectField (obj : Object, objType : System.Type, allowSceneObjects : boolean, params options : GUILayoutOption[]) : Object
static function ObjectField (label : String, obj : Object, objType : System.Type, allowSceneObjects : boolean, params options : GUILayoutOption[]) : Object
static function ObjectField (label : GUIContent, obj : Object, objType : System.Type, allowSceneObjects : boolean, params options : GUILayoutOption[]) : Object

Parameters参数

Returns

Object - The object that has been set by the user.

返回Object,由用户设置的物体。

Description描述

Make an object field. You can assign objects either by drag'n drop objects or by selecting an object using the Object Picker.

制作一个物体字段。可以指定物体无论是通过拖拽物体或通过物体拾取器选择物体。

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.

如果物体引用作为资源的一部分储存,确保allowSceneObjects参数为假。因为资源不能存储在一个场景中的对象的引用。

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.
See example in Editor class.

如果ObjectField用于一个脚本组件自定义编辑器的一部分,如果组件在一个资源或场景物体,使用EditorUtility.IsPersistent()来检查。

EditorGUILayout.ObjectField 物体字段

Search for a help page by selecting the GameObject in the Object Field.
搜索在这个物体字段选择的物体帮助页面。

// EditorScript that quickly searchs for a help page
// of the selected Object.
//搜索选择物体的帮助页面
// If there is no page found on the Manual it opens the Unity forum.
//如果没有发现页面,将打开Unity论坛
import UnityEditor;

class QuickHelper extends EditorWindow {

	var source : Object;

	@MenuItem("Example/QuickHelper _h")
	static function Init() {
	var window : QuickHelper = EditorWindow.GetWindowWithRect(QuickHelper, Rect(0,0,165,100));
	window.Show();
	}

	function OnGUI() {
		EditorGUILayout.BeginHorizontal();
		source = EditorGUILayout.ObjectField(source, Object);
		EditorGUILayout.EndHorizontal();

		if(GUILayout.Button("Search!")) {
			if(source == null) {
			this.ShowNotification(GUIContent("No object selected for searching"));
			} else {
				if(Help.HasHelpForObject(source))
					Help.ShowHelpForObject(source);
				else
					Help.BrowseURL("http://forum.unity3d.com/search.php");
			}
		}
	}
}
最后修改:2011年10月3日 Monday 15:21

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。