126 lines
3.6 KiB
C#
126 lines
3.6 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Example script showing how to use the Quest Manager system
|
|
/// </summary>
|
|
public class QuestExample : MonoBehaviour
|
|
{
|
|
[Header("Example Quest Usage")]
|
|
[SerializeField] private string exampleQuestId = "kill_wolves";
|
|
[SerializeField] private string objectiveId = "kill_objective";
|
|
|
|
void Start()
|
|
{
|
|
// Subscribe to quest events
|
|
if (QuestManager.Instance != null)
|
|
{
|
|
QuestManager.Instance.OnQuestStarted += OnQuestStarted;
|
|
QuestManager.Instance.OnQuestCompleted += OnQuestCompleted;
|
|
QuestManager.Instance.OnObjectiveProgressed += OnObjectiveProgressed;
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// Example: Test quest functionality with keyboard inputs
|
|
if (Input.GetKeyDown(KeyCode.Q))
|
|
{
|
|
StartExampleQuest();
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.P))
|
|
{
|
|
ProgressExampleObjective();
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.C))
|
|
{
|
|
CompleteExampleQuest();
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.A))
|
|
{
|
|
AbandonExampleQuest();
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.S))
|
|
{
|
|
CheckQuestStatus();
|
|
}
|
|
}
|
|
|
|
// Example methods for quest management
|
|
public void StartExampleQuest()
|
|
{
|
|
if (QuestManager.Instance != null)
|
|
{
|
|
bool success = QuestManager.Instance.StartQuest(exampleQuestId);
|
|
Debug.Log($"Start quest result: {success}");
|
|
}
|
|
}
|
|
|
|
public void ProgressExampleObjective()
|
|
{
|
|
if (QuestManager.Instance != null)
|
|
{
|
|
bool success = QuestManager.Instance.ProgressObjective(exampleQuestId, objectiveId, 1);
|
|
Debug.Log($"Progress objective result: {success}");
|
|
}
|
|
}
|
|
|
|
public void CompleteExampleQuest()
|
|
{
|
|
if (QuestManager.Instance != null)
|
|
{
|
|
bool success = QuestManager.Instance.CompleteQuest(exampleQuestId);
|
|
Debug.Log($"Complete quest result: {success}");
|
|
}
|
|
}
|
|
|
|
public void AbandonExampleQuest()
|
|
{
|
|
if (QuestManager.Instance != null)
|
|
{
|
|
bool success = QuestManager.Instance.AbandonQuest(exampleQuestId);
|
|
Debug.Log($"Abandon quest result: {success}");
|
|
}
|
|
}
|
|
|
|
public void CheckQuestStatus()
|
|
{
|
|
if (QuestManager.Instance != null)
|
|
{
|
|
var status = QuestManager.Instance.GetQuestStatus(exampleQuestId);
|
|
var progress = QuestManager.Instance.GetObjectiveProgress(exampleQuestId, objectiveId);
|
|
Debug.Log($"Quest Status: {status}, Objective Progress: {progress}");
|
|
}
|
|
}
|
|
|
|
// Event handlers
|
|
private void OnQuestStarted(Quest quest)
|
|
{
|
|
Debug.Log($"Quest Started: {quest.questName}");
|
|
}
|
|
|
|
private void OnQuestCompleted(Quest quest)
|
|
{
|
|
Debug.Log($"Quest Completed: {quest.questName}");
|
|
}
|
|
|
|
private void OnObjectiveProgressed(Quest quest, QuestObjective objective)
|
|
{
|
|
Debug.Log($"Objective Progress: {quest.questName} - {objective.description} ({objective.currentAmount}/{objective.targetAmount})");
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
// Unsubscribe from events
|
|
if (QuestManager.Instance != null)
|
|
{
|
|
QuestManager.Instance.OnQuestStarted -= OnQuestStarted;
|
|
QuestManager.Instance.OnQuestCompleted -= OnQuestCompleted;
|
|
QuestManager.Instance.OnObjectiveProgressed -= OnObjectiveProgressed;
|
|
}
|
|
}
|
|
}
|