Adding a Raw Image option to DialogueActor

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
kev00
Posts: 5
Joined: Tue Jul 30, 2019 1:25 pm

Adding a Raw Image option to DialogueActor

Post by kev00 »

Hi,

All the character portraits in my game are Raw Images. The reason is that I'm using a camera that updates a render texture.

Would it be possible to add a Raw Image option to the DialogueActor?

Or do you have different recommended method?

Thanks
User avatar
Tony Li
Posts: 20651
Joined: Thu Jul 18, 2013 1:27 pm

Re: Adding a Raw Image option to DialogueActor

Post by Tony Li »

Hi,

I recommend adding a companion script to each DialogueActor to hold the render texture, such as:

DialogueActorRenderTexture.cs

Code: Select all

using UnityEngine;
public class DialogueActorRenderTexture : MonoBehaviour
{
    public RenderTexture renderTexture;
}
Then add a script like this to the Dialogue Manager to show the correct actor's render texture with each subtitle:

ShowActorRawImageOnConversationLine.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ShowActorRawImageOnConversationLine : MonoBehaviour
{
    void OnConversationLine(Subtitle subtitle)
    {
        var ui = DialogueManager.dialogueUI as StandardDialogueUI;
        DialogueActor dialogueActor;
        var panel = ui.conversationUIElements.standardSubtitleControls.GetPanel(subtitle, out dialogueActor);
        var rawImage = panel.GetComponentInChildren<UnityEngine.UI.RawImage>();
        var dialogueActorRenderTexture = subtitle.speakerInfo.transform.GetComponent<DialogueActorRenderTexture>();
        if (rawImage != null)
        {
            rawImage.gameObject.SetActive(dialogueActorRenderTexture != null);
            if (dialogueActorRenderTexture != null)
            {
                rawImage.texture = dialogueActorRenderTexture.renderTexture;
            }
        }
    }
}
If your menu panel also uses a PC Image and you want to replace it with a RawImage, you'll need to add an OnConversationResponseMenu() method that works similarly to OnConversationLine() above.
kev00
Posts: 5
Joined: Tue Jul 30, 2019 1:25 pm

Re: Adding a Raw Image option to DialogueActor

Post by kev00 »

Thanks for your help on this. It took me a while to get back to coding this section of my game, but I've implemented what you suggested and I now have Camera rendered raw images in the dialog ui.

I didn't end up using DialogActorRenderTexture script since I have a singleton that provides my characters portrait rendertexture, but using OnConversationResponseMenu and OnConversationLine really helped.

Using OnConversationLine was easy, but I did notice that I couldn't put the Raw image under "Subtitle Panel Info" since the background I'm using on "Main Panel" covered it. I had to place the raw image under the main panel and pull it in using ui.conversationUIElements.mainPanel

At this point, I just need to iterate over the responses passed into OnConversationResponseMenu and set a raw image for each Character speaking (the player controls multiple characters). It looks like I will have to add a raw image to the "Response Button Template". At the moment I'm just pulling in the speaker using DialogueManager.CurrentActor.
User avatar
Tony Li
Posts: 20651
Joined: Thu Jul 18, 2013 1:27 pm

Re: Adding a Raw Image option to DialogueActor

Post by Tony Li »

Sounds good.

You can make a subclass of the StandardUIResponseButton class to assign your RawImage.

In OnConversationResponseMenu, you can also get the speaker by checking responses[x].destinationEntry.ActorID. It's a bit roundabout, but something like this could work:

Code: Select all

void OnConversationResponseMenu(Response[] responses)
 {
     foreach (var response in responses)
     {
         var responseActorID = response.destinationEntry.ActorID;
         var responseActor = DialogueManager.masterDatabase.GetActor(responseActorID);
         Debug.Log("Response " + response.formattedText.text + " is spoken by " + responseActor.Name);
     }
 }
kev00
Posts: 5
Joined: Tue Jul 30, 2019 1:25 pm

Re: Adding a Raw Image option to DialogueActor

Post by kev00 »

Perfect! I wasn't sure how to get the actor with the ActorID, but you just gave me the answer. thanks again!
User avatar
Tony Li
Posts: 20651
Joined: Thu Jul 18, 2013 1:27 pm

Re: Adding a Raw Image option to DialogueActor

Post by Tony Li »

Glad I could help!
Post Reply