EditorPrefs.SetFloat 设置浮点数

static function SetFloat (key : string, value : float) : void

Description描述

Sets the value of the preference identified by key.

设置由键确定的偏好值。

// Simple scripts that creates an empty window and remembers the position and size
// of the created window.
//创建一个空的窗口并记住位置和大小
class RememberPosition extends EditorWindow {
	var width : float = 300;
	var height : float = 300;
	var x : float = 100;
	var y : float = 100;

	@MenuItem("Examples/Remember position")
	static function Init() {
		var window = GetWindow(RememberPosition);
		window.Show();
	}
	function Awake() {
		width = EditorPrefs.GetFloat("EditorWindowWidth", 300);
		height = EditorPrefs.GetFloat("EditorWindowHeight", 300);
		x = EditorPrefs.GetFloat("EditorWindowX", 100);
		y = EditorPrefs.GetFloat("EditorWindowY", 100);

		position = Rect(x, y, width, height);
	}
	function OnDestroy() {
		EditorPrefs.SetFloat("EditorWindowWidth", width);
		EditorPrefs.SetFloat("EditorWindowHeight", height);
		EditorPrefs.SetFloat("EditorWindowX", x);
		EditorPrefs.SetFloat("EditorWindowY", y);
	}
	function OnGUI() {
		if(GUILayout.Button("Close"))
			this.Close();
	}
}
最后修改:2011年7月11日 Monday 16:29

本脚本参考基于Unity 3.4.1f5

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