2026-06-19 UI, UI로직
This commit is contained in:
69
Assets/My project/Dialogue Scripts/UI/DialogueData.cs
Normal file
69
Assets/My project/Dialogue Scripts/UI/DialogueData.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user