EditorUtility.CreateGameObjectWithHideFlags 创建带有标识的游戏物体

static function CreateGameObjectWithHideFlags (name : string, flags : HideFlags, params components : Type[]) : GameObject

Description描述

Creates a game object with HideFlags and specified components.

创建带有标识(HideFlags)的游戏物体并指定组件。

This is very similar to creating a GameObject the usual way, except it sets the specified HideFlags immediately.

这和通常创建GameObject的方法非常相似,除了力矩设置指定的标识(HideFlags)。

EditorUtility.CreateGameObjectWithHideFlags 创建带有标识的游戏物体

Editor Window that shows how does the example looks.

// Simple script that lets you manage the flags of an instanceID from a
// GameObject or lets you create a new empty GameObject with custom flags set
//让你从一个游戏物体管理实例ID的标识或创建一个新的带有标识的游戏物体
class GameObjectFlags extends EditorWindow {

	var objName : String = "GameObject";
	var instanceID : int = 0;
	var create : boolean = true;
	var go : GameObject = null;

	var hideHierarchy : boolean = false;

	@MenuItem("Examples/GameObject flags")
	static function Init() {
		var window = GetWindow(GameObjectFlags);
		window.Show();
	}

	function OnGUI() {
		create = EditorGUILayout.Toggle("Create a GO:", create);
		GUI.enabled = create;
		objName = EditorGUILayout.TextField("GameObject Name:", objName);
		if(GUILayout.Button("Create")) {
			var created = EditorUtility.CreateGameObjectWithHideFlags(
				objName,
				hideHierarchy ? HideFlags.HideInHierarchy : 0);
			Debug.Log("Created GameObject ID: " + created.GetInstanceID());
		}
		GUI.enabled = !create;
		EditorGUILayout.BeginHorizontal();
		instanceID = EditorGUILayout.IntField("Instance ID:", instanceID);
		if(GUILayout.Button("Search & Update flags")) {
			go = null;
			go = EditorUtility.InstanceIDToObject(instanceID);
			if(go)
				go.hideFlags = hideHierarchy ? HideFlags.HideInHierarchy : 0;
		}
		EditorGUILayout.EndHorizontal();

		if(!go)
			EditorGUILayout.LabelField("Object: ","No object was found");
		else
			EditorGUILayout.LabelField("Object: ", go.name);

		GUI.enabled = true;
		hideHierarchy = EditorGUILayout.Toggle("HideInHierarchy", hideHierarchy);

	}
}
最后修改:2011年7月16日 Saturday 11:22

本脚本参考基于Unity 3.4.1f5

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