Skip to content

PlayerPrefs (JavaScript)

PlayerPrefs

Scripting Name:Insight.PlayerPrefs

数据持久化,用于记录简单配置信息。

  • _在 Web _SDK__中无效

Static Methods


DeleteAll

javascript
static DeleteAll(): void;

删除所有项。

DeleteKey

javascript
static void DeleteKey(key: string): void;

删除指定一项。

Parameters

  • key: string 该项对应的 key

GetFloat

javascript
static GetFloat(key: string): float;

读取一个 float 项,如果未找到则返回 0。

Parameters

  • key : string 该项对应的 key

GetFloat

javascript
static GetFloat(key: string, defaultValue: number): float;

读取一个 float 项,如果未找到则返回默认值。

Parameters

  • key : string 该项对应的 key
  • defaultValue : number 未找到时的默认值

GetInt

javascript
static GetInt(key: string): int;

读取一个 int 项,如果未找到则返回 0。

Parameters

  • key : string 该项对应的 key

GetInt

javascript
static GetInt(key: string, defaultValue: number): int;

读取一个 int 项,如果未找到则返回默认值。

Parameters

  • key : string 该项对应的 key
  • defaultValue : number 未找到时的默认值

GetString

javascript
static GetString(key: string): string;

读取一个 string 项,如果未找到则返回 0。

Parameters

  • key : string 该项对应的 key

GetString

javascript
static GetString(key: string, defaultValue: number): string;

读取一个 string 项,如果未找到则返回默认值。

Parameters

  • key : string 该项对应的 key
  • defaultValue : number 未找到时的默认值

HasKey

javascript
static Haskey(key: string): boolean;

是否存在指定项。

Parameters

  • key : string 该项对应的 key

Save

javascript
static Save(): boolean;

保存设置。

SetFloat

javascript
static SetFloat(key: string, value: number): void;

设置或创建一个 float 项。

Parameters

  • key : string 该项对应的 key
  • value : number float 值

SetInt

javascript
static SetInt(key: string, value: number): void;

设置或创建一个 int 项。

Parameters

  • key : string 该项对应的 key
  • value : number int 值

SetString

javascript
static SetString(key: string, value: string): void;

设置或创建一个字符串。

Parameters

  • key : string 该项对应的 key
  • value : string 字符串的值