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