简体   繁体   English

重构/重命名 Unity 检查器变量名称?

[英]Refactor/Rename Unity inspector variable names?

Refactoring or renaming member variables is commonplace in software development, but this can be difficult while working in Unity.重构或重命名成员变量在软件开发中很常见,但在 Unity 中工作时这可能很困难。 If a variable is visible to the inspector the old variable is destroyed, along with whatever value set, and a new variable is created.如果变量对检查员可见,则旧变量以及设置的任何值都会被销毁,并创建一个新变量。 Is there a way to tell Unity that this new variable is the same as the old one preserving the values set in the inspector for all instances of the component?有没有办法告诉 Unity 这个新变量与旧变量相同,保留了检查器中为组件的所有实例设置的值?

Yes, there's a way -- use the FormerlySerializedAs attribute :是的,有一种方法——使用前序列化的属性

[FormerlySerializedAs("theOldName")]
[SerializeField] float theNewName = 0f;

(An alternative, brute force approach is to do a text search & replace in the scene file to rename something, by the way.) (顺便说一下,另一种蛮力方法是在场景文件中进行文本搜索和替换以重命名某些内容。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM