公司小项目,经常要保存数据到本地,unity自带API PlayerPrefs只能简单的存储基本类型,因此找到这个比较好用的插件Easy Save
插件以及demo下载链接:https://download.csdn.net/download/dengshunhao/10765006
官网 : https://docs.moodkie.com/product/easy-save-3/
链接:https://docs.moodkie.com/easy-save-3/es3-guides/features/
1.保存及获取
ES3.Save / ES3.Load / ES3.LoadInto
Save and Load from Resources
Save and Load Strings and Bytes to File
3.加密
4.缓存
5.备份
6.保存并加载GameObjects和Prefab Instances
7.保存及加载图片、音频
8.File IO
Check if Key, File or Directory Exists
ES3.KeyExists / ES3.FileExists / ES3.DirectoryExists
Find Keys, Files and Directories
ES3.GetKeys / ES3.GetFiles / ES3.GetDirectories
Delete Keys, Files and Directories
Rename Files
Copy Files
Primitive types(原始类型)
Structs(结构体)
Enums(枚举)
Components/MonoBehaviours(组件)
ScriptableObjects
Non-abstract classes with a parameterless constructor(具有无参数构造函数的非抽象类)
Arrays, Lists, Dictionaries, Queues, Stacks and HashSets of supported types(数组、列表、字典、队列、堆栈和受支持类型的散列集)
Non-generic(非泛型)
Nice,我想要的都有了,特别喜欢Dictionariesn能存储,毕竟先前自己写转成List,再读取蛮麻烦的
修改默认设置:
这里面的属性也比较好理解,自己看看吧,工具也挺实用的
运行时修改:
最简单的保存方法允许您提供一个ES3Settings对象作为参数来覆盖默认设置。
只需创建一个新的ES3Settings对象,更改它的变量,并将其作为参数提供给您的方法调用,以在运行时覆盖默认设置。
// Create a new ES3Settings to enable encryption.
var settings = new ES3Settings(ES3.EncryptionType.AES, "myPassword");
// Change the save location to PlayerPrefs.
settings.saveLocation = ES3.Location.PlayerPrefs;
// Use the ES3Settings object to encrypt data and save to PlayerPrefs.
ES3.Save<Transform>("myTransform", this.transform, settings);
补充下参数说明:
属性 | 意义 |
---|---|
location | The storage location where we wish to store data by default. |
path | The path this ES3Settings object points to, if any. |
encryptionType | The type of encryption to use when encrypting data, if any. |
encryptionPassword | The password to use to encrypt the data if encryption is enabled. |
directory | The default directory in which to store files when using the File save location, and the location which relative paths should be relative to. |
format | The format we should use when serializing and deserializing data. |
bufferSize | Any stream buffers will be set to this length in bytes. |
encoding | What text encoding to use when writing and reading text from a file. |
键允许您将多个数据片段存储到同一个文件中。例如:
// These three values are stored to the default file.
ES3.Save<int>("myKey1", 1);
ES3.Save<int>("myKey2", 2);
ES3.Save<int>("myKey3", 3);
// These three values are stored to the file "myFile.es3".
ES3.Save<int>("myKey1", 1, "myFile.es3");
ES3.Save<int>("myKey2", 2, "myFile.es3");
ES3.Save<int>("myKey3", 3, "myFile.es3");
// These three values are stored to different files.
ES3.Save<int>("myKey1", 1);
ES3.Save<int>("myKey2", 2, "myFile.es3");
ES3.Save<int>("myKey3", 3, "anotherFile.es3");
如果一个文件已经包含了给定的键,文件中的值将被覆盖。例如:
// This adds the key "myKey" to the file with a value of '1'.
ES3.Save<int>("myKey", 1);
// This overwrites "myKey", so the value is now '2'.
ES3.Save<int>("myKey", 2);
// This overwrites "myKey" again, so the value is now '3'.
ES3.Save<int>("myKey", 3);
支持相对路径和绝对路径。如果文件或目录不存在,将创建它。
// Save a value to the default file in the default save location.
ES3.Save<int>("myKey", myValue);
// Save a value to a file named "myFile.es3" in the default save location.
ES3.Save<int>("myKey", myValue, "myFile.es3");
// Save a value to a file named "myFile.es3" in a sub-directory called "myFolder" in the default save location.
ES3.Save<int>("myKey", myValue, "myFolder/myFile.es3");
// Save a value to a file named "myFile.es3" in an absolute folder.绝对路径
ES3.Save<int>("myKey", myValue, "C:/Users/User/Documents/myFile.es3);
您可以在默认设置中指定存储位置,或者提供ES3Settings对象作为参数。
将数据存储到文件系统中的文件中。
默认的文件目录是Unity的应用程序。可以得到使用Debug.Log(Application.persistentDataPath)的精确位置。
您还可以选择使用应用程序。通过更改ES3Settings来使用dataPath。目录变量到ES3.Directory。DataPath,但只能保证可从编辑器写入。
文件在WebGL中不受支持,并且将自动默认为PlayerPrefs,不管位置设置为什么。
将数据存储在Unity的PlayerPrefs中,后者通常将数据存储在注册表或独立存储中。
这是为WebGL等平台提供的,这些平台不支持保存到文件,但是很少需要手动将保存位置设置为PlayerPrefs。
在WebGL中,PlayerPrefs有1MB的限制。
内存保存位置只能在特殊情况下使用,例如ES3File。
Easy Save目前支持AES加密,使用128位密钥,可以在默认设置中启用,也可以使用ES3Settings对象作为参数。
默认情况下,加密是禁用的。
由于导出限制,一些应用程序商店要求您声明正在使用加密。要了解更多相关信息,你应该联系相关的app store
// Create a new ES3Settings to enable encryption.
var settings = new ES3Settings(ES3.EncryptionType.AES, "myPassword");
// Use the ES3Settings object to encrypt data.
ES3.Save<Transform>("myTransform", this.transform, settings);
// Use the ES3Settings object to load and decrypt the data.
ES3.LoadInto<Transform>("myTransform, this.transform, settings");
Easy Save允许您使用ES3将字符串和字节直接保存到文件中。SaveRaw ES3.AppendRaw。
如果您想将数据写入文件,而文件的格式与容易保存的用途不同,那么这是非常有用的。
您还可以使用ES3以字符串或字节数组的形式读取文件。LoadRawString或ES3.LoadRawBytes。
保存:
// Create a string which represents three lines in a text file.
string myString = "Line1\nLine2\nLine3";
// Save the string as a file.
ES3.SaveRaw(myString, "myFile.txt");
// Append another line to the file.
ES3.AppendRaw("\nLine4", "myFile.txt");
// Now load the file back.
// This string will be "Line1\nLine2\nLine3\nLine4"
myString = ES3.LoadRawString("myFile.txt");
获取:
// Create some bytes which we wish to store to a file.
byte[] myBytes = GetBytes();
// Save the bytes as a file.
ES3.SaveRaw(myBytes, "myFile.bytes");
// Append more bytes to the file.
ES3.AppendRaw(GetMoreBytes(), "myFile.bytes");
// Now load the file back as a byte array.
myBytes = ES3.LoadRawBytes("myFile.bytes");
手动保存和加载gameobject:
// Save a GameObject.
ES3.Save<GameObject>("myGameObject", go);
// Load a GameObject, automatically assigning it to an existing
// GameObject if one exists, or create a new GameObject if not.
ES3.Load<GameObject>("myGameObject");
// Or we can choose what instance we load the data into.
ES3.LoadInto<GameObject>("myGameObject", go);
这将保存和加载以下内容:
手动保存和加载Prefabs:
有时候创建保存文件的备份是很有用的,例如,如果您希望在罕见的情况下恢复保存文件,比如由于硬件故障导致数据损坏,或者文件被篡改。
你可以用ES3来做这个。CreateBackup,胡状。还原备份以恢复备份。备份是通过复制文件并给它一个.bak扩展名来创建的。
如果备份已经存在,它将被覆盖,因此您需要确保在创建新备份之前不需要旧备份。
还要注意,恢复备份将覆盖它是备份的文件。
// Save some data and then make a backup.
ES3.Save<int>("myKey", "myFile.es3");
ES3.CreateBackup("myFile.es3");
try
{
myInt = ES3.Load<int>("myInt", "myFile.es3");
}
catch
{
if(ES3.RestoreBackup("myFile.es3"))
Debug.Log("Backup restored.");
else
Debug.Log("Backup could not be restored as no backup exists.");
}
使用ES3File缓存文件可以显著提高性能。这样做的好处是:
public class SaveLoadCache : MonoBehaviour
{
public static ES3File file;
public void Start()
{
// Create a new ES3File. This automatically loads
// the data from myFile.es3 into the ES3File.
file = new ES3File("myFile.es3");
}
public void OnApplicationQuit()
{
// Commit our ES3File to storage when the application quits.
file.Sync();
}
// We can call this method whenever we want to save.
public static void Save()
{
file.Save<string>("myName", this.name);
file.Save<Transform>("myTransform", transform);
}
// We can call this method whenever we want to load.
public static void Load()
{
this.name = file.Load<string>("myName", "defaultName");
// We can check whether a key exists in the ES3File before loading it.
if(file.KeyExists("myTransform"))
file.LoadInto<Transform>("myTransform", transform);
}
}
Image:
// Take a screenshot.
var texture = new Texture2D(Screen.width, Screen.height);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture.Apply();
// Save the screenshot as a PNG file.
ES3.SaveImage(texture, "screenshot.png");
// Save the screenshot as a JPG file.
ES3.SaveImage(texture, "screenshot.jpg");
// Load a Texture2D from a PNG file.
var texture = ES3.LoadImage("myImage.png");
// Apply the Texture2D to the material on this object.
GetComponent<Renderer>.material.mainTexture = texture;
// Get the bytes of a PNG file from an external cloud service.
byte[] bytes = CloudService.GetFileBytes("file.png");
// Turn these bytes into a Texture2D.
var texture = ES3.LoadImage(bytes);
audio:
加载:
MP3文件只支持移动设备,Ogg Vorbis文件只支持独立平台。
除了WebGL之外,所有平台都支持WAV、XM、IT、MOD和S3M文件。
由于此方法需要文件访问,所以WebGL不支持此方法。
如果文件不存在,将抛出FileNotFoundException。在这种情况下,您可以使用ES3。FileExists用于在加载前检查数据是否存在。
保存:
目前不可能将音频保存到压缩格式,因为Unity缺乏这样做所需的编码器。
但是,可以使用普通ES3以轻松保存的格式保存和加载AudioClip。保存并胡状。加载方法。由于数据未压缩,文件大小将大于压缩格式。
// Get the AudioSource we want to use to play our AudioClip.
var source = this.GetComponent<AudioSource>();
// Load an AudioClip from the streaming assets folder into our source.
source.clip = ES3.LoadAudio(Application.streamingAssetsPath + "/AudioFile.wav");
// Play the AudioClip we just loaded using our AudioSource.
source.Play();
// Get the AudioSource containing our AudioClip.
var source = this.GetComponent<AudioSource>();
// Save an AudioClip in Easy Save's uncompressed format.
ES3.Save<AudioClip>("myAudio", source.clip);
// Load the AudioClip back into the AudioSource and play it.
source.clip = ES3.Load<AudioClip>("myAudio");
source.Play();
Load:
要从资源加载,必须在默认设置中将位置设置为资源,或者使用ES3Settings对象。
文件必须具有扩展名.bytes,以便能够从参考资料中加载它
// Create an ES3Settings object to set the storage location to Resources.
var settings = new ES3Settings();
settings.location = ES3.Location.Resources;
// Load from a file called "myFile.bytes" in Resources.
var myValue = ES3.Load<Vector3>("myFile.bytes", settings);
// Load from a file called "myFile.bytes" in a subfolder of Resources.
var myValue = ES3.Load<Vector3>("myFolder/myFile.bytes");
Save:
Easy Save只能从编辑器中保存到Resources文件夹,因为在构建Unity应用程序时,Resources文件夹不存在。
如果希望将数据保存到资源中,以便稍后加载,则文件必须以扩展名.bytes结束。
要直接保存到资源,可以使用应用程序。获取路径的dataPath + “/Resources/”。但是,您需要退出Play模式并调用AssetDatabase.Refresh()或手动刷新项目才能从该文件加载。
或者,您可以将数据保存到您选择的文件夹中,然后将其拖放到Resources文件夹中。
ES3.Save<int>("myKey", 123, Application.dataPath+"/Resources/myFile.bytes");
AssetDatabase.Refresh();
ES3Type脚本告诉我们如何保存类型的字段和属性,以及如何保存它们。这可以自动创建,并在必要时进行修改。
一旦创建了脚本,Easy Save就会自动找到它,并使用它序列化和反序列化您的类型。您不需要创建ES3Type的实例。
创建一个ES3Type:
可以通过转到窗口> Easy Save 3来创建ES3Type,并选择Types选项卡。
从这里,您可以从列表中选择您的类型,并选择希望保存的字段和属性。
protected override void WriteComponent(object obj, ES3Writer writer)
{
var instance = (MyScript)obj;
writer.WriteProperty<int>("points", instance.points);
writer.WriteProperty<float>("speed", instance.speed);
writer.WriteProperty<Transform>("partner", instance.partner);
}
读:
protected override void ReadComponent<T>(ES3Reader reader, object obj)
{
var instance = (MyScript)obj;
foreach(string propertyName in reader.Properties)
{
switch(propertyName)
{
case "points":
instance.points = reader.Read<int>();
break;
case "speed":
instance.speed = reader.Read<float>();
break;
case "partner":
instance.partner = reader.Read<Transform>();
break;
default:
reader.Skip();
break;
}
}
}
有时需要将Easy Save的API与其他服务的存储API集成。例如,支持控制台,或与云存储插件集成。
这可以通过使用ES3File写入内存而不是本地存储,并以字节数组或字符串的形式检索ES3File的内容来实现。
以字符串或字节数组的形式保存:
// Create a new ES3File, providing a false parameter.
var es3file = new ES3File(false);
// Save your data to the ES3File.
es3File.Save<Transform>("myTransform", this.transform);
es3File.Save<string>("myName", myScript.name);
// etc ...
// Get the ES3File as a string.
string fileAsString = es3File.LoadRawString();
// Or get it as a byte array.
byte[] fileAsByteArray = es3File.LoadRawBytes().
从字符串或字节数组加载:
存储API应该允许您以字符串或字节数组的形式检索数据。
然后,可以将这个字符串或字节数组加载到ES3File中并从中读取。
// If we're loading from a byte array, simply provide it as a parameter.
var es3file = new ES3File(fileAsByteArray, false);
// If we're loading as a string, we need to convert it to a byte array first.
var es3file = new ES3File((new ES3Settings()).encoding.GetBytes(fileAsString), false);
// Load the data from the ES3File.
es3File.LoadInto<Transform>("myTransform", this.transform);
myScript.name = es3File.Load<string>("myName");
// etc ...
使用ES3Spreadsheet, Easy Save能够创建电子表格并以CSV格式存储,所有流行的电子表格软件都支持这种格式,包括Excel、OSX数字和OpenOffice。
Save:
var sheet = new ES3Spreadsheet();
// Add data to cells in the spreadsheet.
for(int col=0; col<10; col++)
for(int row=0; row<8; row++)
sheet.SetCell<string>(col, row, "someData");
sheet.Save("mySheet.csv");
如果要将数据追加到现有的电子表格,请将电子表格的追加变量设置为true。电子表格中的任何行都将被添加到保存到的行末尾。
Load:
// Create a blank ES3Spreadsheet.
var sheet = new ES3Spreadsheet();
sheet.Load("spreadsheet.csv");
// Output the first row of the spreadsheet to console.
for(int col=0; col<sheet.ColumnCount; col++)
Debug.Log(sheet.GetCell<int>(col, 0));
最新版的easySave3运行会报错,按照以下修改即可:
文章浏览阅读298次。import com.alibaba.fastjson.JSONArray;import com.alibaba.fastjson.JSONObject;import com.auth0.jwk.Jwk;import com.helijia.appuser.modules.user.vo.AppleCredential;import com.helijia.common.api.model.Api..._com.auth0.jwk.jwk
文章浏览阅读4.7k次。原理在叧掌握关于未知分布的部分信息的情况下,符合已知知识的概率分布可能有夗个,但使熵值最大的概率分布最真实地反映了事件的的分布情况,因为熵定义了随机变量的不确定性,弼熵值最大时,随机变量最不确定,最难预测其行为。最大熵模型介绍我们通过一个简单的例子来介绍最大熵概念。假设我们模拟一个翻译专家的决策过程,关于英文单词in到法语单词的翻译。我们的翻译决策模型p给每一个单词或短语分配一..._顺序潜在最大熵强化学习(maxent rl)
文章浏览阅读107次。计算机毕业设计ssm科研成果管理系统p57gs系统+程序+源码+lw+远程部署。springboot基于springboot的影视资讯管理系统。ssm基于SSM高校教师个人主页网站的设计与实现。ssm基于JAVA的求职招聘网站的设计与实现。springboot校园头条新闻管理系统。ssm基于SSM框架的毕业生离校管理系统。ssm预装箱式净水站可视化信息管理系统。ssm基于SSM的网络饮品销售管理系统。
文章浏览阅读1.6w次。不知道大家有没有遇到过与我类似的报错情况,今天发生了此错误后就黏贴复制了报错信息“Caused by: org.xml.sax.SAXParseException; lineNumber: 38; columnNumber: 9; cvc-complex-type.2.3: 元素 'beans' 必须不含字符 [子级], 因为该类型的内容类型为“仅元素”。”然后就是一顿的百度啊, 可一直都没有找到..._saxparseexception; linenumber: 35; columnnumber: 9; cvc-complex-type.2.3:
文章浏览阅读156次。(通讯员 粟坤萍 2018-04-19)4月19日,湖北师范大学计算机科学与技术学院于教育大楼学院会议室1110成功召开大学生创新创业工作会议。参与本次会议的人员有党总支副书记黄海军老师,创新创业学院吴杉老师,计算机科学与技术学院创新创业活动指导老师,15、16、17级各班班主任及学生代表。首先吴杉老师介绍了“互联网+”全国大学生创新创业大赛的相关工作进度,动员各级班主任充分做好“大学生创新创业大..._湖北师范 吴杉
文章浏览阅读1.1w次,点赞69次,收藏76次。安卓逆向技术是一门深奥且充满挑战的领域。通过本文的介绍,我们了解了安卓逆向的基本概念、常用工具、进阶技术以及实战案例分析。然而,逆向工程的世界仍然在不断发展和变化,新的技术和方法不断涌现。展望未来,随着安卓系统的不断更新和加固,逆向工程将面临更大的挑战。同时,随着人工智能和机器学习技术的发展,我们也许能够看到更智能、更高效的逆向工具和方法的出现。由于篇幅限制,本文仅对安卓逆向技术进行了介绍和案例分析。
文章浏览阅读1.1k次。制作饼图还需要下载pyecharts库,Echarts 是一个由百度开源的数据可视化,凭借着良好的交互性,精巧的图表设计,得到了众多开发者的认可。随着学习python的热潮不断增加,Python数据可视化也不停的被使用,那我今天就介绍一下Python数据可视化中的饼图。在我们的生活和学习中,编程是一项非常有用的技能,能够丰富我们的视野,为各行各业的领域提供了新的角度。环形饼图的制作并不难,主要是在于数据的打包和分组这里会有点问题,属性的标签可以去 这个网站进行修改。图中的zip压缩函数,并分组打包。_数据可视化绘制饼图或圆环图
文章浏览阅读325次。1 Spring MVC注解类型Controller和RequestMapping注释类型是SpringMVC API最重要的两个注释类型。基于注解的控制器的几个优点:一个控制器类可以控制几个动作,而一个实现了Controller接口的控制器只能处理一个动作。这就允许将相关操作写在一个控制器类内,从而减少应用类的数量基于注解的控制器的请求映射不需要存储在配置文件中,而是使用RequestM..._jsp/servlet到controller到基于注解的控制器
文章浏览阅读260次,点赞3次,收藏4次。相位裕量可以从增益图中的交越频率处读取(参见图2)。使用的开关频率、选择的外部元件(例如电感和输出电容),以及各自的工作条件(例如输入电压、输出电压和负载电流)都会产生巨大影响。图2所示为波特图中控制环路的增益曲线,其中提供了两条重要信息。对于图2所示的控制环路,这个所谓的交越频率出现在约80 kHz处。通过使用波特图,您可以查看控制环路的速度,特别是其调节稳定性。图2. 显示控制环路增益的波特图(约80 kHz时,达到0 dB交越点)。图3. 控制环路的相位曲线,相位裕量为60°。
文章浏览阅读1.8k次。Error: `_obstack@GLIBC_2.2.5’ can’t be versioned to common symbol '_obstack_compat’原因:https://www.lordaro.co.uk/posts/2018-08-26-compiling-glibc.htmlThis was another issue relating to the newer binutils install. Turns out that all was needed was to initi_`_obstack@glibc_2.2.5' can't be versioned to common symbol '_obstack_compat
文章浏览阅读3k次。基于javaweb+mysql的电影院售票购票电影票管理系统(前台、后台)运行环境Java≥8、MySQL≥5.7开发工具eclipse/idea/myeclipse/sts等均可配置运行适用课程设计,大作业,毕业设计,项目练习,学习演示等功能说明前台用户:查看电影列表、查看排版、选座购票、查看个人信息后台管理员:管理电影排版,活动,会员,退票,影院,统计等前台:后台:技术框架_电影售票系统javaweb
文章浏览阅读95次。分分钟拯救监控知识体系本文出自:http://liangweilinux.blog.51cto.com0 监控目标我们先来了解什么是监控,监控的重要性以及监控的目标,当然每个人所在的行业不同、公司不同、业务不同、岗位不同、对监控的理解也不同,但是我们需要注意,监控是需要站在公司的业务角度去考虑,而不是针对某个监控技术的使用。监控目标1.对系统不间断实时监控:实际上是对系统不间..._不属于监控目标范畴的是 实时反馈系统当前状态