Page 1 of 1

How do you search for a field with a specific value?

Posted: Sun Jul 07, 2019 6:47 pm
by AoF
I see the search/replace section in the database but I don't know how to use it for this. I have this custom field named "energyCost". It's on every node. I want to find every node where it has a value > 0. How would I find every node like that?

Re: How do you search for a field with a specific value?

Posted: Sun Jul 07, 2019 8:47 pm
by Tony Li
There's nothing built into the editor that handles conditional searching like that. But you could write a short editor script like this:

Code: Select all

using UnityEngine;
using UnityEditor;
using PixelCrushers.DialogueSystem;

public class FindNode : MonoBehaviour
{
    [MenuItem("Tools/Find energyCost")]
    public static void FindEnergyCost()
    {
        var database = EditorTools.FindInitialDatabase();
        if (database == null)
        {
            Debug.LogWarning("First open a scene with a Dialogue Manager that points to the database.");
        }
        else
        {
            foreach (var conversation in database.conversations)
            {
                foreach (var entry in conversation.dialogueEntries)
                {
                    var energyCost = Field.LookupInt(entry.fields, "energyCost");
                    if (energyCost > 0)
                    {
                        Debug.Log("Conversation " + conversation.Title +
                            " Entry " + entry.id + " (" + entry.subtitleText + "): " +
                            " energyCost = " + energyCost);
                    }
                }
            }
        }
    }
}
Then open a scene with a Dialogue Manager, and select menu item Tools > Find energyCost.

Re: How do you search for a field with a specific value?

Posted: Sun Jul 07, 2019 8:50 pm
by AoF
OK, thanks for the help.