Version: 2020.3
言語: 日本語

説明

クラスまたは構造体がシリアル化できることを示します。

[Serializable]属性を適用してシリアル化を有効にします。シリアル化に関する詳細については、Script Serializationを参照してください。

Note: Only non-abstract, non-generic custom classes can be serialized.

In the following example we create a custom Player struct and give it the [Serializable] attribute to make it serializable. We then create a private field of the Player type and apply [SerializeField] attribute to it to make it show up in the Inspector.

using System;
using UnityEngine;

public class Player : MonoBehaviour { //Create a custom struct and apply [Serializable] attribute to it [Serializable] public struct PlayerStats { public int movementSpeed; public int hitPoints; public bool hasHealthPotion; }

//Make the private field of our PlayerStats struct visible in the Inspector //by applying [SerializeField] attribute to it [SerializeField] private PlayerStats stats; }