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
Adding a Raw Image option to DialogueActor
Re: Adding a Raw Image option to DialogueActor
Hi,
I recommend adding a companion script to each DialogueActor to hold the render texture, such as:
DialogueActorRenderTexture.cs
Then add a script like this to the Dialogue Manager to show the correct actor's render texture with each subtitle:
ShowActorRawImageOnConversationLine.cs
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.
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;
}
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;
}
}
}
}
Re: Adding a Raw Image option to DialogueActor
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.
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.
Re: Adding a Raw Image option to DialogueActor
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:
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);
}
}
Re: Adding a Raw Image option to DialogueActor
Perfect! I wasn't sure how to get the actor with the ActorID, but you just gave me the answer. thanks again!
Re: Adding a Raw Image option to DialogueActor
Glad I could help!