unity 游戏存档
来源:互联网 发布:网络上流行的英文歌曲 编辑:程序博客网 时间:2024/05/29 07:59
对于简单的存档,可以利用Playerpref永久保存,通过保存游戏角色的位置来实现,然后当点击继续游戏时通过start初始化得到保存的数据,重新开始游戏则不读取数据。大体思路如下:界面上有退出游戏按钮,点击时弹出窗口,有保存和不保存两个按钮,如下所示
function windowsave()
{
if(GUILayout.Button("保存"))
{ cls=false;
//由于只能保存int,string,float型,所以将坐标分开保存
PlayerPrefs.SetFloat("str1",transform.position.x);
PlayerPrefs.SetFloat("str2",transform.position.y);
PlayerPrefs.SetFloat("str3",transform.position.z);
PlayerPrefs.SetInt("str5",PlayerPrefs.GetInt("str4"));
}
if(GUILayout.Button("不保存"))
{ cls=false;
}
}
同时在start函数写下如下:
function Start ()
{
if(PlayerPrefs.GetInt("state"))
{
transform.position = Vector3(PlayerPrefs.GetFloat("str1"),PlayerPrefs.GetFloat("str2"),PlayerPrefs.GetFloat("str3"));
}
}
unity圣典上面介绍如下:
在游戏会话中储存和访问游戏存档。
可以理解为持久化储存,还可以理解为游戏存档, 玩RPG游戏的时候肯定会有游戏存档 存档中就会记录玩家以前游戏的过程,这些都是以数据的形式存在PlayerPrefs中的。
在Web模式,PlayerPrefs存储在Mac OS X的二进制文件 ~/Library/Preferences/Unity/WebPlayerPrefs中和Windows的 %APPDATA%\Unity\WebPlayerPrefs中,一个游戏存档文件对应一个web播放器URL并且文件大小被限制为1MB。如果超出这个限制,SetInt、SetFloat和SetString将不会存储值并抛出一个PlayerPrefsException。
Class Functions类函数
- SetIntSets the value of the preference identified by key.
设置由key确定的参数值。 - GetIntReturns the value corresponding to key in the preference file if it exists.
如果存在,返回偏好文件中key对应的值。 - SetFloatSets the value of the preference identified by key.
设置由key确定的参数值。 - GetFloatReturns the value corresponding to key in the preference file if it exists.
如果存在,返回游戏存档文件中key对应的值。 - SetStringSets the value of the preference identified by key.
设置由key确定的参数值。 - GetStringReturns the value corresponding to key in the preference file if it exists.
如果存在,返回游戏存档文件中key对应的值。 - HasKeyReturns true if key exists in the preferences.
如果key在游戏存档中存在,返回true。 - DeleteKeyRemoves key and its corresponding value from the preferences.
从游戏存档中删除key和它对应的值。 - DeleteAllRemoves all keys and values from the preferences. Use with caution.
从偏好中删除所有key。请谨慎使用。 - SaveWrites all modified preferences to disk.
写入所有修改参数到硬盘。
- unity 游戏存档
- Unity PlayerPrefs 游戏存档
- Unity游戏存档-PlayerPrefs类
- Unity Manual之PlayerPrefs 游戏存档
- Unity 游戏存档之XML实现
- Unity 游戏存档 PlayerPrefs类的用法
- Unity 游戏存档 PlayerPrefs类的用法
- Unity 游戏存档 PlayerPrefs类的用法
- unity日常——游戏存档
- 游戏存档
- unity学习笔记(一) 游戏存档Playerprebs
- unity随笔_unity存档
- Cocos2d-x 游戏存档
- 游戏数据存档CCUserDefault
- PlayerPrefs 游戏存档
- PlayerPrefs 游戏存档
- unity3d--PlayerPrefs 游戏存档
- Untiy 游戏存档PlayerPrefs
- Chromium本地化的方法
- 用C#根据经纬度求两点间距离的函数代码
- poj1003
- Uninstall VLC media player with WindowsUninstaller.Org Removal Tips
- 学习OpenCV 3.1.a 习题解答
- unity 游戏存档
- VS中Tab Control用法
- OpenCV1.1无法读视频文件的解决方法
- chrome UI 学习笔记3--国际化 (转)
- Linux curses库使用
- 数组排序 --- 庞果
- 一些小工具方法,能将容器转换成指定的数组类型有使用泛型
- Log4cpp使用
- jQuery验证控件jquery.validate.js使用说明+中文API