質問編集履歴
2
ソースコードを書き換えました
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,9 +50,11 @@
|
|
50
50
|
|
51
51
|
//使用例
|
52
52
|
|
53
|
-
|
53
|
+
[SerializeField,SetSpecialAttribute]
|
54
|
-
|
54
|
+
|
55
|
-
private Special
|
55
|
+
private SetSpecialAttribute special; //値がセットされない
|
56
|
+
|
57
|
+
|
56
58
|
|
57
59
|
```
|
58
60
|
|
@@ -110,37 +112,79 @@
|
|
110
112
|
|
111
113
|
{
|
112
114
|
|
115
|
+
property.serializedObject.Update ();
|
116
|
+
|
117
|
+
label = EditorGUI.BeginProperty(position, label, property);
|
118
|
+
|
119
|
+
SetSpecialAttribute specialAttribute = (SetSpecialAttribute)attribute;
|
120
|
+
|
113
121
|
int index = GetElementIndex( label );
|
114
122
|
|
115
|
-
|
123
|
+
var paths = Directory.GetFiles (datapath, "*.asset");
|
124
|
+
|
125
|
+
string[] names = new string[paths.Length];
|
126
|
+
|
127
|
+
for (int i = 0; i < paths.Length; ++i) {
|
128
|
+
|
129
|
+
names [i] = Path.GetFileNameWithoutExtension (paths [i]);
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
position.height = 16f;
|
134
|
+
|
135
|
+
int size = EditorGUI.IntField(position,"size",specialAttribute.size);
|
136
|
+
|
137
|
+
position.y += 18f;
|
138
|
+
|
139
|
+
specialAttribute.size = size;
|
140
|
+
|
141
|
+
if(specialAttribute.special.Length < size){
|
142
|
+
|
143
|
+
specialAttribute.special = new Special[size];
|
144
|
+
|
145
|
+
specialAttribute.idx = new int[size];
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
// 文字列のindexを取得する
|
150
|
+
|
151
|
+
// EditorGUI.Popupの結果を index として使用し文字列更新する
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
int indent = EditorGUI.indentLevel;
|
156
|
+
|
157
|
+
EditorGUI.indentLevel = 1;
|
158
|
+
|
159
|
+
for(int i = 0; i < size; ++i) {
|
160
|
+
|
161
|
+
int idx = EditorGUI.Popup (position, label.text, specialAttribute.idx[i], names);
|
162
|
+
|
163
|
+
position.y += 18f;
|
164
|
+
|
165
|
+
specialAttribute.idx[i] = idx;
|
166
|
+
|
167
|
+
var special = AssetDatabase.LoadAssetAtPath<Special> (paths [idx]) as Special;
|
168
|
+
|
169
|
+
specialAttribute.special[i] = special;
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
EditorGUI.indentLevel = indent;
|
174
|
+
|
175
|
+
EditorGUI.EndProperty();
|
176
|
+
|
177
|
+
property.serializedObject.ApplyModifiedProperties();
|
178
|
+
|
179
|
+
return;
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
public override float GetPropertyHeight (SerializedProperty property, GUIContent label) {
|
116
184
|
|
117
185
|
SetSpecialAttribute specialAttribute = (SetSpecialAttribute)attribute;
|
118
186
|
|
119
|
-
|
120
|
-
|
121
|
-
var paths = Directory.GetFiles (datapath, "*.asset");
|
122
|
-
|
123
|
-
string[] names = new string[paths.Length];
|
124
|
-
|
125
|
-
|
187
|
+
return (16f + 18f * specialAttribute.size) ;
|
126
|
-
|
127
|
-
names [i] = Path.GetFileNameWithoutExtension (paths [i]);
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
int idx = EditorGUI.Popup (position, label.text, specialAttribute.idx[index], names);
|
134
|
-
|
135
|
-
specialAttribute.idx[index] = idx;
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
var special = AssetDatabase.LoadAssetAtPath<Special> (paths [idx]) as Special;
|
140
|
-
|
141
|
-
//property = (SerializedProperty)special;
|
142
|
-
|
143
|
-
return;
|
144
188
|
|
145
189
|
}
|
146
190
|
|
@@ -172,8 +216,6 @@
|
|
172
216
|
|
173
217
|
}
|
174
218
|
|
175
|
-
|
176
|
-
|
177
219
|
```
|
178
220
|
|
179
221
|
|
@@ -190,34 +232,30 @@
|
|
190
232
|
|
191
233
|
|
192
234
|
|
235
|
+
[System.Serializable]
|
236
|
+
|
193
237
|
public class SetSpecialAttribute : PropertyAttribute
|
194
238
|
|
195
239
|
{
|
196
240
|
|
197
|
-
string datapath = "Assets/Resources/Data/SpecialData";
|
198
|
-
|
199
241
|
public int[] idx;
|
200
242
|
|
243
|
+
public int size;
|
244
|
+
|
245
|
+
public Special[] special;
|
246
|
+
|
201
247
|
|
202
248
|
|
203
249
|
public SetSpecialAttribute ()
|
204
250
|
|
205
251
|
{
|
206
252
|
|
207
|
-
var paths = Directory.GetFiles (datapath, "*.asset");
|
208
|
-
|
209
|
-
string[] names = new string[paths.Length];
|
210
|
-
|
211
|
-
for (int i = 0; i < paths.Length; ++i) {
|
212
|
-
|
213
|
-
names [i] = Path.GetFileNameWithoutExtension (paths [i]);
|
214
|
-
|
215
|
-
}
|
216
|
-
|
217
253
|
//適当なサイズを指定するしかない?
|
218
254
|
|
219
255
|
idx = new int[10];
|
220
256
|
|
257
|
+
special = new Special[10];
|
258
|
+
|
221
259
|
}
|
222
260
|
|
223
261
|
}
|
1
環境を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,6 +38,14 @@
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
+
### 環境
|
42
|
+
|
43
|
+
Unity 2017.2.0f3
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
41
49
|
```C#
|
42
50
|
|
43
51
|
//使用例
|