Version: 2021.3
public static void DeleteKey (string key);

描述

从偏好中删除 key 及其对应值。

\ 删除用户输入的编辑器偏好设置,如果不存在,则会打印一条消息。

// Removes a user entered editor preference.
// If it does not exists it prints a message.

using UnityEngine; using UnityEditor;

public class DeleteKeyExample : EditorWindow { string editorPref = "";

[MenuItem("Examples/EditorPrefs/Clear Key Preference")] static void Init() { DeleteKeyExample window = GetWindowWithRect<DeleteKeyExample>(new Rect(0, 0, 250, 50)); window.Show(); }

void OnGUI() { editorPref = EditorGUILayout.TextField("Editor key name:", editorPref); if (GUILayout.Button("Delete")) if (EditorPrefs.HasKey(editorPref)) { if (EditorUtility.DisplayDialog("Removing " + editorPref + "?", "Are you sure you want to " + "delete the editor key " + editorPref + "?, This action cant be undone", "Yes", "No")) EditorPrefs.DeleteKey(editorPref); } else { EditorUtility.DisplayDialog("Could not find " + editorPref, "Seems that " + editorPref + " does not exists or it has been deleted already, " + "check that you have typed correctly the name of the key.", "Ok"); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961