EditorGUI.ObjectField 物体字段

static function ObjectField (position : Rect, obj : Object, objType : System.Type, allowSceneObjects : boolean) : Object
static function ObjectField (position : Rect, label : String, obj : Object, objType : System.Type, allowSceneObjects : boolean) : Object
static function ObjectField (position : Rect, label : GUIContent, obj : Object, objType : System.Type, allowSceneObjects : boolean) : 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 and 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()来检查。

EditorGUI.ObjectField 对象字段

Object field in an Editor Window.
在编辑器窗口中的对象字段。

//Select the dependencies of the found GameObject
//管理选择找到的游戏对象
class EditorGUIObjectField extends EditorWindow {

	var obj : GameObject = null;

	@MenuItem("Examples/Select Dependencies")
	static function Init() {
		var window = GetWindow(EditorGUIObjectField);
		window.position = Rect(0, 0, 250, 80);
		window.Show();
	}

	function OnInspectorUpdate() {
		Repaint();
	}

	function OnGUI() {
		obj = EditorGUI.ObjectField(Rect(3,3,position.width - 6, 20),
			"Find Dependency",
			obj,
			GameObject);

		if(obj) {
				if(GUI.Button(Rect(3,25,position.width - 6, 20), "Check Dependencies"))
				Selection.objects = EditorUtility.CollectDependencies([obj]);
		} else {
			EditorGUI.LabelField(Rect(3,25,position.width - 6,20),
				"Missing:",
				"Select an object first");
		}
	}
}
最后修改:2011年10月4日 Tuesday 10:15

本脚本参考基于Unity 3.4.1f5

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