Custom Property Drawers

This page describes the Dialogue System's custom property drawers and attributes, which you can use in your own custom editor scripts.


ConversationPopup Attribute

Use the [ConversationPopup] attribute in your class definition to turn a string into a conversation popup. It has an optional Boolean parameter to show a database selection field.

using UnityEngine;
public class MyClass : MonoBehaviour {
[ConversationPopup]
public string conversation; // Shown without database selection field.
[ConversationPopup(true)]
public string conversation2; // Shown WITH database selection field.
}

QuestPopup Attribute

Use the [QuestPopup] attribute in your class definition to turn a string into a quest popup. It has an optional Boolean parameter to show a database selection field.

using UnityEngine;
public class MyClass : MonoBehaviour {
[QuestPopup]
public string questName; // Shown without database selection field.
[QuestPopup(true)]
public string questName2; // Shown WITH a database selection field.
}

QuestState Attribute

The [QuestState] attribute changes the quest state popup to use lowercase letters so it matches the case used in Lua.

using UnityEngine;
public class MyClass : MonoBehaviour {
public QuestState myQuestState;
}

ItemPopup Attribute

Use the [ItemPopup] attribute in your class definition to turn a string into an item popup. It has an optional Boolean parameter to show a database selection field.

using UnityEngine;
public class MyClass : MonoBehaviour {
[ItemPopup]
public string item; // Example: Shown without database selection field.
}

VariablePopup Attribute

Use the [VariablePopup] attribute in your class definition to turn a string into a variable popup. It has an optional Boolean parameter to show a database selection field.

using UnityEngine;
public class MyClass : MonoBehaviour {
[VariablePopup]
public string variable; // Example: Shown without database selection field.
}

Lua Wizard Attributes

Use the [LuaConditionWizard] and [LuaScriptWizard] attributes in your class definition to turn a string into a Lua wizard field. This allows you to assign Lua code to the string using the drop-down Lua wizards.

using UnityEngine;
public class MyClass : MonoBehaviour {
[LuaConditionWizard]
public string myLuaCondition;
[LuaScriptWizard]
public string myLuaScript;
}

Reference Database

Internally, conversation titles and quest names are just strings. It's helpful to provide pop-up menus instead of having to manually enter the strings. The content for the pop-up menus come from the dialogue database assigned to the static property PixelCrushers.DialogueSystem.EditorTools.selectedDatabase.

If EditorTools.selectedDatabase isn't set, it will default to the Dialogue Manager's Initial Database if you have a Dialogue Manager in your scene.

The ConversationPopup Attribute and QuestPopup Attribute let you specify whether to also show a field where the designer can select the database.

If you want to manually show the database selection field, use the following code in your custom editor:

using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(MyClass))]
public class MyClassEditor : Editor {
public void OnEnable() {
// If EditorTools.selectedDatabase isn't set, try to use DialogueManager.initialDatabase:
EditorTools.SetInitialDatabaseIfNull();
}
public override void OnInspectorGUI() {
EditorTools.DrawReferenceDatabase();
// Your custom GUI stuff goes here, or call this for the default GUI:
DrawDefaultInspector();
}
}

Dialogue Trigger Event Popup

To draw a dialogue trigger event (e.g., OnUse, OnTriggerEnter, etc.) in a custom inspector, call DialogueTriggerEventDrawer.LayoutPopup():

//...
trigger = DialogueTriggerEventDrawer.LayoutPopup("Trigger", trigger);

This method shows the choices in a nicer order than the default used by GUILayout.EnumPopup().


Lua Wizards in Custom Editors

To manually incorporate Lua wizards in your custom editor scripts, create a Lua wizard and then call its Draw() method. (Note: It's usually easier to simply use the Lua Wizard Attributes above.)

Example: Say you have a MonoBehaviour like this:

using UnityEngine;
public class TestLuaWizard : MonoBehaviour {
public string luaCode;
}

Use this code to draw a wizard for the luaCode variable:

using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TestLuaWizard))]
public class TestLuaWizardEditor : Editor {
private LuaScriptWizard luaScriptWizard;
public void OnEnable() {
// The EditorTools class maintains a reference to a dialogue database.
// If it's null, set it to the Dialogue Manager's Initial Database:
EditorTools.SetInitialDatabaseIfNull();
// Create a LuaScriptWizard that uses the selected database:
luaScriptWizard = new LuaScriptWizard(EditorTools.selectedDatabase);
}
public override void OnInspectorGUI() {
var script = target as TestLuaWizard;
// Allow the user to change to refer to a different database:
EditorTools.DrawReferenceDatabase();
if (EditorTools.selectedDatabase != luaScriptWizard.database) {
luaScriptWizard.database = EditorTools.selectedDatabase;
luaScriptWizard.RefreshWizardResources();
}
// This line actually draws the wizard:
script.luaCode = luaScriptWizard.Draw(new GUIContent("Lua Code"), script.luaCode);
}
}

<< Script Messages | Integrating With Other Systems and Scripts >>

PixelCrushers.DialogueSystem.QuestState
QuestState
Quest state is a bit-flag enum that indicates the state of a quest.
Definition: QuestState.cs:8
PixelCrushers.DialogueSystem.DialogueTriggerEvent.OnEnable
Trigger when the trigger script is enabled (allows retriggering if you disable and re-enable the scri...
PixelCrushers.DialogueSystem
Definition: ArticyConverterWindow.cs:8
PixelCrushers
Definition: ArticyConverterWindow.cs:8
PixelCrushers.DialogueSystem.DialogueTriggerEvent
DialogueTriggerEvent
A bit mask enum that defines the events that can trigger barks, conversations, and sequences.
Definition: DialogueTriggerEvent.cs:10