強火で進め

このブログではプログラム関連の記事を中心に書いてます。

C#で構造体をInspectorで使える様にする方法


この様なタイトルにしましたが実際は構造体(struct)はInspectorには表示されないようです。

しかし、classであれば以下の様に [System.Serializable] を使うとプロパティのgameがInspectorで表示され編集する事が出来る様に成ります。こちらで代用しましょう。

using UnityEngine;
using System.Collections;

[System.Serializable]
public class GameData {
	public int Score;
	public int CurrentStage;
}

[System.Serializable]
public class Test : MonoBehaviour {
	public int p = 5;
	public Color col = Color.white;
	public Vector3 vec;
	public Transform trans;
	public GameData game;

	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}