Good day
I am busy making a dialogue node tree system, using Localized Strings as part. I have created a DialogueNode class to represent the nodes in the tree.
namespace Dialogue
{
[Serializable]
public class DialogueNode
{
public TableEntryReference stringId;
public LocalizedString dialogueString;
[SerializeReference]
public List<LocalizedString> childStrings = new List<LocalizedString>();
}
}
After which, I created a scriptable object to create the different node trees.
namespace Dialogue
{
[CreateAssetMenu(fileName = "Dialogue", menuName = "New Revalo Dialogue", order = 0)]
public class Dialogue : ScriptableObject
{
[SerializeField]
private List<DialogueNode> _Nodes = new List<DialogueNode>();
#if UNITY_EDITOR
private void Awake()
{
if(_Nodes.Count == 0)
{
_Nodes.Add(new DialogueNode());
}
}
#endif
public IEnumerable<DialogueNode> GetAllNodes()
{
return _Nodes;
}
void OnValidate()
{
foreach(DialogueNode node in _Nodes)
{
if (node.dialogueString != null)
{
node.stringId = node.dialogueString.TableEntryReference;
}
}
}
}
}
I am then displaying in a custom editor window to edit and change the nodes. I have created the ability to change the content of the main localized string in the node through the editor; however, for the child strings/nodes, that will be the following options in the dialogue. I would just like to display the localized string editor as seen in the inspector. I have attempted to do so via a property field, but I am not successful, and all the topics that I have found are for older versions, where I am unsure if the solutions provided are still the same, as I have not had success in implementing them.
namespace Dialogue.Editor
{
public class DialogueEditor : EditorWindow
{
Dialogue selectedDialogue = null;
StringTable tableRef;
LocalizedString childString;
[MenuItem("Window/Dialogue Editor")]
public static void ShowEditorWindow()
{
GetWindow(typeof(DialogueEditor), false, "Dialogue Editor");
}
[OnOpenAssetAttribute(1)]
public static bool OnOpenAsset(int instanceID, int line)
{
Dialogue dialogue = EditorUtility.InstanceIDToObject(instanceID) as Dialogue;
if (dialogue != null)
{
ShowEditorWindow();
return true;
}
return false;
}
private void OnEnable()
{
Selection.selectionChanged += OnSelectionChange;
}
private void OnDisable()
{
Selection.selectionChanged -= OnSelectionChange;
}
private void OnSelectionChange()
{
Dialogue dialogue = Selection.activeObject as Dialogue;
if(dialogue != null)
{
selectedDialogue = dialogue;
tableRef = LocalizationSettings.StringDatabase.GetTable("LocalStrings", LocalizationSettings.SelectedLocale);
//EditorUtility.SetDirty(tableRef);
//EditorUtility.SetDirty(tableRef.SharedData);
Repaint();
}
}
private void OnGUI()
{
if(selectedDialogue == null)
{
EditorGUILayout.LabelField("No Dialogue Selected");
}
else
{
foreach(DialogueNode node in selectedDialogue.GetAllNodes())
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.LabelField("Node:");
string NewDialogue = EditorGUILayout.TextField(node.dialogueString.GetLocalizedString());
for(int i = 0; i <= node.childStrings.Count -1; i++)
{
childString = node.childStrings[i];
EditorGUILayout.PropertyField(new SerializedObject(this).FindProperty("childString"));
}
if(NewDialogue != null && EditorGUI.EndChangeCheck())
{
Undo.RecordObject(tableRef, "Table String Update");
tableRef.AddEntry(node.stringId.KeyId, NewDialogue);
//AssetDatabase.SaveAssetIfDirty(tableRef);
//AssetDatabase.SaveAssetIfDirty(tableRef.SharedData);
}
}
}
}
}
}






