Version: 2022.3

PlayerPrefsException

class in UnityEngine

切换到手册

描述

PlayerPrefs 类在 Web 播放器构建中抛出的异常。

当对偏好设置文件进行的写入超过分配的存储空间时,会抛出该异常。在其他平台上不会抛出此异常。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Start() { // create a one megabyte character string string s16 = "0123456789abcdef"; string s1024 = ""; for (int j = 0; j < 64; j++) s1024 += s16; string s1024x1024 = ""; for (int i = 0; i < 1024; i++) s1024x1024 += s1024;

// try to save the string try { PlayerPrefs.SetString("fail", s1024x1024); } // handle the error catch (System.Exception err) { Debug.Log("Got: " + err); } } }

请注意,5.4.0 及更高版本不支持 Web 播放器。