[SOLVED] "Lua Conditions" only in inspector
[SOLVED] "Lua Conditions" only in inspector
Hey Tony! Hope you're doing well.
I want to add a set of Lua Conditions to a script that I can configure using the Wizard, and run a simple 'are conditions true' check via code.
Is there anything out of the box to have only the Lua Conditions (with the wizard), and not the Quest Conditions / Accepted Tags / Accepted Game Objects?
If there isn't anything out of the box for that - how would you suggest I go about setting that up? Maybe I could make my own custom version of Condition.cs and ConditionEditor.cs and delete everything except the Lua Condition related code? Would it be as easy as that?
Thanks for any help!
I want to add a set of Lua Conditions to a script that I can configure using the Wizard, and run a simple 'are conditions true' check via code.
Is there anything out of the box to have only the Lua Conditions (with the wizard), and not the Quest Conditions / Accepted Tags / Accepted Game Objects?
If there isn't anything out of the box for that - how would you suggest I go about setting that up? Maybe I could make my own custom version of Condition.cs and ConditionEditor.cs and delete everything except the Lua Condition related code? Would it be as easy as that?
Thanks for any help!
Last edited by Jamez0r on Thu Sep 21, 2023 2:22 pm, edited 1 time in total.
Re: "Lua Conditions" only in inspector
Hi,
Use the [LuaConditionWizard] attribute. Example:
Use the [LuaConditionWizard] attribute. Example:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class TestLuaWizard : MonoBehaviour
{
[LuaConditionsWizard(true)] public string luaConditions;
public bool IsTrue()
{
return Lua.IsTrue(luaConditions);
}
}
Re: "Lua Conditions" only in inspector
Thanks for the help Tony!Tony Li wrote: ↑Wed Sep 20, 2023 9:06 pm Hi,
Use the [LuaConditionWizard] attribute. Example:
Code: Select all
using UnityEngine; using PixelCrushers.DialogueSystem; public class TestLuaWizard : MonoBehaviour { [LuaConditionsWizard(true)] public string luaConditions; public bool IsTrue() { return Lua.IsTrue(luaConditions); } }
That did indeed work (awesome! ), but immediately brought up another question. I am actually looking to use these LuaConditions as part of a ScriptableObject. I noticed that if I have the scene open that has the "Dialogue Manager" prefab instance in it, then the Reference Database is automatically set to my database (my game only needs a single database).
However, if the scene I currently have open doesn't have the "Dialogue Manager" in it, then when I recompile my code, the scriptable object's Reference Database loses the reference. My guess is that behind the scenes the "Dialogue Manager" is automatically setting the "master database" after code recompilation, maybe?
How could I set things up so that my scriptable object maintains the Reference Database link? Ideally I wouldn't ever have to drag-and-drop my database into the reference for these scriptable objects, since I only have one database in my project. I don't mind doing a bit of custom code / tweaking if it's required.
Thanks a ton!
Re: "Lua Conditions" only in inspector
Hi,
The [LuaConditionsWizard] attribute doesn't store a reference to the database, since this is just extra data that you don't need at runtime.
However, you could add that. Add a field to your ScriptableObject such as:
Then write a custom editor script for your ScriptableObject, something like:
The [LuaConditionsWizard] attribute doesn't store a reference to the database, since this is just extra data that you don't need at runtime.
However, you could add that. Add a field to your ScriptableObject such as:
Code: Select all
public class MySO : ScriptableObject
{
public DialogueDatabase referenceDatabase;
[LuaConditionsWizard] public string luaConditions;
}
Code: Select all
[CustomEditor(typeof(MySO))]
public class MySOEditor ; Editor
{
public override OnInspectorGUI()
{
EditorTools.selectedDatabase = (target as MySO).referenceDatabase;
EditorTools.SetInitialDatabaseIfNull();
base.OnInspectorGUI();
}
}
Re: "Lua Conditions" only in inspector
Hey Tony, thanks for the response!Tony Li wrote: ↑Thu Sep 21, 2023 9:30 am Hi,
The [LuaConditionsWizard] attribute doesn't store a reference to the database, since this is just extra data that you don't need at runtime.
However, you could add that. Add a field to your ScriptableObject such as:
Then write a custom editor script for your ScriptableObject, something like:Code: Select all
public class MySO : ScriptableObject { public DialogueDatabase referenceDatabase; [LuaConditionsWizard] public string luaConditions; }
Code: Select all
[CustomEditor(typeof(MySO))] public class MySOEditor ; Editor { public override OnInspectorGUI() { EditorTools.selectedDatabase = (target as MySO).referenceDatabase; EditorTools.SetInitialDatabaseIfNull(); base.OnInspectorGUI(); } }
It seems like FindInitialDatabase() (called by SetInitialDatabaseIfNull) is expecting the currently open scene to have a DialogueSystemController. Since I'm working with a ScriptableObject here, I won't usually have a scene open that has one.
Should I make my own custom function similar to FindInitialDatabase(), that just points directly to my database in the Assets folder, and assigns it to EditorTools.selectedDatabase?
Thanks a lot for your help!
Re: "Lua Conditions" only in inspector
Update: Believe I got this working. Sorry if my question/info wasn't very clear!
In my CustomEditor for my Scriptable Object I have:
and then I have this static function in DialogueInterface.cs:
Seems to be working great!
In my CustomEditor for my Scriptable Object I have:
Code: Select all
public override void OnInspectorGUI() {
if (EditorTools.selectedDatabase == null) {
EditorTools.selectedDatabase = DialogueInterface.Editor_GetDialogueDatabaseAsset();
}
base.OnInspectorGUI();
}
Code: Select all
#if UNITY_EDITOR
public static DialogueDatabase Editor_GetDialogueDatabaseAsset() {
return AssetDatabase.LoadAssetAtPath("Assets/Dialogue Database/Dialogue Database.asset", typeof(DialogueDatabase)) as DialogueDatabase;
}
#endif
Re: [SOLVED] "Lua Conditions" only in inspector
Looks good!
Re: [SOLVED] "Lua Conditions" only in inspector
I quickly realized I needed a 'global' way of setting the database reference (things like [VariablePopup] on scripts, etc, wouldn't work since the reference would get lost every time I recompile).
I created an EditorWindow that handles it - it sets the reference OnEnable() and also "afterAssemblyReload". So as long as you have this EditorWindow open, it should maintain the reference.
Note: See my previous response for what DialogueInterface.Editor_GetDialogueDatabaseAsset() is.
Hope it helps anyone that needs it!
I created an EditorWindow that handles it - it sets the reference OnEnable() and also "afterAssemblyReload". So as long as you have this EditorWindow open, it should maintain the reference.
Code: Select all
using PixelCrushers.DialogueSystem;
using UnityEditor;
using UnityEngine;
public class GardenfiendGamesProjectToolsWindow : EditorWindow
{
[MenuItem("Window/Gardenfiend Games/ProjectTools")]
public static void ShowWindow() {
EditorWindow.GetWindow<GardenfiendGamesProjectToolsWindow>("ProjectTools");
}
void OnEnable() {
Debug.Log("PROJECTTOOLS: OnEnable called (assembly reload callback added)");
EnsureDialogueDatabaseStaticReference();
AssemblyReloadEvents.afterAssemblyReload -= OnAfterAssemblyReload;
AssemblyReloadEvents.afterAssemblyReload += OnAfterAssemblyReload;
}
void OnDisable() {
Debug.Log("PROJECTTOOLS: OnDisabled called");
AssemblyReloadEvents.afterAssemblyReload -= OnAfterAssemblyReload;
}
public void OnAfterAssemblyReload() {
Debug.Log("PROJECTTOOLS: OnAfterAssemblyReload");
EnsureDialogueDatabaseStaticReference();
}
public static void EnsureDialogueDatabaseStaticReference() {
if (EditorTools.selectedDatabase == null) {
EditorTools.selectedDatabase = DialogueInterface.Editor_GetDialogueDatabaseAsset();
}
}
}
Hope it helps anyone that needs it!
Re: [SOLVED] "Lua Conditions" only in inspector
Thanks for sharing!