public static int GetInt (string key, int defaultValue= 0);

参数

key要从中读取整数的键的名称。
defaultValue当键不在存储中时返回的整数值。

返回

int 存储在偏好设置文件中的值。

描述

返回偏好设置文件中与 key 对应的值(如果存在)。

如果偏好设置文件中不存在此值,则函数将返回 /defaultValue/。

另请参阅:SetInt

// A small editor window that allows an integer value to be
// read and written to the EditorPrefs online storage.
//
// SetIntExample is the name of the int to read/write.

using UnityEngine; using UnityEditor;

public class ExampleClass : EditorWindow { int intValue = 42;

[MenuItem("Examples/Prefs.GetInt Example")] static void Init() { ExampleClass window = (ExampleClass)EditorWindow.GetWindow(typeof(ExampleClass)); window.Show(); }

void OnGUI() { int temp; temp = EditorPrefs.GetInt("SetIntExample", -1); EditorGUILayout.LabelField("Current stored value: " + temp.ToString()); intValue = EditorGUILayout.IntField("Value to write to Prefs: ", intValue); if (GUILayout.Button("Save value: " + intValue.ToString())) { EditorPrefs.SetInt("SetIntExample", intValue); Debug.Log("SetInt: " + intValue); } } }