Unity Manual之PlayerPrefs 游戏存档
2015-08-07 01:43
633 查看
Unity Manual之PlayerPrefs 游戏存档
Description 描述在游戏会话中储存和访问游戏存档。这个是持久化数据储存,比如保存游戏记录。
Editor/Standalone 编辑器 / 桌面平台
Mac OS
在Mac OS X上PlayerPrefs是存储在~/Library/Preferences文件夹,名为unity.[company name].[product name].plist,其中company name和product name名是在Project Setting中设置,.plist文件可用于编辑器和桌面平台运行。
Windows
在Windows平台下,PlayerPrefs被存储在注册表的 HKEY_CURRENT_USER\Software\[company name]\[product name]键下,其中company name和product name名是在Project Setting中设置。
Linux
在Linux,PlayerPrefs是储存在~/.config/unity3d/[CompanyName]/[ProductName]。其中CompanyName和ProductName名是在Project Setting中设置
Windows Store
在Windows Store,PlayerPrefs是储存在%userprofile%\AppData\Local\Packages\[ProductPackageId]>\LocalState\playerprefs.dat。
Windows Phone
在Windows Phone 8,PlayerPrefs是储存在应用自己的文件夹,参见:Windows.Directory.localFolder
WebPlayer 网页
在网页平台,PlayerPrefs是储存在二进制文件,看下面的对应的各平台位置:
Mac OS X: ~/Library/Preferences/Unity/WebPlayerPrefs
Windows: %APPDATA%\Unity\WebPlayerPrefs
一个游戏存档文件对应一个web播放器URL并且文件大小被限制为1MB。如果超出这个限制,SetInt、SetFloat和SetString将不会存储值并抛出一个PlayerPrefsException异常。
1、PlayerPrefs.SetInt 设置整数
设置由key键确定的整数值。
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Example() { PlayerPrefs.SetInt("Player Score", 10); } }
2、PlayerPrefs.SetString 设置字符串
设置由key确定的字符串值。
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Example() { PlayerPrefs.SetString("Player Name", "Foobar"); } }
相关文章推荐
- Unity Manual之Transform 变换
- Unity Manual之MonoBehaviour
- Unity Manual之CharacterController 角色控制器
- Unity Manual之Component 组件
- Unity Manual之GameObject 游戏对象
- Unity解决脚本之间相互调用的几种方法
- Unity获取游戏对象详解
- Unity常用插件
- unity GL画线
- Unity3D避免玩家作弊
- Unity (三)
- unity3d 学习笔记(两)
- Unity3D EasyTouch使用教程包括实例资源
- unity AssetBundle的资源管理
- 通过Unity依赖注入
- 解决 unity 用 vs通过wifi 真机联调 一直连接不上
- unity, audio falloff
- unity 摄像头
- 【Unity】2D动画控制器详解
- Unity 2D动画控制器详解