0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Unityで自作classをListにしてInspectorで扱えるようにする

Last updated at Posted at 2023-01-03

Unityで自作classをListにしてInspectorで扱えるようにする

ポイント:

  • 自作classには[System.Serializable]を付けてシリアライズする必要があります。

解決方法:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    // 自作classはSerializableする
    [System.Serializable] public class SpawnInfo {
        public GameObject spawner; // EnemyのPrefab
        public Vector2 pos;        // Enemyのspawn座標
    }
    // 通常のListとしてinspectorで扱える
    [SerializeField] List<SpawnInfo> spawnList = new List<SpawnInfo>();

結果:(UnityのInspector上の表示)

image.png

編集後記

  • 調べまわって時間消費したのに、
  • ChatGPTで「Unityで自作classをListにしてInspectorで扱えるようにするには?」でオワリだった、ははは
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?