Fix - dialogue structure

This commit is contained in:
kabix09 2022-12-06 21:35:17 +01:00
parent ba894215fa
commit cc9c34930f
19 changed files with 335 additions and 143 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d9fa006e9c23c6b48bad6eb4312ffb9a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 746d0ce278aa8bf4b980ee3b69386d72
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,39 @@
%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: 06201cadd951bcc4db5fccaa01783060, type: 3}
m_Name: BossThugDialPl
m_EditorClassIdentifier:
SpeakerName:
CurrentStep: 0
DialogueSteps:
- Header:
WasDisplayed: 0
ListOfSentences:
- Sentence: Who are you? How did you get past my guards?!
Buttons: []
- Sentence: Don't answer, I don't care anyway. You're dead to me.
Buttons: []
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 4267060477434669900, guid: df6c42c9616028a4badca81953f003ab, type: 3}
m_TargetAssemblyTypeName: NpcDialogueManager, Assembly-CSharp
m_MethodName: DialogueEndAction
m_Mode: 3
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ccce026cbe2eff3478d588341e4dd531
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,19 @@
%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: 45b41589283138641ba006c2243b0637, type: 3}
m_Name: BossThugMultiDialPl
m_EditorClassIdentifier:
SpeakerName:
CurrentDialogue: 0
Dialogues:
- Key: 0
Value: {fileID: 11400000, guid: ccce026cbe2eff3478d588341e4dd531, type: 2}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cb19cd4601a7b9f4c8804f5ec09ad157
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -14,30 +14,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
SpeakerName:
CurrentDialogue: 0
MultiWayDialogue:
Dialogues:
- Key: 0
Value:
- Header:
WasDisplayed: 0
ListOfSentences:
- Header:
Sentence: Who are you? Hod did you get past my guards?!
Buttons: []
- Header:
Sentence: Don't answer. I don't care anyway. You're dead to me/.
Buttons: []
EndOfDialogueStepAction:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 4267060477434669900, guid: df6c42c9616028a4badca81953f003ab, type: 3}
m_TargetAssemblyTypeName: NpcDialogueManager, Assembly-CSharp
m_MethodName: DialogueEndAction
m_Mode: 3
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
Value: {fileID: 0}

View File

@ -168,7 +168,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
SpeakerName: Thug Boss
DialogueTemplate: {fileID: 11400000, guid: b47b2441f5e5f9e4ab687bf2a2fddbfa, type: 2}
DialogueTemplate: {fileID: 11400000, guid: cb19cd4601a7b9f4c8804f5ec09ad157, type: 2}
Dialogue: {fileID: 0}
EndactionEventList:
- Key:

View File

@ -135,7 +135,7 @@ public class BossThug : MonoBehaviour
isDuringConversation = false;
gameObject.GetComponent<NpcDialogueManager>().Dialogue.BreakDialogue();
gameObject.GetComponent<NpcDialogueManager>().Dialogue.BreakDialogueStep();
//TODO break dialogue after leaving collider range!!!
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d8a9f0c703509b94a93e318c01cf0ef6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,71 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
[Serializable]
[CreateAssetMenu(fileName = "New Dialogue", menuName = "Dialogue/New Dialogue")]
public class Dialogue : ScriptableObject
public class Dialogue : ScriptableObject, IDialogue
{
[SerializeField]
public string SpeakerName;
[SerializeField]
int CurrentDialogue = 0;
int CurrentStep = 0;
[SerializeField]
public List<IndexValuePair<int, List<DialogueStepModel>>> MultiWayDialogue;
public List<DialogueStepModel> DialogueSteps;
/*
Dialogues - list of dialoges
Steps bucket (one dialogue unit) - list of liner 'steps', finished special action, whole can be stopped special requirements (like go and do something - to declared in 'finish action')
Steps - its a cell package contains 'sentences' (one per panel)
Sentence - its a opanel with phrase and buttons
*/
/*
* WAZNE:
* Jesli przechodzimy odpowiedzia do nastepnego dialogu musi to byc osttani panel w obecnym!!!
*/
public void Start()
public void SetSpeakerName(string speakerName)
{
/* CODE DIALOGUE DECLARATION EXAMPLE
SpeakerName = speakerName;
DialogueController DialogueStep = new DialogueController();
DialogueStep.AddSentence(new DialogueModel("lorem ipsum"));
*//* di.AddSentence(new QuestionDialogueModel("tolore dolore?",
new List<Tuple<string, Action>> {
new Tuple<string, Action>("AcceptButton", CustomPanel),
new Tuple<string, Action>("RejectButton", QuestionPanel)
}));*//*
DialogueStep.SetActionAfterDialogueEnds(() => { });
DialogueStepModel dialogueStepModel = new DialogueStepModel(DialogueStep);
DialogueStepsList = new List<DialogueStepModel> { dialogueStepModel };
*/
/*if (MultiWayDialogue.Count > 0)
BuildDialogue(MultiWayDialogue.Where(el => el.Key == CurrentDialogue).First().Value);*/
DialogueSteps.ForEach(step => step.Header = speakerName);
}
public void StartDialogue()
{
// 1. Build
BuildDialogue(MultiWayDialogue.Where(el => el.Key == CurrentDialogue).First().Value);
BuildDialogue(DialogueSteps);
// 2. Show first step
ShowStep();
ShowDialogueStepPanel();
}
public void BreakDialogue()
public void BreakDialogueStep()
{
// 1. Find first yet undisplayed for player anbd show
var dialogueStepsList = MultiWayDialogue.Where(el => el.Key == CurrentDialogue).ToArray().First().Value;
foreach (var DialogueStep in dialogueStepsList)
foreach (var DialogueStep in DialogueSteps)
{
if (!DialogueStep.WasDisplayed && DialogueStep.DialogueController.CurrentPanel != null)
{
@ -84,13 +54,9 @@ public class Dialogue : ScriptableObject
///
/// The best way is to invoked its after player reaction from other script (by event - collision) :)
/// </summary>
public void ShowStep()
public void ShowDialogueStepPanel()
{
// 1. Find first yet undisplayed for player anbd show
var dialogueStepsList = MultiWayDialogue.Where(el => el.Key == CurrentDialogue).ToArray().First().Value;
foreach (var DialogueStep in dialogueStepsList)
foreach (var DialogueStep in DialogueSteps)
{
if (!DialogueStep.WasDisplayed && DialogueStep.DialogueController.listOfDialogue.Count != 0)
{
@ -104,7 +70,12 @@ public class Dialogue : ScriptableObject
/// <summary>
/// Dialogue API
///
/// Default function to get next sentence if dialogue is currently started
/// Function to automaticly go to next dialgue sentence (in this or next step eg after pressing button on panel
/// It provide that dialogue not braking after finishing current step
///
/// The dialogue follows the order of the lists ! !
///
/// It's default function to get next sentence if dialogue is currently started
/// It is responsible for detecting
/// 1) if there is any dialogue panel already created before displaying next sentence
/// 2) if its last panel sentence and invoiking 'end dialogue' action
@ -113,11 +84,7 @@ public class Dialogue : ScriptableObject
/// </summary>
public void GoToNextSentence()
{
// 1. Find first yet undisplayed for player anbd show
var dialogueStepsList = MultiWayDialogue.Where(el => el.Key == CurrentDialogue).ToArray().First().Value;
foreach (var DialogueStep in dialogueStepsList)
foreach (var DialogueStep in DialogueSteps)
{
if (!DialogueStep.WasDisplayed)
{
@ -127,7 +94,7 @@ public class Dialogue : ScriptableObject
{
DialogueStep.WasDisplayed = true;
ShowStep();
ShowDialogueStepPanel();
}
break;
@ -136,49 +103,9 @@ public class Dialogue : ScriptableObject
}
/// <summary>
/// Dialogue API
///
/// Function to prepare next dialogue to start after one more palyer interaction with actor
/// - ends current dialogue (destroy panel & invoke finish action - if setupped)
/// - set new dialogue pointer
///
/// Function to build each step of dialogue
/// </summary>
/// <param name="dialogueNumber"></param>
public void SetNextDialogue(int dialogueNumber)
{
if (MultiWayDialogue.Where(el => el.Key == dialogueNumber).ToArray().Count() == 0)
return;
// 1. Make sure to close current panel after finishing current dialogue and 'finish action' will invoked if setuped
GoToNextSentence();
// 2. Chane index
CurrentDialogue = dialogueNumber;
}
/// <summary>
/// Dialogue API
///
/// Function to finish current dialog and immediately start next one
///
/// </summary>
/// <param name="dialogueNumber"></param>
public void GoToNextDialogue(int dialogueNumber)
{
// 1. Prepare necessary environoment parts
SetNextDialogue(dialogueNumber);
// 3. Build new dialogue
BuildDialogue(MultiWayDialogue.Where(el => el.Key == CurrentDialogue).First().Value);
// 4. Start new dialogue bucket
ShowStep();
}
/// <summary>
/// Build each step of dialogue
/// </summary>
private void BuildDialogue(List<DialogueStepModel> Dialogue)
public void BuildDialogue(List<DialogueStepModel> Dialogue)
{
foreach (var dialogueStep in Dialogue)
{
@ -187,18 +114,4 @@ public class Dialogue : ScriptableObject
dialogueStep.Build();
}
}
public (int, int) DialogueStepStatus()
{
var currentDialogueStepIndex = MultiWayDialogue
.Where(el => el.Key == CurrentDialogue)
.Select(el => el.Value)
.First()
.Where(step => step.WasDisplayed == true)
.ToArray()
.Count()
;
return(CurrentDialogue, currentDialogueStepIndex);
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 45b41589283138641ba006c2243b0637
guid: 06201cadd951bcc4db5fccaa01783060
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,19 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public interface IDialogue
{
public void SetSpeakerName(string speakerName);
public void StartDialogue();
public void BreakDialogueStep();
public void ShowDialogueStepPanel();
public void GoToNextSentence();
public void BuildDialogue(List<DialogueStepModel> Dialogue);
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 98a40f30fd98e1443aa1034fcfcaadc4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,164 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
[Serializable]
[CreateAssetMenu(fileName = "New Dialogue", menuName = "Dialogue/New Multi Dialogue")]
public class MultiDialogue : ScriptableObject, IDialogue
{
[SerializeField]
public string SpeakerName;
[SerializeField]
int CurrentDialogue = 0;
[SerializeField]
public List<IndexValuePair<int, Dialogue>> Dialogues;
/*
Dialogues - list of dialoges
Steps bucket (one dialogue unit) - list of liner 'steps', finished special action, whole can be stopped special requirements (like go and do something - to declared in 'finish action')
Steps - its a cell package contains 'sentences' (one per panel)
Sentence - its a opanel with phrase and buttons
*/
/*
* WAZNE:
* Jesli przechodzimy odpowiedzia do nastepnego dialogu musi to byc osttani panel w obecnym!!!
*/
public void Start()
{
/* CODE DIALOGUE DECLARATION EXAMPLE
DialogueController DialogueStep = new DialogueController();
DialogueStep.AddSentence(new DialogueModel("lorem ipsum"));
*//* di.AddSentence(new QuestionDialogueModel("tolore dolore?",
new List<Tuple<string, Action>> {
new Tuple<string, Action>("AcceptButton", CustomPanel),
new Tuple<string, Action>("RejectButton", QuestionPanel)
}));*//*
DialogueStep.SetActionAfterDialogueEnds(() => { });
DialogueStepModel dialogueStepModel = new DialogueStepModel(DialogueStep);
DialogueStepsList = new List<DialogueStepModel> { dialogueStepModel };
*/
/*if (MultiWayDialogue.Count > 0)
BuildDialogue(MultiWayDialogue.Where(el => el.Key == CurrentDialogue).First().Value);*/
}
public void SetSpeakerName(string speakerName)
{
SpeakerName = speakerName;
Dialogues.ForEach(dialogue => dialogue.Value.SetSpeakerName(speakerName));
}
public void StartDialogue()
{
// 1. Start Dialogue (build + show panel)
Dialogues.Where(el => el.Key == CurrentDialogue).First().Value.StartDialogue();
}
public void BreakDialogueStep()
{
// 1. Break Dialogue (close panel without marking as displayed)
Dialogues.Where(el => el.Key == CurrentDialogue).ToArray().First().Value.BreakDialogueStep();
}
/// <summary>
/// Dialogue API
///
/// MAIN bunction to begin dialogue
/// Create new panel instance on scene by force with sentence from queue
///
/// The best way is to invoked its after player reaction from other script (by event - collision) :)
/// </summary>
public void ShowDialogueStepPanel()
{
Dialogues.Where(el => el.Key == CurrentDialogue).ToArray().First().Value.ShowDialogueStepPanel();
}
/// <summary>
/// Dialogue API
///
/// Default function to get next sentence if dialogue is currently started
/// It is responsible for detecting
/// 1) if there is any dialogue panel already created before displaying next sentence
/// 2) if its last panel sentence and invoiking 'end dialogue' action
///
/// Whats more, if there was no more sentences in 'step', althroughr closing panel go to next step automatiiccally
/// </summary>
public void GoToNextSentence()
{
Dialogues.Where(el => el.Key == CurrentDialogue).ToArray().First().Value.GoToNextSentence();
}
/// <summary>
/// Dialogue API
///
/// Function to prepare next dialogue to start after one more palyer interaction with actor
/// - ends current dialogue (destroy panel & invoke finish action - if setupped)
/// - set new dialogue pointer
///
/// </summary>
/// <param name="dialogueNumber"></param>
public void SetNextDialogue(int dialogueNumber)
{
if (Dialogues.Where(el => el.Key == dialogueNumber).ToArray().Count() == 0)
return;
// 1. Make sure to close current panel after finishing current dialogue and 'finish action' will invoked if setuped
GoToNextSentence();
// 2. Chane index
CurrentDialogue = dialogueNumber;
}
/// <summary>
/// Dialogue API
///
/// Function to finish current dialog and immediately start next one
///
/// </summary>
/// <param name="dialogueNumber"></param>
public void GoToNextDialogue(int dialogueNumber)
{
// 1. Prepare necessary environoment parts
SetNextDialogue(dialogueNumber);
// 2. Build new (next) dialogue & show panel
StartDialogue();
}
/// <summary>
/// Build each step of dialogue
/// </summary>
public void BuildDialogue(List<DialogueStepModel> Dialogue)
{
foreach (var dialogueStep in Dialogue)
{
dialogueStep.Header = SpeakerName;
dialogueStep.Build();
}
}
public (int, int) DialogueStepStatus()
{
var currentDialogueStepIndex = Dialogues
.Where(el => el.Key == CurrentDialogue)
.Select(el => el.Value)
.First()
.DialogueSteps
.Where(step => step.WasDisplayed == true)
.ToArray()
.Count()
;
return(CurrentDialogue, currentDialogueStepIndex);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 45b41589283138641ba006c2243b0637
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -12,11 +12,11 @@ public class NpcDialogueManager : MonoBehaviour
public string SpeakerName;
[SerializeField]
public Dialogue DialogueTemplate;
public MultiDialogue DialogueTemplate;
/* We user object CLONED TO PREVENT overwritting changes in main object inassets */
[SerializeField]
public Dialogue Dialogue;
public MultiDialogue Dialogue;
// List<Key<dialogue No, dialogue step No>, Value : UnityEvent>
public List<IndexValuePair<IndexValuePair<int, int>, UnityEvent>> EndactionEventList;
@ -24,7 +24,7 @@ public class NpcDialogueManager : MonoBehaviour
public void Start()
{
Dialogue = Instantiate(DialogueTemplate);
Dialogue.SpeakerName = SpeakerName;
Dialogue.SetSpeakerName(SpeakerName);
}
public void Update() { }