Version: 2017.3
public static void SetInt (string key, int value);

参数

key 要在其中写入整数的键的名称。
value 要写入存储的整数的值。

描述

将由键标识的偏好设置的值设置为整数。

将由 key 标识的偏好设置的值设置为整数。

另请参阅:GetInt

// 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.SetInt 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); } } }