我是否必须使用onPause/onStart/onDestroy [英] Do I have to use onPause/onStart/onDestroy

查看:104
本文介绍了我是否必须使用onPause/onStart/onDestroy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Unity中开发一款移动益智游戏,当我将游戏退出到主屏幕并返回时,该游戏从同一位置继续进行,这似乎还不错(不重写onPause/onStart),对吗?遗漏了什么?退出时是否需要存储变量?人们通常会保存什么?恐怕将来会出现错误.

I'm developing a mobile puzzle game in Unity, when I exit my game to the home screen and return back- the game continues from the same spot and it seems to be fine (without overriding onPause/onStart), am I missing something? Do I need to store variables when exit? What do people usually save? I'm afraid to have bugs in the future.

推荐答案

我想念东西吗?

I missing something?

退出时是否需要存储变量?

Do I need to store variables when exit?

恐怕将来会出现错误.

I'm afraid to have bugs in the future.

是的,你会的.您将遇到丢失变量的问题.您有责任执行此操作.仅仅因为现在看起来一切正常,并不意味着什么.在不同的平台和设备上,行为是不同的,并且还取决于在后台+当前可用RAM上已经运行了多少个应用程序.通常,您使用一个类将所有重要变量存储在您的类中,然后序列化并保存它们.

Yes, you will. You will run into lost variables issues. It is your responsibly to implement this. Just because everything looks and works fine now doesn't mean anything. The behavior is different on different platforms and devices and also depends on how many apps are already running on the background + current available ram. Usually, you use a class to store all important variables in your class then serialize and save them.

请参见帖子解释了如何执行此操作,并提供了一个包装器,可轻松保存和加载任何类.当Unity即将被中断时,您必须保存游戏状态.这些是可用于检测到这一点的功能,您必须了解以下信息:

See this post that explains how to do this and provides a wrapper to easily save and load any class. You have to save your game state when Unity is about to be interrupted. These are the functions that can be used to detect this and you must know about:

您必须决定要使用哪些来保存数据.有时,由于每个平台中每个组件的行为,您必须使用多个组件.值得阅读每个文档上的文档,以了解它们在每个平台上的工作.

You have to decide which ones to use to save the data. Sometimes, you must use multiple of them due to the behavior of each one in each platform. It's worth reading the Doc on each one to understand what they do on each platform.

这篇关于我是否必须使用onPause/onStart/onDestroy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆