Page 1 of 2

How to get the responder's transform?

Posted: Tue Apr 28, 2015 11:23 am
by NyxGen
I'm trying to perform some custom actions when the responses are shown, but these actions differ depending on who the "responding actor" is, as I need to call GetComponent<>() on their GameObject and use some of those MonoBehaviours.



It seems that all of the existing events and overridable methods provide at most an ActorID and ConversantID, but not the actual transforms that are associated with them. Is there something I'm missing, or will I need to hack in a lookup table or something?

How to get the responder's transform?

Posted: Tue Apr 28, 2015 12:31 pm
by Tony Li
Hi,



There are a few easy ways you can do this. One way is to use script messages. Add a script to the Dialogue Manager or one of the conversation participants. In the script, add a method "void OnConversationLine(Subtitle subtitle)". The Subtitle object has all the info about the line. For example:

public void OnConversationLine(Subtitle subtitle) {

var myScript = subtitle.speakerInfo.transform.GetComponent<MyScript>();

// etc....

}





Another way is to make a subclass of your dialogue UI script. You can override the ShowSubtitle() method to do your additional work. The Recipes page has some examples of overriding the dialogue UI.







Another way is to use the SendMessage() sequencer command in the dialogue entry. For example, if your script has a method PlayAnimation(string animationName), you can use this sequencer command:

SendMessage(PlayAnimation, dance, speaker)

This is the equivalent of finding the speaker's GameObject and calling PlayAnimation("dance") on its scripts.







If none of these fit your needs, let me know. There's almost certainly an easy way without having to go to the effort of hacking a lookup table.

How to get the responder's transform?

Posted: Wed Apr 29, 2015 4:20 am
by NyxGen
Hi there~!



Thanks for the response, but I think you might misunderstand my question-- the problem isn't with the displaying of individual subtitle lines (I've already got that working), but with the displaying of the responses.



More specifically, what I'm doing, is providing "dialogue settings" that are specific to each character in the game-- amongst other things, it includes a custom color to use for _all_ dialogue text for that character. I've already got all of the actual subtitle dialogue text properly setting the text color, using the same techniques you described, however I've hit my problem when I've tried to customize the text color appearing on the response buttons.



Like I mentioned earlier, the actual transforms for the actor/conversant aren't provided anywhere that I can see, in any of the overridable methods, event callbacks, etc provided by the Dialogue Plugin during responses (not subtitles! Those work great!). The best I've seen has been the ActorID and ConversantID.

How to get the responder's transform?

Posted: Wed Apr 29, 2015 4:33 am
by Tony Li
Hi,



Thanks for clarifying. I think I understand now. The dialogue UI uses the ShowResponses() method to show the response menu. The signature of this method is:

void ShowResponses (Subtitle subtitle, Response[] responses, float timeout)

The subtitle is the previous line. Assuming that the listener of the previous line is now the responder, can you use the subtitle.listenerInfo.transform?

How to get the responder's transform?

Posted: Wed Apr 29, 2015 5:05 am
by NyxGen
I did actually look into this myself, briefly. Right now, I have things configured to not use "reminder" subtitles, so that parameter comes thru as null; however with my current implementation, it should be safe for me to change things so that I can use it.



The big problem, however, is that I can't necessarily guarantee that the listener of the reminder subtitle is going to be the responder when the responses are shown. In some cases, not only is the player expected to select a response for more than a single character during the course of a single conversation (which was what introduced this issue), but also there may be 3 or more characters involved in a single conversation (which is what necessitates not making assumptions such as this)...

How to get the responder's transform?

Posted: Wed Apr 29, 2015 6:31 am
by Tony Li
Got it. So, for example, say you have three responses. Each response could come from a different character, so the three buttons in the response menu would be colored differently.







Some devs use [em#] tags or rich text color codes in their response text. If you only need to use colors, maybe this would be a simple solution.







If you need to do more, you can get the response's transform like this:

var charID = response.dialogueEntry.ActorID;

var model = DialogueManager.Instance.GetComponent<ConversationModel>();

var charTransform =

(charID == model.ActorInfo.id) ? model.ActorInfo.transform

: (charID == model.ConversantInfo.id) ? model.ConversantInfo.transform

: null;

var charInfo = model.GetCharacterInfo(charID, charTransform);



var myScript = charInfo.transform.GetComponent<MyScript>();

How to get the responder's transform?

Posted: Wed Apr 29, 2015 7:18 am
by NyxGen
That's not exactly what's going on, but it's close enough that it doesn't matter, heh ^^







Ah- that snippet looks like it's exactly what I need, except in the version I've got here, ConversationModel doesn't derive from MonoBehaviour-- is this something that changed recently?







As a side note: is the line model.GetCharacterInfo(charID, charTransform); really necessary? Can't I just use charTransform, or does it do some required internal housekeeping or something?

How to get the responder's transform?

Posted: Wed Apr 29, 2015 7:28 am
by Tony Li
Doh, sorry, I'm not in front of Unity at the moment, and I missed that. I'll expose ConversationModel as a property and send you a patch later today.







I'll also expose the method model.GetCharacterInfo(charID), which is currently a private variation of GetCharacterInfo. It will simplify the code snippet above. It does some housekeeping to cache transforms for characters that aren't the conversation's primary actor or conversant.

How to get the responder's transform?

Posted: Wed Apr 29, 2015 8:21 am
by NyxGen
Awesome, thanks!  I'll look forward to that patch~

How to get the responder's transform?

Posted: Wed Apr 29, 2015 3:37 pm
by Tony Li
Hi,



I just emailed you download links for patch 2015-04-29a, which is also on the Pixel Crushers customer download site.  This patch contains the following:



Sends script message OnConversationResponseMenu(Response[] responses) to the Dialogue Manager.

Exposed DialogueManager.ConversationModel, ConversationView, and ConversationController.

Optimized the Tools.IsPrefab method, which is used to determine if a dialogue UI is a prefab or a scene object.

Fixed: Cross-conversation links weren’t displaying correctly in the editor.







So you can either add a script to the Dialogue Manager that implements OnConversationResponseMenu(Response[] responses) as documented now on the Script Messages page, or override your dialogue UI's ShowResponses method and add code similar to this:

var charID = response.dialogueEntry.ActorID;

var charInfo = DialogueManager.ConversationModel.GetCharacterInfo(charID);



var myScript = charInfo.transform.GetComponent<MyScript>();