Page 1 of 1

Sequencer Command To Set TMP Objects from Dialogue

Posted: Mon Nov 23, 2020 5:41 am
by Keiji
Hey Tony! I was hoping you could help me in the making of two custom sequencer commands for the dialogue system:

I'd like to be able to take a Dialogue System Text or Number Variable and use it to set the text of a TMP Object in the scene from within a conversation sequence.

Something like:

SetTMPUI(TMPObjectname, Variablename);
/
SetTMPUI(PlayerHealthText, Playerhealth);

So I guess the command would have to convert a Dialogue System text or number variable into a string and use it to set the TMP object.

Do you think that is possible in this way?

It would also be great to have the same sequencer command, but have it work with a TMP Object in world space (I am guessing this would need to be a separate command.)

So one could do something like this in a dialogue:

Dialogue: Hey Boss. What should we name our restaurant?

(Sequence:
TextInput(MyTextInputUI,Restaurant Name,RestaurantName); )

Next sequence:
SetTMP3D(TMPObjectname, Variablename);
/
SetTMP3D(RestaurantSign, RestaurantName);

Of course, if it was possible to do it all in one command, that would be the most convenient, I guess! But it looks like TMP itself uses two different ways of setting text, so I'm not sure if that is even possible or efficient.

In that case, the sequencer command could just be called something like SetTMP(TMPObjectname, Variablename).

I have tried it myself, but I am not succeeding. Do you think you help me with this?

Wishing you all the best, and keep up the great work on your Dialogue System asset. It is easily the best asset of the more than 60.000 on the asset store.


Keiji

Re: Sequencer Command To Set TMP Objects from Dialogue

Posted: Mon Nov 23, 2020 10:18 am
by Tony Li
Hi Keiji,

You can do both in one sequencer command:

SequencerCommandSetTMPUI.cs

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{

    // Syntax: SetTMPUI(TMPObjectName, VariableName)
    public class SequencerCommandSetTMPUI : SequencerCommand
    {
        private void Awake()
        {
            var tmpObject = GetSubject(0);
            var variableName = GetParameter(1);
            if (tmpObject == null)
            {
                Debug.LogWarning("SetTMPUI(): Can't find GameObject '" + GetParameter(0) + "'");
            }
            else if (string.IsNullOrEmpty(variableName) || !DialogueLua.DoesVariableExist(variableName))
            {
                Debug.LogWarning("SetTMPUI(): There is no variable named '" + variableName + "'");
            }
            else
            {
                var variableValue = DialogueLua.GetVariable(variableName).asString;
                var tmp = tmpObject.GetComponent<TextMeshPro>();
                var tmpUGUI = tmpObject.GetComponent<TextMeshProUGUI>();
                if (tmp != null)
                {
                    tmp.text = variableValue;
                }
                else if (tmpUGUI != null)
                {
                    tmpUGUI.text = variableValue;
                }
                else
                {
                    Debug.LogWarning("SetTMPUI(): No TextMesh Pro component found on " + tmpObject, tmpObject);
                }
            }
            Stop();
        }
    }
}

Re: Sequencer Command To Set TMP Objects from Dialogue

Posted: Fri Nov 27, 2020 5:01 pm
by Keiji
Wow, it works perfectly! Thanks so much, Tony, this is perfect! Very easy to have the player customize stuff in the level from a conversation now :) Amazing

Re: Sequencer Command To Set TMP Objects from Dialogue

Posted: Fri Nov 27, 2020 5:05 pm
by Tony Li
Great! Happy to help.