using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class Test : MonoBehaviour
{
public string fruit = "test";
[HideInInspector]
public int editorSelectedIndex;
[HideInInspector]
public string[] dropdownItems = new string[] { "Apple", "Orange", "Banana" };
}
#if UNITY_EDITOR
[CustomEditor(typeof(Test))]
public class LocalizeTextEditor : Editor
{
private Test test;
private void OnEnable()
{
this.test = target as Test;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
DrawDefaultInspector();
EditorGUI.BeginChangeCheck();
var selectedIndex = this.test.editorSelectedIndex;
List<string> list = new List<string>();
//ここを変更すればテキストファイルから取ってきたりできる
list.AddRange(this.test.dropdownItems);
var displayOptions = list.ToArray();
var index = displayOptions.Length > 0 ? EditorGUILayout.Popup("入力支援", selectedIndex, displayOptions)
: -1;
if (EditorGUI.EndChangeCheck())
{
var objectToUndo = this.test;
var name = "Foo";
Undo.RecordObject(objectToUndo, name);
this.test.editorSelectedIndex = index;
this.test.fruit = list[index];
}
serializedObject.ApplyModifiedProperties();
}
}
#endif