简体   繁体   English

Unity 编辑器与预制件冲突

[英]Unity editor conflicts with prefabs

So I'm working this hexagonal grid system for buildings in Unity.所以我正在为 Unity 中的建筑物使用这个六边形网格系统。 I made a 2d boolean array to set which area of the grid, the building will occupy.我制作了一个二维 boolean 数组来设置网格的哪个区域,建筑物将占据。 I have made a custom editor so I can edit it.我制作了一个自定义编辑器,因此我可以对其进行编辑。 It all works perfectly until I set it to a prefab.在我将它设置为预制之前,这一切都完美无缺。 Then the grid that sets the area just resets.然后设置区域的网格会重置。 Is there any way I can fix this issue?有什么办法可以解决这个问题吗?

PS Weird this is when I set a slider in the same script. PS 很奇怪,这是我在同一脚本中设置 slider 的时候。 Unity had no problem remembering the slider's data. Unity 可以毫无问题地记住滑块的数据。 But changing it in the prefab caused it to reset但是在预制件中更改它会导致它重置

I'm using Unity version 2018.3.0f2我正在使用 Unity 版本 2018.3.0f2

Custom editor scripts have the habit of loosing all their data upon play, instantiate or build.自定义编辑器脚本有在播放、实例化或构建时丢失所有数据的习惯。 It is up to you to save the data upon edit and deserialize it back into the interface upon viewing.您可以在编辑时保存数据并在查看时将其反序列化回界面。 It is much easier to use custom [system.serializable] classes with [serializeField] in the declaration.在声明中使用带有 [serializeField] 的自定义 [system.serializable] 类要容易得多。 a List of buildingRows classes, consisting of a list of a buildings classes would do fine in your case.一个 buildingRows 类的列表,由一个建筑物类的列表组成,在你的情况下会很好。 It just does not look as pretty as you might like.它只是看起来不像你想的那么漂亮。

a neat workaround would be to use a [mutiline] string text inputfield in the inspector.一个巧妙的解决方法是在检查器中使用 [mitiline] 字符串文本输入字段。 buildings could be either the character "o" or "x" for example.例如,建筑物可以是字符“o”或“x”。 When split on newlines this is essentially a 2D array of chars.在换行符上拆分时,这本质上是一个二维字符数组。 Like this:像这样:

o o o o x o o o o o 
o x o o x x o o o x 
o o o o o x o x x x 
o o o x o o o o o o 
o o o x o o o x o o 
o o o x o o o x o o 
o o o x o o o x o o 
x x x x o o o x o o 
x x x o o o o x o o 
o o o o o o o o o o 

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

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