Avatar
0
tvd12 Enlightened
tvd12 Enlightened
Ý nghĩa của [Serializable] attribute là gì?
Ví dụ trong đoạn code này thì [Serializable] attribute có nghĩa là gì?<div class="markdown-block position-relative overflow-auto source-csharp"> <pre> <span class="pl-k">using</span> System; <span class="pl-k">using</span> UnityEngine; <span class="pl-k">public</span> <span class="pl-k">class</span> Player : MonoBehaviour { //Create a custom <span class="pl-k">struct</span> and apply [Serializable] attribute to it [Serializable] <span class="pl-k">public</span> <span class="pl-k">struct</span> PlayerStats { <span class="pl-k">public</span> <span class="pl-k">int</span> movementSpeed; <span class="pl-k">public</span> <span class="pl-k">int</span> hitPoints; <span class="pl-k">public</span> <span class="pl-k">bool</span> hasHealthPotion; } //Make the <span class="pl-k">private</span> field of our PlayerStats <span class="pl-k">struct</span> visible <span class="pl-k">in</span> the Inspector //by applying [SerializeField] attribute to it [SerializeField] <span class="pl-k">private</span> PlayerStats stats; } </pre> </div>
Answer