Page 1 of 1
Alternate focus on NPC portrait images
Posted: Wed Aug 24, 2022 1:28 am
by Dabsco
Hello!
I am sure this is a simple fix, but for the life of me I cannot find the answer here or figure it out myself.
I would like to alternate focus on 2 NPCs as they converse with the PC.
The fade works great, but the new NPC image remains on the topmost layer as shown in images.
I am using the VN template, and have assigned NPC 2 to Panel 2, which I don't think is a great solution given in the future there will be multiple conversations with multiple NPCs, and at times they will take the primary position...
Any pointers appreciated!!
- Image 1.jpg (49.09 KiB) Viewed 773 times
- Image 2.jpg (39.79 KiB) Viewed 773 times
- Image 3.jpg (52.73 KiB) Viewed 773 times
Re: Alternate focus on NPC portrait images
Posted: Wed Aug 24, 2022 8:14 am
by Tony Li
Hi,
I want to make sure I understand what you're asking.
The NPC is who speaking has focus, and the other NPCs are faded to a darker tint.
However, you also want the NPC who has focus to be rendered on top of the other portraits, correct? For example, in the third image, the NPC holding the paper is darkened, but he is rendered on top of the focused NPC (Cacey) and covers the focused NPC's elbow. Instead, you want the focused NPC to be on top so that his elbow is not covered?
Re: Alternate focus on NPC portrait images
Posted: Wed Aug 24, 2022 6:16 pm
by Dabsco
Hello!
Yes that's correct. I would like them to be the topmost image when they are in focus.
This example isn't great because it is only the elbow, but I will have others which are more crowded.
D
Re: Alternate focus on NPC portrait images
Posted: Wed Aug 24, 2022 8:40 pm
by Tony Li
Hi,
You can put all of your portrait images on the same hierarchy level in your dialogue UI, and add a small script like this to your subtitle panels:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
[RequireComponent(typeof(StandardUISubtitlePanel))]
public class BringToFrontOnFocus : MonoBehaviour
{
private StandardUISubtitlePanel panel;
private void Awake()
{
panel = GetComponent<StandardUISubtitlePanel>();
}
private void Start()
{
panel.onFocus.AddListener(BringPortraitToFront);
}
private void BringPortraitToFront()
{
panel.portraitImage.transform.SetAsLastSibling();
}
}
Here's an example scene:
DS_VNBringToFrontExample_2022-08-24.unitypackage
It's a copy of one of the VN example scenes on the Extras page, but I moved the portraits to the same hierarchy level (in a GameObject named "Portraits") and added the script above to the subtitle panels.
Re: Alternate focus on NPC portrait images
Posted: Fri Aug 26, 2022 2:23 am
by Dabsco
Thanks Tony,
I have included the script and childed the portraits, and the layering seems to be working well now, if a little abrupt.
However the darkening of the portraits is no longer working?
Image shows what I mean and also the portraits in hierarchy.
What have I done here?
- No darkening image.jpg (446.19 KiB) Viewed 741 times
Re: Alternate focus on NPC portrait images
Posted: Fri Aug 26, 2022 8:44 am
by Tony Li
Hi,
Since they're sprites, there's only "in front of" or "behind". I'm not sure how you'd make it less abrupt, unless you were perhaps to do some kind of temporary blending of the portraits, but I don't think that would actually look good.
I forgot about the animation. The dark/light fading is handled by animations. In Unity, animations work on GameObjects in a hierarchy. Since the hierarchy was changed (moving the portraits to be children of a shared GameObject), the current animation isn't able to work with it. This should work:
1. Move the portrait images
back to their original places as children of Subtitle Panel 0, Subtitle Panel 1, etc., so the animations will work again.
2. Put the entire Subtitle Panel 0, Subtitle Panel 1, etc., GameObjects in a shared GameObject instead.
3. Make this small change to the script:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
[RequireComponent(typeof(StandardUISubtitlePanel))]
public class BringToFrontOnFocus : MonoBehaviour
{
private StandardUISubtitlePanel panel;
private void Awake()
{
panel = GetComponent<StandardUISubtitlePanel>();
}
private void Start()
{
panel.onFocus.AddListener(BringPortraitToFront);
}
private void BringPortraitToFront()
{
panel.transform.SetAsLastSibling(); //<-- THIS CHANGE.
}
}
Re: Alternate focus on NPC portrait images
Posted: Tue Aug 30, 2022 10:58 pm
by Dabsco
Thanks Tony!
Looking good now. I wonder if this is something others might want in their visual novel set up?
I'll keep going with the game and no doubt be in touch again if I hit another road bump - thanks again!!
Cheers!
Re: Alternate focus on NPC portrait images
Posted: Wed Aug 31, 2022 7:53 am
by Tony Li
Good thinking. I'll add this to the VN template prefab.