Unity入门操作_PlayerPrefs存储_037

来源:互联网 发布:ios10越狱软件源 编辑:程序博客网 时间:2024/06/16 19:03

任何前端都会有临时存储的机制,PlayerPrefs存储机制保密性差,所以一般情况下用在单机游戏存储。
static function DeleteAll(): void
描述:从设置文件中移除所有键和值,谨慎的使用它们。

static function DeleteKey(key: string): void
描述:从设置文件中移除key和它对应的值。

static function GetFloat(key: string, defaultValue: float=OF): float
描述:如果存在,返回设置文件中key对应的值.如果不存在,它将返回defaultValue。

static function GetInt(key: string, defaultValue: int): int
描述:返回设置文件中key对应的值,如果存在.如果不存在,它将返回defaultValue。

static function GetString(key: string, defaultValue: string=**): string
描述:返回设置文件中key对应的值,如果存在.如果不存在,它将返回defaultValue.

static function HasKey(key: string): bool
描述:在设置文件如果存在key则返回真.

static function SetFloat(key: string, value: float): void
描述:设置由key确定的值.

static function SetInt(key: string, value: int): void
描述:设置由key确定的值.

static function SetString(key: string, value: string): void
描述:设置由key确定的值.

using UnityEngine;
using System.Collections;
public class Test01 : MonoBehaviour {

// Use this for initializationvoid Start () {    if (PlayerPrefs.HasKey("aa"))    {        Debug.Log(PlayerPrefs.GetString("aa"));    }    else    {        Debug.Log("不存在");        PlayerPrefs.SetString("aa","100");    }  }// Update is called once per framevoid Update () {}

}

namespace UnityEngine
{

//// 摘要://     /////     Stores and accesses player preferences between game sessions.//     ///public sealed class PlayerPrefs{    public PlayerPrefs();    //    // 摘要:    //     ///    //     Removes all keys and values from the preferences. Use with caution.    //     ///    [WrapperlessIcall]    public static void DeleteAll();    //    // 摘要:    //     ///    //     Removes key and its corresponding value from the preferences.    //     ///    //    // 参数:    //   key:    [WrapperlessIcall]    public static void DeleteKey(string key);    //    // 摘要:    //     ///    //     Returns the value corresponding to key in the preference file if it exists.    //     ///    //    // 参数:    //   key:    //    //   defaultValue:    [ExcludeFromDocs]    public static float GetFloat(string key);    //    // 摘要:    //     ///    //     Returns the value corresponding to key in the preference file if it exists.    //     ///    //    // 参数:    //   key:    //    //   defaultValue:    [WrapperlessIcall]    public static float GetFloat(string key, [DefaultValue("0.0F")] float defaultValue);    //    // 摘要:    //     ///    //     Returns the value corresponding to key in the preference file if it exists.    //     ///    //    // 参数:    //   key:    //    //   defaultValue:    [ExcludeFromDocs]    public static int GetInt(string key);    //    // 摘要:    //     ///    //     Returns the value corresponding to key in the preference file if it exists.    //     ///    //    // 参数:    //   key:    //    //   defaultValue:    [WrapperlessIcall]    public static int GetInt(string key, [DefaultValue("0")] int defaultValue);    //    // 摘要:    //     ///    //     Returns the value corresponding to key in the preference file if it exists.    //     ///    //    // 参数:    //   key:    //    //   defaultValue:    [ExcludeFromDocs]    public static string GetString(string key);    //    // 摘要:    //     ///    //     Returns the value corresponding to key in the preference file if it exists.    //     ///    //    // 参数:    //   key:    //    //   defaultValue:    [WrapperlessIcall]    public static string GetString(string key, [DefaultValue("\"\"")] string defaultValue);    //    // 摘要:    //     ///    //     Returns true if key exists in the preferences.    //     ///    //    // 参数:    //   key:    [WrapperlessIcall]    public static bool HasKey(string key);    //    // 摘要:    //     ///    //     Writes all modified preferences to disk.    //     ///    [WrapperlessIcall]    public static void Save();    //    // 摘要:    //     ///    //     Sets the value of the preference identified by key.    //     ///    //    // 参数:    //   key:    //    //   value:    public static void SetFloat(string key, float value);    //    // 摘要:    //     ///    //     Sets the value of the preference identified by key.    //     ///    //    // 参数:    //   key:    //    //   value:    public static void SetInt(string key, int value);    //    // 摘要:    //     ///    //     Sets the value of the preference identified by key.    //     ///    //    // 参数:    //   key:    //    //   value:    public static void SetString(string key, string value);}

}

原创粉丝点击