欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

android+unity3D实现数据的存取(PlayerPrefs)

来源: 开发者 投稿于  被查看 15226 次 评论:162

android+unity3D实现数据的存取(PlayerPrefs)


 

我们先来看看PlayerPrefs的API吧,

\

 

我来解释一下,

 

 

SetInt是保存一个值PlayerPrefs.SetInt("Player Score",10);,

GetInt是读取一个值PlayerPrefs.GetInt("Player Score"),他们就是一对啦,作为整形的存取。

顾名思义,SetFloat和GetFloat为浮点型的存取,SetString和GetString是字符型的存取;

 

HasKey是指如果存有这个数,返回值就是true,反之,false;PlayerPrefs.HasKey("Player Score");

DeleteKey就是指删除这个数,PlayerPrefs.DeleteKey("Player Score");

DeleteAll就是删除所有数啦,PlayerPrefs.DeleteAll();

 

那下面我们来个简单的练习吧,

    pref2.cs

 

using UnityEngine; 

using System.Collections; 

 

public class pref2 : MonoBehaviour { 

 

    // Use this for initialization 

    void Start () { 

        PlayerPrefs.SetInt("Player Score",10); 

        print (PlayerPrefs.GetInt("Player Score")+"---"+PlayerPrefs.HasKey("Player Score")); 

        PlayerPrefs.DeleteKey("Player Score"); 

        print(PlayerPrefs.GetInt("Player Score")); 

    } 

     

    // Update is called once per frame 

    void Update () { 

     

    } 

 

 \

 

摘自 dlnuchunge的专栏

相关文章

    暂无相关文章

用户评论