Files
WhaleAdventure_VR/Assets/My project/Dialogue Scripts/UI/DialogueData.cs
skrwns304@gmail.com b1e85a5b89 2026-06-19 UI, UI로직
2026-06-19 14:27:40 +09:00

69 lines
1.4 KiB
C#

using UnityEngine;
[CreateAssetMenu(fileName = "New Dialogue",
menuName = "Dialogue/Dialogue Data")]
public class DialogueData : ScriptableObject
{
public DialogueNode[] nodes;
public bool HasNodes
{
get
{
return nodes != null && nodes.Length > 0;
}
}
public bool IsValidIndex(int index)
{
return nodes != null && index >= 0 && index < nodes.Length;
}
public bool TryGetNode(int index, out DialogueNode node)
{
node = null;
if (!IsValidIndex(index))
return false;
node = nodes[index];
return node != null;
}
public int GetNodeIndexById(string nodeId)
{
if (string.IsNullOrWhiteSpace(nodeId))
return -1;
if (nodes == null)
return -1;
for (int i = 0; i < nodes.Length; i++)
{
if (nodes[i] == null)
continue;
if (nodes[i].nodeId == nodeId)
return i;
}
return -1;
}
#if UNITY_EDITOR
private void OnValidate()
{
if (nodes == null)
return;
for (int i = 0; i < nodes.Length; i++)
{
if (nodes[i] == null)
continue;
if (string.IsNullOrWhiteSpace(nodes[i].nodeId))
nodes[i].nodeId = $"Node_{i:00}";
}
}
#endif
}