Introduced dialogue graph magic, created assest and importers. Added events for broadcasting puzzle steps
This commit is contained in:
3
Assets/Scripts/Dialogue.meta
Normal file
3
Assets/Scripts/Dialogue.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e592597a12a7498dbb5336395d7db00c
|
||||
timeCreated: 1758871403
|
||||
63
Assets/Scripts/Dialogue/DialogueComponent.cs
Normal file
63
Assets/Scripts/Dialogue/DialogueComponent.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Dialogue
|
||||
{
|
||||
public class DialogueComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private RuntimeDialogueGraph runtimeGraph;
|
||||
private Dictionary<string, RuntimeDialogueNode> _nodeLookup = new Dictionary<string, RuntimeDialogueNode>();
|
||||
private RuntimeDialogueNode _currentNode;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
foreach (var node in runtimeGraph.allNodes)
|
||||
{
|
||||
_nodeLookup[node.nodeID] = node;
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(runtimeGraph.entryNodeID))
|
||||
{
|
||||
EndDialogue();
|
||||
return;
|
||||
}
|
||||
|
||||
ShowNode(runtimeGraph.entryNodeID);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(Mouse.current.leftButton.wasPressedThisFrame && _currentNode != null)
|
||||
{
|
||||
if(string.IsNullOrEmpty(_currentNode.nextNodeID))
|
||||
{
|
||||
EndDialogue();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowNode(_currentNode.nextNodeID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowNode(string nodeID)
|
||||
{
|
||||
if (!_nodeLookup.ContainsKey(nodeID))
|
||||
{
|
||||
EndDialogue();
|
||||
return;
|
||||
}
|
||||
|
||||
_currentNode = _nodeLookup[nodeID];
|
||||
Debug.Log($"{runtimeGraph.speakerName}: {_currentNode.dialogueLine}");
|
||||
}
|
||||
|
||||
private void EndDialogue()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Dialogue/DialogueComponent.cs.meta
Normal file
3
Assets/Scripts/Dialogue/DialogueComponent.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 749c3dece1c14b82845c175203a2e7dc
|
||||
timeCreated: 1758873871
|
||||
22
Assets/Scripts/Dialogue/RuntimeDialogueGraph.cs
Normal file
22
Assets/Scripts/Dialogue/RuntimeDialogueGraph.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Dialogue
|
||||
{
|
||||
[Serializable]
|
||||
public class RuntimeDialogueGraph : ScriptableObject
|
||||
{
|
||||
public string entryNodeID;
|
||||
public string speakerName;
|
||||
public List<RuntimeDialogueNode> allNodes = new List<RuntimeDialogueNode>();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class RuntimeDialogueNode
|
||||
{
|
||||
public string nodeID;
|
||||
public string dialogueLine;
|
||||
public string nextNodeID;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Dialogue/RuntimeDialogueGraph.cs.meta
Normal file
3
Assets/Scripts/Dialogue/RuntimeDialogueGraph.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c3be3596532450a923c31dfe0ed4aa9
|
||||
timeCreated: 1758871423
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using PuzzleS;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System; // added for Action<T>
|
||||
|
||||
/// <summary>
|
||||
/// Manages puzzle step registration, dependency management, and step completion for the puzzle system.
|
||||
@@ -32,6 +33,10 @@ public class PuzzleManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Events to notify about step lifecycle
|
||||
public event Action<PuzzleStepSO> StepCompleted;
|
||||
public event Action<PuzzleStepSO> StepUnlocked;
|
||||
|
||||
private HashSet<PuzzleStepSO> completedSteps = new HashSet<PuzzleStepSO>();
|
||||
private HashSet<PuzzleStepSO> unlockedSteps = new HashSet<PuzzleStepSO>();
|
||||
|
||||
@@ -122,6 +127,10 @@ public class PuzzleManager : MonoBehaviour
|
||||
if (completedSteps.Contains(step)) return;
|
||||
completedSteps.Add(step);
|
||||
Debug.Log($"[Puzzles] Step completed: {step.stepId}");
|
||||
|
||||
// Broadcast completion
|
||||
StepCompleted?.Invoke(step);
|
||||
|
||||
foreach (var unlock in step.unlocks)
|
||||
{
|
||||
if (AreRuntimeDependenciesMet(unlock))
|
||||
@@ -165,6 +174,9 @@ public class PuzzleManager : MonoBehaviour
|
||||
behaviour.UnlockStep();
|
||||
}
|
||||
Debug.Log($"[Puzzles] Step unlocked: {step.stepId}");
|
||||
|
||||
// Broadcast unlock
|
||||
StepUnlocked?.Invoke(step);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user