suppress world interaction while a menu panel is open
DialogueInteractable, DialogueTransitionController, and DialogueUIVisibility are reworked against the new UI layer: visibility is driven by UIStateController rather than each component toggling canvases itself, which removes the duplicated show/hide logic the two had accumulated. NPCStandIn now ignores the interact button while UIStateController reports a menu open, so pressing interact through an open panel no longer starts a conversation behind it. The yarnproject change is graph-editor node positions only. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using StarterAssets;
|
||||
using NightclubArcadia.UI;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
@@ -7,33 +7,27 @@ namespace NightclubArcadia.Dialogue
|
||||
/// <summary>
|
||||
/// Owns the hand-off between dialogue and the 3D environment: locks the
|
||||
/// player's controls for as long as a conversation is running, and registers
|
||||
/// the <<enter_environment>> Yarn command that hands control back.
|
||||
/// the <<enter_environment>> Yarn command that hands control back.
|
||||
///
|
||||
/// The lock is driven by the DialogueRunner's own lifecycle events rather
|
||||
/// than by each interactable, so every entry point — auto-started nodes,
|
||||
/// NPCStandIn, DialogueInteractable — gets the same behaviour without
|
||||
/// having to remember to do it.
|
||||
/// having to remember to do it. Control locking is delegated to
|
||||
/// <see cref="PlayerControlLock"/> so the player menu can hold a second
|
||||
/// independent lock without re-enabling movement mid-conversation.
|
||||
/// </summary>
|
||||
public class DialogueTransitionController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private DialogueRunner dialogueRunner;
|
||||
[SerializeField] private GameObject dialogueUI;
|
||||
[SerializeField] private GameObject playerArmature;
|
||||
|
||||
private ThirdPersonController playerController;
|
||||
private StarterAssetsInputs playerInputs;
|
||||
private Animator playerAnimator;
|
||||
|
||||
static readonly int AnimIDSpeed = Animator.StringToHash("Speed");
|
||||
static readonly int AnimIDMotionSpeed = Animator.StringToHash("MotionSpeed");
|
||||
[SerializeField] private PlayerControlLock controlLock;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (playerArmature != null)
|
||||
if (controlLock == null && playerArmature != null)
|
||||
{
|
||||
playerController = playerArmature.GetComponent<ThirdPersonController>();
|
||||
playerInputs = playerArmature.GetComponent<StarterAssetsInputs>();
|
||||
playerAnimator = playerArmature.GetComponent<Animator>();
|
||||
controlLock = playerArmature.GetComponent<PlayerControlLock>();
|
||||
}
|
||||
|
||||
// Subscribed in Awake rather than Start: the runner auto-starts its
|
||||
@@ -45,11 +39,16 @@ namespace NightclubArcadia.Dialogue
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (controlLock == null && playerArmature != null)
|
||||
{
|
||||
controlLock = playerArmature.GetComponent<PlayerControlLock>();
|
||||
}
|
||||
|
||||
// Dialogue is in progress as soon as this controller is active
|
||||
// (including auto-started nodes), so the player stays locked out
|
||||
// until <<enter_environment>>. The armature itself stays
|
||||
// active/visible — only its controls are disabled.
|
||||
SetPlayerControlEnabled(false);
|
||||
controlLock?.Acquire(this);
|
||||
|
||||
dialogueRunner.AddCommandHandler("enter_environment", EnterEnvironment);
|
||||
}
|
||||
@@ -63,7 +62,8 @@ namespace NightclubArcadia.Dialogue
|
||||
void OnDialogueStart()
|
||||
{
|
||||
DialogueUIVisibility.Show(dialogueUI);
|
||||
SetPlayerControlEnabled(false);
|
||||
UIStateController.Instance?.SetDialogueActive(true);
|
||||
controlLock?.Acquire(this);
|
||||
}
|
||||
|
||||
// Safety net: a node that ends without <<enter_environment>> must still
|
||||
@@ -74,40 +74,12 @@ namespace NightclubArcadia.Dialogue
|
||||
{
|
||||
// Hide, don't deactivate: deactivating the Canvas breaks TMP's
|
||||
// cached Canvas reference and makes the next conversation throw.
|
||||
// See DialogueUIVisibility.
|
||||
// See DialogueUIVisibility / PanelVisibility.
|
||||
DialogueUIVisibility.Hide(dialogueUI);
|
||||
SetPlayerControlEnabled(true);
|
||||
}
|
||||
|
||||
void SetPlayerControlEnabled(bool value)
|
||||
{
|
||||
if (playerController == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!value)
|
||||
{
|
||||
// Clear pending input and the locomotion blend before freezing
|
||||
// the controller. Disabling it mid-stride otherwise leaves
|
||||
// Speed at its last value, and the character keeps running on
|
||||
// the spot for the whole conversation.
|
||||
if (playerInputs != null)
|
||||
{
|
||||
playerInputs.MoveInput(Vector2.zero);
|
||||
playerInputs.LookInput(Vector2.zero);
|
||||
playerInputs.SprintInput(false);
|
||||
playerInputs.JumpInput(false);
|
||||
}
|
||||
|
||||
if (playerAnimator != null)
|
||||
{
|
||||
playerAnimator.SetFloat(AnimIDSpeed, 0f);
|
||||
playerAnimator.SetFloat(AnimIDMotionSpeed, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
playerController.enabled = value;
|
||||
UIStateController.Instance?.SetDialogueActive(false);
|
||||
// Release is idempotent on a HashSet — safe when both
|
||||
// <<enter_environment>> and onDialogueComplete fire.
|
||||
controlLock?.Release(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user