teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

ソースを追加

2017/10/23 23:10

投稿

suvera
suvera

スコア106

title CHANGED
File without changes
body CHANGED
@@ -13,9 +13,67 @@
13
13
 
14
14
  ###該当のソースコード
15
15
  ```ここに言語を入力
16
+ # スクリプトの一部
17
+
16
- ここにご自身が実行したソーコードを書いてください
18
+ MonoBehaviour継承クラ
19
+ ```MapManagerClass
20
+ public List<List<int>> map;
21
+
22
+ void Start() {
23
+ Debug.Log(map);
24
+ }
25
+ public void SetMap(List<List<BlockStatus>> newMap) {
26
+ map = newMap;
27
+ }
17
28
  ```
18
29
 
30
+ Editorスクリプト
31
+ ```
32
+ void OnGUI() {
33
+ mapManager = EditorGUILayout.ObjectField("MapManagerコンポーネント を持ったオブジェクト", mapManager, typeof(MapManager), true) as MapManager;
34
+
35
+ if (mapManager == null)
36
+ return;
37
+
38
+ List<List<int>> map = mapManager.map;
39
+ int mapSize = 0;
40
+ Debug.Log(map);
41
+ if (map != null) {
42
+ mapSize = map.Count;
43
+ }
44
+ else {
45
+ mapManager.map = new List<List<int>>();
46
+ map = mapManager.map;
47
+ }
48
+
49
+ foldoutMapList = EditorGUILayout.Foldout(foldoutMapList, "map");
50
+ if (this.foldoutMapList) {
51
+ mapSize = EditorGUILayout.IntField("Size", mapSize);
52
+ mapSize = Mathf.Clamp(mapSize, 1, 5);
53
+ EditorGUILayout.BeginHorizontal(GUI.skin.box);
54
+ {
55
+ for (int index = 0; index < mapSize; index++) {
56
+ EditorGUILayout.BeginVertical(GUI.skin.box);
57
+ {
58
+ if (index < map.Count) {
59
+ EditorGUILayout.LabelField(index.ToString());
60
+ }
61
+ else {
62
+ map.Add(new List<int>());
63
+ }
64
+ EditorGUILayout.EndVertical();
65
+ }
66
+ }
67
+ EditorGUILayout.EndHorizontal();
68
+ if (mapSize < map.Count) {
69
+ map.RemoveRange(mapSize, map.Count - mapSize);
70
+ }
71
+ }
72
+ mapManager.SetMap(map);
73
+ }
74
+ ```
75
+ ```
76
+
19
77
  ###試したこと
20
78
  1次元で同じような処理をやってみました。
21
79
  こちらは思ったように動作して、実行時にNullになるようなことはありませんでした。