[QuestPopup] custom

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

[QuestPopup] custom

Post by alfonso »

Hi Tony!

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();
	}
}
this is the code of the CustomPropertyDrawer

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;
	}
}
if i select a database, the field string change to popup and show the Quests names in the database but if i select any of them dont update the value of the selection or if i toggle the popup to string neither work, any idea what im doing wrong?

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 :)
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: [QuestPopup] custom

Post by Tony Li »

Hi Alfonso,

I'll test this code when I get back into the office and try to post some suggestions.

Is there a reason why you're not using the Dialogue System's built-in [QuestPopup] attribute?
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

Re: [QuestPopup] custom

Post by alfonso »

thanks Tony :)

at first i started using the [QuestPopup] of Dialogue System, but the problem is for each component who need a quest selecter i need to create a CustomEditor to the component to be able to show the Database Selection (i dont have the database in the scene).
with the CustomPropertyDrawer i can draw the Database selection automatically if the property is using the [QuestPopup](the custom one) and is not need to create a CustomEditor or this is my thought
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: [QuestPopup] custom

Post by Tony Li »

Hi Alfonso,

I'll add an optional parameter to [QuestPopup] and [ConversationPopup] that you can include to show the Reference Database selector, like:

Code: Select all

[QuestPopup(showReferenceDatabase=true)]
public string questTitle;
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

Re: [QuestPopup] custom

Post by alfonso »

Tony Li wrote:Hi Alfonso,

I'll add an optional parameter to [QuestPopup] and [ConversationPopup] that you can include to show the Reference Database selector, like:

Code: Select all

[QuestPopup(showReferenceDatabase=true)]
public string questTitle;
you knows how to make happy a developer :)
Post Reply