Page 1 of 1

TextTable get Instance

Posted: Tue Oct 15, 2019 5:40 pm
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

Re: TextTable get Instance

Posted: Tue Oct 15, 2019 7:29 pm
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");