Пропадает скрипт при выборе popup после редактированния Editor скриптом
После редактировании Editor-а скриптом, пропадает сам скрипт при выборе в popup. Как исправить? Все видно в коде и на скриншотах.
[CustomEditor(typeof(Cards))]
public class CardsMod : Editor
{
string[] costTypes = { "action", "mana" };
int costIndex;
string[] spellTypes = { "Creature", "Spell" };
int spellIndex;
public override void OnInspectorGUI()
{
DrawDefaultInspector();
EditorGUILayout.Space(10);
Cards cards = (Cards)target;
#region Настойка стоимости карты
GUILayout.BeginHorizontal();
cards.GetCost = EditorGUILayout.IntField("Стоимость карты", cards.GetCost);
costIndex = EditorGUILayout.Popup(costIndex, costTypes);
if (costIndex == 0)
cards.GetCostType = costTypes[0];
else
cards.GetCostType = costTypes[1];
GUILayout.EndHorizontal();
#endregion
#region Выбор типа карты
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(new GUIContent("Тип карты", "Призыв или заклинание"));
spellIndex = EditorGUILayout.Popup(spellIndex, spellTypes);
if (spellIndex == 0)
{
cards.GetIsCreature = true;
cards.GetCreature = EditorGUILayout.ObjectField(cards.GetCreature, typeof(GameObject), true) as GameObject;
}
else
{
cards.GetIsCreature = false;
cards.GetBonus.name = EditorGUILayout.TextField("Spell name");
}
EditorGUILayout.EndHorizontal();
#endregion
if (GUILayout.Button("Play card"))
{
cards.GetActive = true;
Debug.Log(cards.GetActive);
}
}
}
Я что-то читал, что могут быть какие-то проблемы при использовании EditorGUILayout и GUILayout одновременно. Но что если мне нужен popup, например, которого нет в GUILayout? :(
Ответы (1 шт):
Автор решения: Dead Lord
→ Ссылка
Что ж, что бы справится с этим мне пришлось просто добавлять еще одну строчку, тогда все работает fine. А так же все EditorGUILayout.Begin(end)Horizontal(); заменил на GUILayout.Begin(end)Horizontal();:
#region Выбор типа карты
GUILayout.BeginHorizontal();
GUILayout.Label(new GUIContent("Тип карты", "Призыв или заклинание"));
spellIndex = GUILayout.SelectionGrid(spellIndex, spellTypes, spellTypes.Count());
GUILayout.EndHorizontal();
if (spellIndex == 0)
{
cards.GetIsCreature = true;
creature = EditorGUILayout.ObjectField(cards.GetCreature, typeof(GameObject), true) as GameObject;
cards.GetCreature = creature;
}
else
{
cards.GetIsCreature = false;
cards.GetBonusName = EditorGUILayout.TextField("Название заклинания", bonusName);
}
#endregion

