Unity3d editor: how to prevent changes from being undone upon exiting play mode?

我的梦境 提交于 2019-12-01 11:02:42

Other Unity coders have had this problem before me and they came up with a neat solution. Setting the UI to a different colour while in playmode "Playmode tint".

You can read the details here (originally posted 2009 but I have checked it still works in latest Unity 5.3):

http://answers.unity3d.com/questions/9159/best-strategies-for-not-accidently-editing-whilst.html

There is no settings to prevent changing things during play mode but there are ways to reduce the chances of losing changes during play mode.

1.Edit->Preferences... -> Colors. Now, on the right change Playmode Tint to red. That will remind you you are making changes in play mode.

2.Click on the gear icon of each component you change during play then click Copy Component. When are done with playmode, select the component you want to keep its changes. Click the gear icon again and this time, Click Paste Component Values.

3.Write an Editor Plugin that will do that for you. This is hard but possible.

Use event to find out when entering playmode. Store all GameObject public important variables such as transform/rigidbody properties in a list.

Wait for the stop event to fire then ask your self which GameObjects to overwrite settings to. Then overwrite the properties of the selected GameObjects That's it.

Usefull APIs for this:

EditorApplication.isPlaying
EditorApplication.isPaused
EditorApplication.isPlayingOrWillChangePlaymode
EditorApplication.playmodeStateChanged += callBackFunc;
EditorApplication.HierarchyWindowItemCallback
EditorApplication.ProjectWindowItemCallback

Note: According to Unity roadmap, a feature that enables you to save playtime changes is in construction and will be released soon but the above seems to be the only way at this time.

You can select objects you want to keep while in play mode, copy them with Ctrl + C, and then just paste them back in with Ctrl + V after returning to edit mode. Then you can eithr delete the originals from the scene or copy values from individual components like @Programmer suggested.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!