2026-04-24 캐릭터 상호작용

This commit is contained in:
2026-04-24 17:46:29 +09:00
parent 305a911524
commit 752b891a48
6 changed files with 51 additions and 21 deletions

Binary file not shown.

View File

@@ -8,6 +8,7 @@ public class DialogPlayer : MonoBehaviour
[SerializeField] private List<DialogGroup> _dialogGroups; [SerializeField] private List<DialogGroup> _dialogGroups;
private Dictionary<string, DialogGroup> _dialogGroupMap; private Dictionary<string, DialogGroup> _dialogGroupMap;
private Animator _animator; private Animator _animator;
public bool IsPlaying { get; private set; }
private void Awake() private void Awake()
{ {
@@ -18,36 +19,44 @@ private void Awake()
_animator = GetComponentInChildren<Animator>(); _animator = GetComponentInChildren<Animator>();
} }
// 임시 테스트용 public async Awaitable Play()
private void Update()
{ {
if (Keyboard.current != null && Keyboard.current.tKey.wasPressedThisFrame) if(_dialogGroups.Count > 0)
_ = Play("BlackDialogGroup1"); _ = Play(_dialogGroups[0].DialogGroupName);
} }
public async Awaitable Play(string groupName) public async Awaitable Play(string groupName)
{ {
if (IsPlaying) return;
if (!_dialogGroupMap.TryGetValue(groupName, out var group)) if (!_dialogGroupMap.TryGetValue(groupName, out var group))
{ {
Debug.LogWarning($"[DialogPlayer] 그룹 없음: {groupName}"); Debug.LogWarning($"[DialogPlayer] 그룹 없음: {groupName}");
return; return;
} }
var node = group.StartNode; IsPlaying = true;
while (node != null) try
{ {
await PlayNode(node); var node = group.StartNode;
while (node != null)
{
await PlayNode(node);
if (node.Choices != null && node.Choices.Count > 0) if (node.Choices != null && node.Choices.Count > 0)
{ {
int picked = await WaitForChoice(node); int picked = await WaitForChoice(node);
node = node.Choices[picked].DestinationNode; node = node.Choices[picked].DestinationNode;
} }
else else
{ {
node = node.Next; node = node.Next;
}
} }
} }
finally
{
IsPlaying = false;
}
Debug.Log("[DialogPlayer] 대화 종료"); Debug.Log("[DialogPlayer] 대화 종료");
} }

View File

@@ -0,0 +1,19 @@
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
[RequireComponent(typeof(DialogPlayer))]
public class DialogInteractable : MonoBehaviour
{
private DialogPlayer _player;
private void Awake()
{
_player = GetComponent<DialogPlayer>();
}
public void HandleActivated(ActivateEventArgs args)
{
if (_player == null || _player.IsPlaying) return;
_ = _player.Play();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a8a22189f0d1e5448bf3e44657410176

Binary file not shown.