uChema
4 年前
当前提交
964f7361
共有 17 个文件被更改,包括 505 次插入 和 373 次删除
-
27UOP1_Project/Assets/Scenes/Gameplay.unity
-
9UOP1_Project/Assets/Scenes/TestingGround.unity
-
12UOP1_Project/Assets/Scripts/Quests/ScriptableObjects/QuestSO.cs
-
198UOP1_Project/Assets/Scripts/Quests/StepController.cs
-
2UOP1_Project/Assets/Scripts/Quests/QuestAncorSO.cs.meta
-
2UOP1_Project/Assets/Scripts/UI/UIDialogueChoiceFiller.cs
-
20UOP1_Project/Assets/QuestManager.cs
-
11UOP1_Project/Assets/QuestManager.cs.meta
-
17UOP1_Project/Assets/ScriptableObjects/Quests/Quest1/Questline.asset
-
8UOP1_Project/Assets/ScriptableObjects/Quests/Quest1/Questline.asset.meta
-
24UOP1_Project/Assets/Scripts/Quests/QuestAnchor.asset
-
8UOP1_Project/Assets/Scripts/Quests/QuestAnchor.asset.meta
-
302UOP1_Project/Assets/Scripts/Quests/QuestAncorSO.cs
-
20UOP1_Project/Assets/Scripts/Quests/ScriptableObjects/QuestlineSO.cs
-
11UOP1_Project/Assets/Scripts/Quests/ScriptableObjects/QuestlineSO.cs.meta
-
207UOP1_Project/Assets/Scripts/Quests/QuestManager.cs
-
0/UOP1_Project/Assets/Scripts/Quests/QuestAncorSO.cs.meta
9
UOP1_Project/Assets/Scenes/TestingGround.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class QuestManager : MonoBehaviour |
|||
{ |
|||
|
|||
[SerializeField] private QuestAncorSO _questAnchor = default; |
|||
// Start is called before the first frame update
|
|||
void Start() |
|||
{ |
|||
_questAnchor.StartGame(); |
|||
} |
|||
|
|||
// Update is called once per frame
|
|||
void Update() |
|||
{ |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d3b99813ebb688d4ea1c24c7ac430cdc |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: b4f9c8aa1ce987b4799f7093a99181a9, type: 3} |
|||
m_Name: Questline |
|||
m_EditorClassIdentifier: |
|||
_quests: |
|||
- {fileID: 11400000, guid: 4235b642a3ad91341a7cb42c6851293f, type: 2} |
|||
_isDone: 0 |
|
|||
fileFormatVersion: 2 |
|||
guid: 8fd63124ea38bb24bb4263fda8d06ab3 |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: bcc67b9fd1ae89449a1734139485f3b2, type: 3} |
|||
m_Name: QuestAnchor |
|||
m_EditorClassIdentifier: |
|||
_questlines: |
|||
- {fileID: 11400000, guid: 8fd63124ea38bb24bb4263fda8d06ab3, type: 2} |
|||
_inventory: {fileID: 11400000, guid: 59c84467f7726dc4587a8373b0936f03, type: 2} |
|||
_checkStepValidityEvent: {fileID: 11400000, guid: 6711182c372e2e94a8bd3fd1868223ec, |
|||
type: 2} |
|||
_endDialogueEvent: {fileID: 11400000, guid: b8f14d59bc3b10e4f9bdf1e65c3c6280, type: 2} |
|||
_winDialogueEvent: {fileID: 11400000, guid: dc2da1754c28ab9499cb6c7d72465e69, type: 2} |
|||
_loseDialogueEvent: {fileID: 11400000, guid: fcc99784052e5cc469b8c22c0674b051, type: 2} |
|||
_giveItemEvent: {fileID: 11400000, guid: c54b320c4205f1c49b296b878daf2097, type: 2} |
|||
_rewardItemEvent: {fileID: 11400000, guid: ceeec59dc461abd4f91dac5b07084d24, type: 2} |
|
|||
fileFormatVersion: 2 |
|||
guid: dacb138678b7c2344b59c68de5dc18db |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
[CreateAssetMenu(fileName = "QuestAnchor", menuName = "Quests/QuestAnchor", order = 51)] |
|||
public class QuestAncorSO : ScriptableObject |
|||
{ |
|||
[Header("Data")] |
|||
[SerializeField] private List<QuestlineSO> _questlines = default; |
|||
[SerializeField] private Inventory _inventory = default; |
|||
|
|||
|
|||
|
|||
[Header("Linstening to channels")] |
|||
[SerializeField] private VoidEventChannelSO _checkStepValidityEvent = default; |
|||
[SerializeField] private DialogueDataChannelSO _endDialogueEvent = default; |
|||
//[SerializeField] private DialogueActorChannelSO _checkForQuest = default;
|
|||
|
|||
[Header("Broadcasting on channels")] |
|||
//[SerializeField] private StepChannelSO _startStepEvent = default;
|
|||
|
|||
//[SerializeField] private VoidEventChannelSO _endStepEvent = default;
|
|||
|
|||
[SerializeField] private VoidEventChannelSO _winDialogueEvent = default; |
|||
[SerializeField] private VoidEventChannelSO _loseDialogueEvent = default; |
|||
|
|||
[SerializeField] private ItemEventChannelSO _giveItemEvent = default; |
|||
[SerializeField] private ItemEventChannelSO _rewardItemEvent = default; |
|||
|
|||
private QuestSO _currentQuest=null; |
|||
private QuestlineSO _currentQuestline; |
|||
private StepSO _currentStep; |
|||
private int _currentQuestIndex = 0; |
|||
private int _currentQuestlineIndex = 0; |
|||
private int _currentStepIndex = 0; |
|||
|
|||
public void StartGame() |
|||
{//Add code for saved information
|
|||
if (_checkStepValidityEvent != null) |
|||
{ |
|||
_checkStepValidityEvent.OnEventRaised += CheckStepValidity; |
|||
} |
|||
if (_endDialogueEvent != null) |
|||
{ |
|||
_endDialogueEvent.OnEventRaised += EndDialogue; |
|||
} |
|||
StartQuestline(); |
|||
} |
|||
void StartQuestline() |
|||
{ |
|||
if (_questlines != null) |
|||
{ |
|||
if (_questlines.Exists(o => !o.IsDone)) |
|||
{ |
|||
_currentQuestlineIndex = _questlines.FindIndex(o => !o.IsDone); |
|||
if (_currentQuestlineIndex >= 0) |
|||
_currentQuestline = _questlines.Find(o => !o.IsDone); |
|||
} |
|||
|
|||
} |
|||
} |
|||
bool hasStep(ActorSO actorToCheckWith) |
|||
{ |
|||
if(_currentStep!=null) |
|||
{ |
|||
|
|||
if(_currentStep.Actor== actorToCheckWith) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
} |
|||
return false; |
|||
|
|||
} |
|||
bool CheckQuestlineForQuestWithActor(ActorSO actorToCheckWith) |
|||
{ |
|||
if (_currentQuest == null)//check if there's a current quest
|
|||
{ |
|||
if (_currentQuestline != null) |
|||
{ |
|||
|
|||
return _currentQuestline.Quests.Exists(o => !o.IsDone && o.Steps != null && o.Steps[0].Actor == actorToCheckWith); |
|||
|
|||
} |
|||
|
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public DialogueDataSO InteractWithCharacter(ActorSO actor, bool isCheckValidity, bool isValid) |
|||
{ |
|||
|
|||
if (_currentQuest == null) |
|||
{ |
|||
if (CheckQuestlineForQuestWithActor(actor)) |
|||
{ |
|||
StartQuest(actor); |
|||
} |
|||
|
|||
} |
|||
|
|||
if (hasStep(actor)) |
|||
{ |
|||
if (isCheckValidity) |
|||
{ |
|||
|
|||
if (isValid) |
|||
{ |
|||
return _currentStep.WinDialogue; |
|||
|
|||
} |
|||
else |
|||
{ |
|||
return _currentStep.LoseDialogue; |
|||
|
|||
} |
|||
|
|||
} |
|||
else |
|||
{ |
|||
return _currentStep.DialogueBeforeStep; |
|||
} |
|||
|
|||
} |
|||
return null; |
|||
|
|||
} |
|||
//When Interacting with a character, we ask the quest manager if there's a quest that starts with a step with a certain character
|
|||
void StartQuest(ActorSO actorToCheckWith) |
|||
{ |
|||
if (_currentQuest != null)//check if there's a current quest
|
|||
{ |
|||
return; |
|||
} |
|||
|
|||
if (_currentQuestline != null) |
|||
{ |
|||
//find quest index
|
|||
_currentQuestIndex = _currentQuestline.Quests.FindIndex(o => !o.IsDone && o.Steps != null && o.Steps[0].Actor == actorToCheckWith); |
|||
|
|||
if ((_currentQuestline.Quests.Count > _currentQuestIndex) && (_currentQuestIndex >= 0)) |
|||
{ |
|||
_currentQuest = _currentQuestline.Quests[_currentQuestIndex]; |
|||
//start Step
|
|||
_currentStepIndex = 0; |
|||
_currentStepIndex = _currentQuest.Steps.FindIndex(o => o.IsDone == false); |
|||
if (_currentStepIndex >= 0) |
|||
StartStep(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
void StartStep() |
|||
{ |
|||
if (_currentQuest.Steps != null) |
|||
if (_currentQuest.Steps.Count > _currentStepIndex) |
|||
{ |
|||
_currentStep = _currentQuest.Steps[_currentStepIndex]; |
|||
|
|||
} |
|||
|
|||
} |
|||
void CheckStepValidity() |
|||
{ |
|||
Debug.Log("Check step Validity"); |
|||
|
|||
if (_currentStep != null) |
|||
{ |
|||
switch (_currentStep.Type) |
|||
{ |
|||
case stepType.checkItem: |
|||
|
|||
if (_inventory.Contains(_currentStep.Item)) |
|||
{ |
|||
_inventory.Contains(_currentStep.Item); |
|||
//Trigger win dialogue
|
|||
_winDialogueEvent.RaiseEvent(); |
|||
} |
|||
else |
|||
{ |
|||
//trigger lose dialogue
|
|||
_loseDialogueEvent.RaiseEvent(); |
|||
} |
|||
break; |
|||
case stepType.giveItem: |
|||
Debug.Log("Check Item "); |
|||
if (_inventory.Contains(_currentStep.Item)) |
|||
{ |
|||
Debug.Log("Item exists"); |
|||
_giveItemEvent.RaiseEvent(_currentStep.Item); |
|||
_winDialogueEvent.RaiseEvent(); |
|||
} |
|||
else |
|||
{ |
|||
//trigger lose dialogue
|
|||
_loseDialogueEvent.RaiseEvent(); |
|||
|
|||
} |
|||
break; |
|||
case stepType.rewardItem: |
|||
_rewardItemEvent.RaiseEvent(_currentStep.Item); |
|||
//no dialogue is needed after Reward Item
|
|||
EndStep(); |
|||
break; |
|||
case stepType.dialogue: |
|||
//dialogue has already been played
|
|||
EndStep(); |
|||
break; |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
void EndDialogue(DialogueDataSO dialogue) |
|||
{ |
|||
|
|||
//depending on the dialogue that ended, do something
|
|||
switch (dialogue.DialogueType) |
|||
{ |
|||
case DialogueType.winDialogue: |
|||
EndStep(); |
|||
break; |
|||
case DialogueType.startDialogue: |
|||
CheckStepValidity(); |
|||
break; |
|||
default: |
|||
break; |
|||
|
|||
} |
|||
|
|||
} |
|||
void EndStep() |
|||
{ |
|||
|
|||
_currentStep = null; |
|||
|
|||
if (_currentQuest != null) |
|||
if (_currentQuest.Steps.Count > _currentStepIndex) |
|||
{ |
|||
_currentQuest.Steps[_currentStepIndex].FinishStep(); |
|||
if (_currentQuest.Steps.Count > _currentStepIndex + 1) |
|||
{ |
|||
_currentStepIndex++; |
|||
StartStep(); |
|||
|
|||
} |
|||
else |
|||
{ |
|||
|
|||
EndQuest(); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
void EndQuest() |
|||
{ |
|||
|
|||
if (_currentQuest != null) |
|||
_currentQuest.FinishQuest(); |
|||
|
|||
_currentQuest = null; |
|||
_currentQuestIndex = -1; |
|||
if (_currentQuestline != null) |
|||
{ |
|||
if (!_currentQuestline.Quests.Exists(o => !o.IsDone)) |
|||
{ |
|||
EndQuestline(); |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
void EndQuestline() |
|||
{ |
|||
if (_questlines != null) |
|||
{ |
|||
if (_currentQuestline != null) |
|||
{ |
|||
_currentQuestline.FinishQuestline(); |
|||
|
|||
} |
|||
|
|||
if (_questlines.Exists(o => o.IsDone)) |
|||
{ |
|||
StartQuestline(); |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
|
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
[CreateAssetMenu(fileName = "Quest", menuName = "Quests/Quest", order = 51)] |
|||
public class QuestSO : ScriptableObject |
|||
{ |
|||
[Tooltip("The collection of Steps composing the Quest")] |
|||
[SerializeField] |
|||
private List<StepSO> _steps = new List<StepSO>(); |
|||
[SerializeField] |
|||
bool _isDone = false; |
|||
public List<StepSO> Steps => _steps; |
|||
public bool IsDone => _isDone; |
|||
public void FinishQuest() |
|||
{ |
|||
_isDone = true; |
|||
} |
|||
|
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b4f9c8aa1ce987b4799f7093a99181a9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class QuestManager : MonoBehaviour |
|||
{ |
|||
[Header("Data")] |
|||
[SerializeField] private List<QuestSO> _quests = default; |
|||
[SerializeField] private Inventory _inventory = default; |
|||
|
|||
|
|||
[Header("Linstening to channels")] |
|||
[SerializeField] private VoidEventChannelSO _checkStepValidityEvent = default; |
|||
[SerializeField] private DialogueDataChannelSO _endDialogueEvent = default; |
|||
|
|||
[Header("Broadcasting on channels")] |
|||
[SerializeField] private StepChannelSO _startStepEvent = default; |
|||
|
|||
[SerializeField] private VoidEventChannelSO _endStepEvent = default; |
|||
|
|||
[SerializeField] private VoidEventChannelSO _winDialogueEvent = default; |
|||
[SerializeField] private VoidEventChannelSO _loseDialogueEvent = default; |
|||
|
|||
[SerializeField] private ItemEventChannelSO _giveItemEvent = default; |
|||
[SerializeField] private ItemEventChannelSO _rewardItemEvent = default; |
|||
|
|||
private QuestSO _currentQuest; |
|||
private StepSO _currentStep; |
|||
private int _currentQuestIndex = 0; |
|||
private int _currentStepIndex = 0; |
|||
private void Start() |
|||
{ |
|||
|
|||
if (_checkStepValidityEvent != null) |
|||
{ |
|||
_checkStepValidityEvent.OnEventRaised += CheckStepValidity; |
|||
} |
|||
if (_endDialogueEvent != null) |
|||
{ |
|||
_endDialogueEvent.OnEventRaised += EndDialogue; |
|||
} |
|||
StartGame(); |
|||
|
|||
} |
|||
void StartGame() |
|||
{//Add code for saved information
|
|||
|
|||
_currentQuestIndex = 0; |
|||
if (_quests != null) |
|||
{ |
|||
_currentQuestIndex = _quests.FindIndex(o => o.IsDone == false); |
|||
if (_currentQuestIndex >= 0) |
|||
StartQuest(); |
|||
} |
|||
|
|||
} |
|||
void StartQuest() |
|||
{ |
|||
if (_quests != null) |
|||
if (_quests.Count > _currentQuestIndex) |
|||
{ |
|||
_currentQuest = _quests[_currentQuestIndex]; |
|||
_currentStepIndex = 0; |
|||
_currentStepIndex = _currentQuest.Steps.FindIndex(o => o.IsDone == false); |
|||
if (_currentStepIndex >= 0) |
|||
StartStep(); |
|||
} |
|||
|
|||
} |
|||
|
|||
void StartStep() |
|||
{ |
|||
if (_currentQuest.Steps != null) |
|||
if (_currentQuest.Steps.Count > _currentStepIndex) |
|||
{ |
|||
_currentStep = _currentQuest.Steps[_currentStepIndex]; |
|||
_startStepEvent.RaiseEvent(_currentStep); |
|||
|
|||
} |
|||
|
|||
} |
|||
void CheckStepValidity() |
|||
{ |
|||
if (_currentQuest != null) |
|||
if (_currentQuest.Steps != null) |
|||
if (_currentQuest.Steps.Count > _currentStepIndex) |
|||
{ |
|||
_currentStep = _currentQuest.Steps[_currentStepIndex]; |
|||
switch (_currentStep.Type) |
|||
{ |
|||
case stepType.checkItem: |
|||
if (_inventory.Contains(_currentStep.Item)) |
|||
{ |
|||
_inventory.Contains(_currentStep.Item); |
|||
//Trigger win dialogue
|
|||
if (_winDialogueEvent != null) |
|||
{ |
|||
_winDialogueEvent.OnEventRaised(); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
//trigger lose dialogue
|
|||
if (_loseDialogueEvent != null) |
|||
{ |
|||
_loseDialogueEvent.OnEventRaised(); |
|||
} |
|||
} |
|||
break; |
|||
case stepType.giveItem: |
|||
if (_inventory.Contains(_currentStep.Item)) |
|||
{ |
|||
_giveItemEvent.RaiseEvent(_currentStep.Item); |
|||
//trigger win dialogue
|
|||
if (_winDialogueEvent != null) |
|||
{ |
|||
_winDialogueEvent.OnEventRaised(); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
//trigger lose dialogue
|
|||
if (_loseDialogueEvent != null) |
|||
{ |
|||
_loseDialogueEvent.OnEventRaised(); |
|||
} |
|||
} |
|||
break; |
|||
case stepType.rewardItem: |
|||
_rewardItemEvent.RaiseEvent(_currentStep.Item); |
|||
//no dialogue is needed after Reward Item
|
|||
EndStep(); |
|||
break; |
|||
case stepType.dialogue: |
|||
//dialogue has already been played
|
|||
EndStep(); |
|||
break; |
|||
|
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
void EndDialogue(DialogueDataSO dialogue) |
|||
{ |
|||
|
|||
//depending on the dialogue that ended, do something
|
|||
switch (dialogue.DialogueType) |
|||
{ |
|||
case DialogueType.winDialogue: |
|||
EndStep(); |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
|
|||
} |
|||
|
|||
} |
|||
void EndStep() |
|||
{ |
|||
_currentStep = null; |
|||
|
|||
if (_quests != null) |
|||
if (_quests.Count > _currentQuestIndex) |
|||
if (_quests[_currentQuestIndex].Steps != null) |
|||
if (_quests[_currentQuestIndex].Steps.Count > _currentStepIndex) |
|||
{ |
|||
if (_endStepEvent != null) |
|||
_endStepEvent.RaiseEvent(); |
|||
_quests[_currentQuestIndex].Steps[_currentStepIndex].FinishStep(); |
|||
if (_quests[_currentQuestIndex].Steps.Count > _currentStepIndex + 1) |
|||
{ |
|||
_currentStepIndex++; |
|||
StartStep(); |
|||
|
|||
} |
|||
else |
|||
{ |
|||
EndQuest(); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
void EndQuest() |
|||
{ |
|||
|
|||
if (_quests != null) |
|||
if (_quests.Count > _currentQuestIndex) |
|||
{ |
|||
_quests[_currentQuestIndex].FinishQuest(); |
|||
|
|||
if (_quests.Count < _currentQuestIndex + 1) |
|||
{ |
|||
_currentQuestIndex++; |
|||
StartQuest(); |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue