PreviewLabs是一款用来提升手机运行速度的插件,插件使用很简单,新建一个名为PlayerPrefs.cs的C#脚本,源码如下:
/*
PreviewLabs.PlayerPrefs
Public Domain
To the extent possible under law, PreviewLabs has waived all copyright and related or neighboring rights to this document. This work is published from: Belgium.
http://www.previewlabs.com
*/
using UnityEngine;
using System;
using System.Collections;
using System.IO;
using System.Text.RegularExpressions;
namespace PreviewLabs
{
public static class PlayerPrefs
{
private static Hashtable playerPrefsHashtable = new Hashtable();
private static bool hashTableChanged = false;
private static string serializedOutput = "";
private static string serializedInput = "";
private const string PARAMETERS_SEPERATOR = ";";
private const string KEY_VALUE_SEPERATOR = ":";
private static readonly string fileName = Application.persistentDataPath + "/PlayerPrefs.txt";
static PlayerPrefs()
{
//load previous settings
StreamReader fileReader = null;
if (File.Exists(fileName))
{
fileReader = new StreamReader(fileName);
serializedInput = fileReader.ReadLine();
Deserialize();
fileReader.Close();
}
}
public static bool HasKey(string key)
{
return playerPrefsHashtable.ContainsKey(key);
}
public static void SetString(string key, string value)
{
if(!playerPrefsHashtable.ContainsKey(key))
{
playerPrefsHashtable.Add(key, value);
}
else
{
playerPrefsHashtable[key] = value;
}