簡體   English   中英

停止 Unity Inspector DecoratorDrawer 鏈接

[英]Stop Unity Inspector DecoratorDrawer chaining

我的代碼如下所示:

C# 代碼

問題是,當將 DecoratorDrawer 元素添加到代碼中時,它們與檢查器中的所有以下鏈接對象鏈接在一起,因此它們看起來像這樣:

具有鏈式 DecoratorDrawer 元素的 Unity 檢查器

有沒有辦法讓代碼保持原樣,使檢查器看起來像這樣,例如任何類型的[Space(10), showOnce=true]

Unity 中檢查器的最佳外觀

還是沒有辦法阻止 DecoratorDrawer 與內置的檢查器裝飾鏈接?

當您連續聲明多個變量時,它們會接收所有屬性。

寫入 [Space(10)] 不會在檢查器中此時添加空間,但會使用序列化程序拾取的屬性裝飾字段,從而導致不同的布局。 但是,此屬性將分配給所有字段,從而產生您獲得的布局。 所以不,我不認為你可以這樣做。

Odin Inspector具有這樣的分組功能,但來自 Unity 的功能仍然會像您的問題一樣。

一般來說,為什么在提問時不上傳代碼/錯誤的圖像? .


觀點

然后一般來說,我個人也不會使用多個內聯聲明。 這是可維護性/可讀性較差的方式。


問題

如您所見,多個內聯聲明意味着屬性應用於每個單獨的字段/屬性。

所以基本上你的

[Header("Start points of the arrow")]
[SerializeField] private GameObject arrowpoint_joystick, arrowpoint_trigger, arrowpoint_secondary;

等於寫作

[Header("Start points of the arrow")][SerializeField] private GameObject arrowpoint_joystick;
[Header("Start points of the arrow")][SerializeField] private GameObject arrowpoint_trigger;
[Header("Start points of the arrow")][SerializeField] private GameObject arrowpoint_secondary;

這當然不是你想要做的。

解決方案

代替

[Header("Start points of the arrow")]
[SerializeField] private GameObject arrowpoint_joystick, arrowpoint_trigger, arrowpoint_secondary;

[Space(10)]
[Header("List of secondary bezier points")]
[SerializeField] private GameObject arrowpoint_joystickBezierPoint, arrowpoint_triggerBezierPoint, arrowpoint_secondaryBezierPoint;

我寧願做到

[Header("Start points of the arrow")]
[SerializeField] private GameObject arrowpoint_joystick;
[SerializeField] private GameObject arrowpoint_trigger;
[SerializeField] private GameObject arrowpoint_secondary;

[Space(10)]

[Header("List of secondary bezier points")]
[SerializeField] private GameObject arrowpoint_joystickBezierPoint;
[SerializeField] private GameObject arrowpoint_triggerBezierPoint
[SerializeField] private GameObject arrowpoint_secondaryBezierPoint;

和(兩者)“問題”(和意見)已經解決,而且這種方式在代碼中看起來更類似於它在檢查器中的樣子。 而且不需要外部庫。 (Odin 有時會因為它的“神奇”序列化而帶來其他問題;))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM