AssetPostprocessor.OnPostprocessGameObjectWithUserProperties 在导入带有用户属性的游戏物体之后

function OnPostprocessGameObjectWithUserProperties (root : GameObject, propNames : string[], values : object[]) : void

Description描述

Gets called for each GameObject that had at least one userpropery attached to it in the imported file.

在导入文件中,为每个至少附加了一个用户属性的游戏物体调用。

The propNames is a string[] containing all the names of the properties found. The values is an System.Object[] containing all the actual values. These can be of type string, Vector4, bool, string, Color, float, int.

PropNames是一个string[],其中包含了所有找到的属性的名称.该值是一个object[],包含所有实际值。它们可以是string,Vector4, bool, string, Color, float, int。

Typical usecase for this feature is reading out "userdata" stored on objects in 3dmax/maya. Based on what is written in the text userdata for an object, you could decide to postprocess your GameObject in different ways. The sample below adds a simple BoxCollider component if the userdata string contains "addboxcollider".

典型的运用是从存储在3dmax/maya的对象中读取”userdata”,基于什么用户数据被写入到对象,你可以用不同的方式来后处理游戏物体。下面的例子中,如果用户数据字符串包含”addboxcollider”,就添加一个BoxCollider组件。

class MyPostprocessor extends AssetPostprocessor {



	function OnPostprocessGameObjectWithUserProperties (

	go : GameObject ,

	propNames : String [],

	values : System. Object []

	)

	{

		for (var i : int =0; i!= propNames.Length; i++)

		{



			var propName : String = propNames[i];

			var value : Object = values[i];



			Debug.Log ("Propname: "+propName+" value: "+values[i]);



			if (value.GetType() == String )

			{

				var s : String = value;

				if (s.Contains("addboxcollider")) go.AddComponent( BoxCollider );

			}



			if (value.GetType() == Vector4 )

			{

				var v : Vector4 = value;

				// do something useful.

			}



			if (value.GetType() == Color )

			{

				var c : Color = value;

				// do something useful.

			}



			if (value.GetType() == int)

			{

				var myInt : int = value;

				// do something useful.

			}



			if (value.GetType() == float)

			{

				var myFloat : float = value;

				// do something useful

			}

		}

	}

}
Page last updated: 2011-1-8