Answer the question
In order to leave comments, you need to log in
How to specify UnityEvent in custom inspector?
using UnityEngine;
using UnityEngine.Events;
using UnityEditor;
using UnityEditor.Events;
using UnityEditor.SceneManagement;
[CustomEditor(typeof(MessObj))]
public class SetMessages : Editor
{
private MessObj MO;
private void OnEnable()
{
MO = (MessObj)target;
}
public override void OnInspectorGUI()
{
EditorGUILayout.LabelField("Реплики");
if (MO.messages.Count > 0)
{
foreach (Function.Message Mess in MO.messages)
{
EditorGUILayout.BeginVertical("Box");
Mess.message = EditorGUILayout.TextField("Содержание:", Mess.message);
Mess.TextDelay = EditorGUILayout.FloatField("Скорость текста:", Mess.TextDelay);
Mess.IsWaitKey = EditorGUILayout.Toggle("Ожидать нажатия кнопки?", Mess.IsWaitKey);
Mess.FillString = EditorGUILayout.Toggle("Занять всю строку?", Mess.FillString);
Mess.ClearTextField = EditorGUILayout.Toggle("Очистить поле?", Mess.ClearTextField);
Mess.CustomTXTSound = (AudioSource)EditorGUILayout.ObjectField("Другой звук текста:", Mess.CustomTXTSound, typeof(AudioSource), true);
Mess.CustomFont = (Font)EditorGUILayout.ObjectField("Другой шрифт:", Mess.CustomFont, typeof(Font), true);
Mess.Face = (Sprite)EditorGUILayout.ObjectField("Лицо", Mess.Face, typeof(Sprite), true);
Mess.ActivateID = EditorGUILayout.IntField("ID вопроса:", Mess.ActivateID);
EditorGUILayout.LabelField("//0 = отсутсвие вопроса//");
if (GUILayout.Button("Удалить реплику")) MO.messages.Remove(Mess);
EditorGUILayout.EndVertical();
}
if (GUILayout.Button("Удалить последнюю реплику")) MO.messages.RemoveAt(MO.messages.Count - 1);
}
else EditorGUILayout.LabelField("Реплики отсутствуют!");
if (GUILayout.Button("Добавить реплику", GUILayout.Height(35))) MO.messages.Add(new Function.Message());
if (MO.questions.Count > 0)
{
foreach (Function.Question quest in MO.questions)
{
EditorGUILayout.BeginVertical("Box");
quest.QuestionID = EditorGUILayout.IntField("ID", quest.QuestionID);
quest.message = EditorGUILayout.TextField("Содержание:", quest.message);
quest.ChangeOne = EditorGUILayout.TextField("Выбор первый:", quest.ChangeOne);
//quest.IfChangeFirst = (Что здесь должно быть?); <<---- Нужно чтобы в инспектре можно было указать UnityEvent
quest.ChangeTwo = EditorGUILayout.TextField("Выбор второй:", quest.ChangeTwo);
quest.TextDelay = EditorGUILayout.FloatField("Скорость текста:", quest.TextDelay);
quest.CustomFont = (Font)EditorGUILayout.ObjectField("Другой шрифт:", quest.CustomFont, typeof(Font), true);
quest.CustomTXTSound = (AudioSource)EditorGUILayout.ObjectField("Другой звук текста:", quest.CustomTXTSound, typeof(AudioSource), true);
EditorGUILayout.EndVertical();
}
if (GUILayout.Button("Удалить последнюю вопрос")) MO.questions.RemoveAt(MO.questions.Count - 1);
}
else EditorGUILayout.LabelField("Вопросы отсутствуют!");
if (GUILayout.Button("Добавить вопрос", GUILayout.Height(35))) MO.questions.Add(new Function.Question());
if (GUI.changed) SetObjDirty(MO.gameObject);
}
public static void SetObjDirty(GameObject obj)
{
EditorUtility.SetDirty(obj);
EditorSceneManager.MarkSceneDirty(obj.scene);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question