|
7 | 7 |
|
8 | 8 | #if UNITY_EDITOR
|
9 | 9 | using UnityEditor;
|
| 10 | +using UnityEditorInternal; |
10 | 11 | using net.narazaka.avatarmenucreator.util;
|
11 | 12 | using System.Text.RegularExpressions;
|
12 | 13 | #endif
|
@@ -189,6 +190,7 @@ protected override void OnMultiGUI(SerializedProperty serializedProperty)
|
189 | 190 | string ChooseNameRenameSearch = "";
|
190 | 191 | string ChooseNameRenameResult = "";
|
191 | 192 | Vector2 ScrollPositionChoises;
|
| 193 | + ReorderableList ChoiceList = null; |
192 | 194 |
|
193 | 195 | protected override void OnHeaderGUI(IList<string> children)
|
194 | 196 | {
|
@@ -218,7 +220,10 @@ protected override void OnHeaderGUI(IList<string> children)
|
218 | 220 | EditorGUILayout.BeginHorizontal();
|
219 | 221 | var rect = EditorGUILayout.GetControlRect(false, GUILayout.Width(EditorGUIUtility.labelWidth));
|
220 | 222 | ChoiceFoldout = EditorGUI.Foldout(rect, ChoiceFoldout, T.選択肢の数);
|
221 |
| - ChooseCount = IntField(ChooseCount); |
| 223 | + ChooseCount = IntField(ChooseCount, index => |
| 224 | + { |
| 225 | + ChoiceList = null; |
| 226 | + }); |
222 | 227 | EditorGUILayout.EndHorizontal();
|
223 | 228 |
|
224 | 229 | if (ChooseCount < 1) ChooseCount = 1;
|
@@ -320,29 +325,41 @@ protected override void OnHeaderGUI(IList<string> children)
|
320 | 325 |
|
321 | 326 | void HeaderChoises()
|
322 | 327 | {
|
323 |
| - EditorGUI.indentLevel++; |
324 |
| - EditorGUIUtility.labelWidth = 65; |
325 |
| - for (var i = 0; i < ChooseCount; ++i) |
| 328 | + if (ChoiceList == null) |
326 | 329 | {
|
327 |
| - EditorGUILayout.BeginHorizontal(); |
328 |
| - ChooseNames[i] = TextField($"{T.選択肢}{i}", ChooseName(i)); |
329 |
| - ChooseIcons[i] = TextureField(ChooseIcon(i)); |
330 |
| - if (GUILayout.Button("↑", GUILayout.Width(19))) |
| 330 | + ChoiceList = new ReorderableList(Enumerable.Range(0, ChooseCount).ToList(), typeof(int), true, false, true, true); |
| 331 | + ChoiceList.drawElementCallback = (rect, index, isActive, isFocused) => |
331 | 332 | {
|
332 |
| - MoveChoice(i, i > 0 ? i - 1 : ChooseCount - 1); |
333 |
| - } |
334 |
| - if (GUILayout.Button("↓", GUILayout.Width(19))) |
| 333 | + rect.height = EditorGUIUtility.singleLineHeight; |
| 334 | + rect.y += 2; |
| 335 | + rect.width -= EditorGUIUtility.standardVerticalSpacing; |
| 336 | + rect.width /= 2; |
| 337 | + EditorGUIUtility.labelWidth = 50; |
| 338 | + ChooseNames[index] = TextField(rect, $"{T.選択肢}{index}", ChooseName(index)); |
| 339 | + EditorGUIUtility.labelWidth = 0; |
| 340 | + rect.x += rect.width + EditorGUIUtility.standardVerticalSpacing; |
| 341 | + ChooseIcons[index] = TextureField(rect, ChooseIcon(index)); |
| 342 | + }; |
| 343 | + ChoiceList.onAddCallback = list => |
335 | 344 | {
|
336 |
| - MoveChoice(i, i < ChooseCount - 1 ? i + 1 : 0); |
337 |
| - } |
338 |
| - if (GUILayout.Button("×", GUILayout.Width(19))) |
| 345 | + WillChange(); |
| 346 | + ChooseCount++; |
| 347 | + var index = ChooseCount - 1; |
| 348 | + ChooseNames[index] = ChooseName(index); |
| 349 | + ChooseIcons[index] = ChooseIcon(index); |
| 350 | + list.list.Add(index); // dummy |
| 351 | + }; |
| 352 | + ChoiceList.onRemoveCallback = list => |
339 | 353 | {
|
340 |
| - RemoveChoice(i); |
341 |
| - } |
342 |
| - EditorGUILayout.EndHorizontal(); |
| 354 | + RemoveChoice(list.index); |
| 355 | + list.list.RemoveAt(list.index); |
| 356 | + }; |
| 357 | + ChoiceList.onReorderCallbackWithDetails = (list, oldIndex, newIndex) => |
| 358 | + { |
| 359 | + MoveChoice(oldIndex, newIndex); |
| 360 | + }; |
343 | 361 | }
|
344 |
| - EditorGUIUtility.labelWidth = 0; |
345 |
| - EditorGUI.indentLevel--; |
| 362 | + ChoiceList.DoLayoutList(); |
346 | 363 | }
|
347 | 364 |
|
348 | 365 | protected override bool HasHeaderBulkGUI => true;
|
|
0 commit comments