TextTable get Instance

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Thistis
Posts: 27
Joined: Sat Oct 05, 2019 5:05 pm

TextTable get Instance

Post by Thistis »

Hello,
one question about TextTable. How do I get an instance of a TextTable via Code?

In the documentation, it says:

Code: Select all

var hello = myTextTable.GetFieldTextForLanguage("Hello", "FR");
But how do I get the myTextTable? Is there a method to search a TextTable by name?
I couldn't find something fitting in the TextTable class documentation.

All the best,
Evelyn
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: TextTable get Instance

Post by Tony Li »

Hi Evelyn,

A good way is to add a variable to your script that you can assign in the Inspector:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class TestClass : MonoBehaviour
{
    public TextTable myTextTable; // <-- ASSIGN IN INSPECTOR.
    
    private void Start()
    {
        Debug.Log("Text Table " + myTextTable.name + " has " + myTextTable.GetFieldNames().Length + " fields.");
    }
}
Alternatively, you can put the TextTable in a Resources folder and use Resources.Load to load it at runtime:

Code: Select all

TextTable myTextTable = Resources.Load<TextTable>("Your TextTable Asset Name");
Post Reply