| | 1 | | using System; |
| | 2 | | using UnityEditor; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.MyAccount |
| | 6 | | { |
| | 7 | | [CustomEditor(typeof(ProfileAdditionalInfoValueListScriptableObject))] |
| | 8 | | public class ProfileAdditionalInfoValueListScriptableObjectEditor : Editor |
| | 9 | | { |
| | 10 | | private SerializedProperty valuesProperty; |
| | 11 | | private string csvTextContent; |
| | 12 | |
|
| | 13 | | private void OnEnable() |
| | 14 | | { |
| 0 | 15 | | valuesProperty = serializedObject.FindProperty("values"); |
| 0 | 16 | | } |
| | 17 | |
|
| | 18 | | public override void OnInspectorGUI() |
| | 19 | | { |
| 0 | 20 | | base.OnInspectorGUI(); |
| | 21 | |
|
| 0 | 22 | | csvTextContent = EditorGUILayout.TextArea(csvTextContent); |
| | 23 | |
|
| 0 | 24 | | if (GUILayout.Button("Generate from CSV")) |
| | 25 | | { |
| 0 | 26 | | string[] values = ConvertCsvToStringArray(csvTextContent); |
| | 27 | |
|
| 0 | 28 | | valuesProperty.arraySize = values.Length; |
| | 29 | |
|
| 0 | 30 | | for (var i = 0; i < values.Length; i++) |
| 0 | 31 | | valuesProperty.GetArrayElementAtIndex(i).stringValue = values[i]; |
| | 32 | |
|
| 0 | 33 | | serializedObject.ApplyModifiedProperties(); |
| | 34 | | } |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | private string[] ConvertCsvToStringArray(string csvText) => |
| 0 | 38 | | csvText.Split(new char[] { ',', '\n' }, StringSplitOptions.RemoveEmptyEntries); |
| | 39 | | } |
| | 40 | | } |