Day 16. Unity: 来学Implement data persistence between sessions

:D
 
 
这个部分的概念,其实跟把训练好的模型还有过程的Loss value、Metrics value储存下来很像呢,只是我现在要学习的是在Unity这个软件中,要怎麽实现它才比较好呢?

会学到:

  • 在启动时载入资料
  • 适用的资料结构
  • 在结束时储存资料

在开始之前,我对这些问题的回答是:

What do you need to implement, and where will you implement it ? Write down your thoughts now, to compare them with the approach we take.

因为是要储存使用者最後所选的颜色,可以建立一个档案,所以我猜是在MainManager.cs里新增一个Start(),在开始时即从档案载入资料,然後应该也可以新增一个End(),让他在结束时写入资料。
 
 

Where have you encountered similar functionality before, in Create with Code or other learning experiences? Even if you can’t access the code, think about examples of data persistence between sessions that you’re familiar with.

嘛,我也只有在训练模型时,要在epoch结束时储存模型资讯之类的东西做过而已。
 
 

Beyond Unity Learn, what resources could help you do this? Think about options within the Unity ecosystem and beyond it.

Unity ecosystem??? 不知道这个是什麽,跳过。

 
 
 

好的,开始上课做笔记

OK,这次要用来储存的资料格式是JSON,就是副档名是.json的那个。

using JsonUtility;

所以今天新学了JsonUtility的用法啦,他是可以把程序中的class instance,快速转成对应的json档案。

 
 
...
 
 
比我想像的复杂许多:

把要打包的资料写成一个class,然後针对这个class写save()跟load() method(这里是用JsonUtility完成)。

然後不需要在MainManager新增Start(),在原本的Awake()底下load()就好。
 
 

此外,为了让使用者能具体看到储存的资料,所以在画面上也要显示之前储存的颜色是什麽,以及目前切换的颜色是什麽。这里就需要一起调整Menu场景中UIHandler.cs的程序,让他在目前使用的颜色打勾。

这边的话,就是调用MainManager下的save()跟load()。

 
 

参考:
https://learn.unity.com/tutorial/implement-data-persistence-between-sessions?uv=2020.3&missionId=5f751af7edbc2a0022cdbbb6#60b747c4edbc2a5532d133d2


<<:  【D17】杂谈:版本与Github找不到资料

>>:  Day16- 让页面不再被上下左右上下左右

Day4- Java语言编译器:javac & 运行工具:java (上)

前言 个人在学习java程序时,一开始对於Java如何编译以及执行编译档这块知识很模糊,如何运作的完...

[DAY 30] 章节3-10: 晨晓之始-继续统计旅程

3-10 晨晓之始 半夜4:30天还未亮,茉姨便拿着提灯到两人房间叫醒二人,飞哥与小博匆匆起床洗漱後...

SCPM requires Internet Explorer,version 5.5 or 6.x

IE Web 网站执行时产生问题! 它让我马上用google大神找到了答案---打开 IE-->...

Day2:How to use comments,octothorpe and variable in Python

Comment is a very important part in programing Com...

#3 CSS Introduction x Foodie

What is CSS? English: CSS = Cascading Stylesheets ...