im making a own QuestPopup because i have may component who need se quest name, so instead of put the below code for each class i create a CustomPropertyDrawer how put the fieldObject of the database so only need to puto the attribute [QuestPopup] where i need it.
Code: Select all
[CustomEditor(typeof(Class))]
public class ClassEditor: Editor {
public void OnEnable() {
// If EditorTools.selectedDatabase isn't set, try to use DialogueManager.initialDatabase:
EditorTools.SetInitialDatabaseIfNull();
}
public override void OnInspectorGUI() {
// Your custom GUI stuff goes here, or call this for the default GUI:
DrawDefaultInspector();
EditorTools.DrawReferenceDatabase();
}
}
Code: Select all
[CustomPropertyDrawer(typeof(QuestPopupAttribute))]
public class QuestPopupDrawer : PropertyDrawer
{
public DialogueDatabase selectedDatabase;
public QuestPicker questPicker = null;
public override void OnGUI (Rect p, SerializedProperty property, GUIContent label)
{
Rect dbRect = new Rect (p.x, p.y, p.width, EditorGUIUtility.singleLineHeight);
Rect questRect = new Rect(p.x, p.y+18, p.width, EditorGUIUtility.singleLineHeight);
EditorGUI.BeginProperty (p, label, property);
EditorGUI.BeginChangeCheck ();
selectedDatabase = EditorGUI.ObjectField(dbRect, new GUIContent("Reference Database", "Database to use for pop-up menus"), selectedDatabase, typeof(DialogueDatabase), false) as DialogueDatabase;
if (selectedDatabase == null)
EditorGUI.PropertyField (questRect, property);
else
{
questPicker = new QuestPicker (selectedDatabase, property.stringValue, true);
questPicker.Draw (questRect);
property.stringValue = questPicker.currentQuest;
}
if (EditorGUI.EndChangeCheck())
property.serializedObject.ApplyModifiedProperties();
EditorGUI.EndProperty ();
}
public override float GetPropertyHeight (SerializedProperty property, GUIContent label)
{
return base.GetPropertyHeight (property, label) + EditorGUIUtility.singleLineHeight;
}
}
edit: this line "property.stringValue = questPicker.currentQuest;" fix the value selection, but not the toogle issue and other thing is if i select other gameobject the database reference is lost.
Thanks