PlayerPrefs使用
来源:互联网 发布:网络信息安全认证 编辑:程序博客网 时间:2024/06/16 02:01
其实官方文档已经说得很明确很明确了,抄写一遍:
相关信息存放的具体位置:
On Mac OS X PlayerPrefs are stored in ~/Library/Preferences folder, in a file namedunity.[company name].[product name].plist, where company and product names are the names set up in Project Settings. The same .plist file is used for both Projects run in the Editor and standalone players.
On Windows, PlayerPrefs are stored in the registry underHKCU\Software\[company name]\[product name] key, where company and product names are the names set up in Project Settings.
On Linux, PlayerPrefs can be found in ~/.config/unity3d/[CompanyName]/[ProductName]again using the company and product names specified in the Project Settings.
On Windows Store Apps, Player Prefs can be found in %userprofile%\AppData\Local\Packages\[ProductPackageId]>\LocalState\playerprefs.dat
On Windows Phone 8, Player Prefs can be found in application's local folder
On Android data is stored (persisted) on the device. The data is saved in SharerPreferences. C#/JavaScript, Android Java and Native code can all access the PlayerPrefs data. The PlayerPrefs data is physically stored in /data/data/pkg-name/shared_prefs/pkg-name.xml.
On WebGL, PlayerPrefs are stored using the browser's IndexedDB API.
常用的方法
DeleteAllRemoves all keys and values from the preferences. Use with caution.
DeleteKey Removes key and its corresponding value from the preferences.
GetFloat Returns the value corresponding to key in the preference file if it exists.
public static float GetFloat(string key, float defaultValue = 0.0F);Returns the value corresponding to key in the preference file if it exists.
If it doesn't exist, it will return defaultValue.
如果key存在,返回key对应的值;如果不存在,返回默认值。
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour { void Example() { print(PlayerPrefs.GetFloat("Player Score")); }}
GetInt Returns the value corresponding to key in the preference file if it exists.
GetString Returns the value corresponding to key in the preference file if it exists.
HasKey Returns true if key exists in the preferences.
Save Writes all modified preferences to disk.
Writes all modified preferences to disk.
By default Unity writes preferences to disk during OnApplicationQuit(). In cases when the game crashes or otherwise prematuraly exits, you might want to write the PlayerPrefs at sensible 'checkpoints' in your game. This function will write to disk potentially causing a small hiccup, therefore it is not recommended to call during actual gameplay.
Note: There is no need to call this function manually inside OnApplicationQuit().
Note: On Windows Store Apps and Windows Phone 8.1 preferences are saved during application suspend, because there's no application quit event.
默认情况下在OnApplicationQuit()里unity会自动调用该方法,所以没必要在去手动调用;当然了,为了防止游戏崩溃却没有存档,你可以在游戏的“存盘点”处使用该方法。由于在存盘的时候会引起小卡顿,所以通常不建议在游戏时调用。
而在Windows Store Apps 和 Windows Phone 8.1上是在挂起的时候调用,因为这两者没有application quit详情点这里
SetFloatSets the value of the preference identified by key.
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour { void Example() { PlayerPrefs.SetFloat("Player Score", 10.0F); }}SetIntSets the value of the preference identified by key.
SetString Sets the value of the preference identified by key.
- PlayerPrefs使用
- PlayerPrefs使用
- Unity3D PlayerPrefs的使用
- PlayerPrefs的使用
- 使用PlayerPrefs执行高分排行榜
- Unity3d使用PlayerPrefs类实现数据存档
- Unity3d(PlayerPrefs 类的介绍与使用)
- [Unity&]PlayerPrefs.GetString的使用案例
- Unity3D游戏开发之数据持久化PlayerPrefs的使用
- [懒癌初期]Unity中PlayerPrefs的使用
- Unity3D游戏开发之数据持久化PlayerPrefs的使用
- PlayerPrefs类
- PlayerPrefs学习
- unity3d PlayerPrefs
- 封装PlayerPrefs
- [Unity3D]Unity3D游戏开发之数据持久化PlayerPrefs的使用
- Unity 3D--PlayerPrefs
- Unity PlayerPrefs 存储字段
- 【3D Slicer 从零开始】(一)安装和配置
- 8.28 考试第二题(DP + 矩阵快速幂)
- BVT测试与冒烟测试
- Android“保存ArrayList到本地”并”获取显示“(结合SharedPreferences)
- vxworks中vxbus使用入门
- PlayerPrefs使用
- 九九乘法表
- Echarts学习笔记
- valgrind内存泄漏检测详解
- Windows手动删除服务列表中残留服务的方法
- 2016年暑假总结
- 聊天界面之ListView
- 《Google C++ 编程风格指南》对于头文件的包含顺序
- linux常用环境变量和c/c++头文件/库路径环境变量