EditorPrefs.SetInt 设置整数

static function SetInt (key : string, value : int) : void

Description描述

Sets the value of the preference identified by key.

设置由键确定的偏好值。

EditorPrefs.SetInt 设置整数

Add one or more script to the selected GameObjects

添加一个或更多脚本到选择的游戏物体。

// Simple Editor Script that adds one or more scripts
// to the selected GameObjects
//添加一个或更多脚本到选择的游戏物体。
class ScriptAdder extends EditorWindow {
	var numComponents = 1;
	var componentsToAdd : MonoScript[];
	@MenuItem("Examples/Script Adder")
	static function Init() {
		var window = GetWindow(ScriptAdder);
		window.Show();
	}
	function Awake() {
		numComponents = EditorPrefs.GetInt("NumberOfComponents", 1);
		componentsToAdd = new MonoScript[numComponents];
	}
	function OnDestroy() {
	EditorPrefs.SetInt("NumberOfComponents", numComponents);
	}
	function OnGUI() {
		if(GUILayout.Button("Clear all components"))
			for(var c : MonoScript in componentsToAdd)
			c = null;
			EditorGUILayout.BeginHorizontal();
		if(GUILayout.Button("-")) IncreaseDecreaseComponents(-1);
			if(GUILayout.Button("+")) IncreaseDecreaseComponents(1);
				EditorGUILayout.EndHorizontal();

		for(var i = 0; i < numComponents; i++)
			componentsToAdd[i] =
			EditorGUILayout.ObjectField("Component", componentsToAdd[i], MonoScript);

		if(GUILayout.Button("Add to selection"))
			if(Selection.activeGameObject)
				for(var go : GameObject in Selection.gameObjects)
					for(var c : MonoScript in componentsToAdd)
						go.AddComponent(c.GetClass());
		}
	function IncreaseDecreaseComponents(num : int) {
		if(numComponents + num == 0) {
			numComponents = 1;
			return;
		}
		numComponents += num ;
		var newArray : MonoScript[] = new MonoScript[numComponents];
		var count = 0;
		if(num > 0)
			for(count = 0; count < componentsToAdd.Length; count++)
				newArray[count] = componentsToAdd[count];
		else
			for(count = 0; count < newArray.Length; count++)
				newArray[count] = componentsToAdd[count];
		componentsToAdd = newArray;
	}
}
最后修改:2011年7月11日 Monday 16:04

本脚本参考基于Unity 3.4.1f5

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