112 lines
3.7 KiB
C#
112 lines
3.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
[RequireComponent(typeof(NPC))]
|
|
public class NpcDialogueManager : DialogueManager
|
|
{
|
|
public override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
CanBeOpened = false;
|
|
OpenInDefaultWay = false;
|
|
|
|
// UPDATE DIALOGUE
|
|
// search in scene manager list
|
|
var machedDialogueData = ((MultiDialogueDataManager)MultiDialogueDataManager.Instance).GetDialogue(Dialogue);
|
|
if(Dialogue != null && machedDialogueData != null)
|
|
{
|
|
Debug.Log("Multi Dialogue - updated");
|
|
UpdateDialogueState(machedDialogueData);
|
|
}
|
|
}
|
|
|
|
#region Open Panel API
|
|
public override bool OpenPanelCondition()
|
|
{
|
|
/*
|
|
* Conditions:
|
|
* - npc bust me in Talking mode
|
|
* - player is in collision range
|
|
* - panel assigned to next sentence in dialogue must be closed
|
|
*/
|
|
return gameObject.GetComponent<NPC>().State == NPCStateEnum.Talking && base.OpenPanelCondition();
|
|
}
|
|
|
|
protected virtual bool ColliderTypeCondition()
|
|
{
|
|
return !gameObject.GetComponent<NpcDialogueManager>().enabled;
|
|
}
|
|
#endregion
|
|
public override void CreateInstanceBasedOnLanguage()
|
|
{
|
|
Dialogue = Instantiate(languageDetector.DetectInstanceBasedOnLanguage());
|
|
|
|
}
|
|
|
|
public void UpdateDialogueState(MultiDialogueData dialogueData)
|
|
{
|
|
// 1 Rule - speaker name shouldnt change !!! its our 'key'
|
|
|
|
Dialogue.CurrentDialogue = dialogueData.CurrentDialogue;
|
|
|
|
foreach(var singleDialogue in dialogueData.DialogueStepModelDataList)
|
|
{
|
|
Dialogue.Dialogues
|
|
.Where(dial => dial.Key == singleDialogue.Key)
|
|
.Select(dial => dial.Value)
|
|
.ToList()
|
|
.ForEach(dial => dial.UpdateDialogueState(singleDialogue.Value) );
|
|
}
|
|
}
|
|
|
|
#region Dialogue actions API
|
|
/// <summary>
|
|
/// Function to invoke actions declared in manager on object from scene not onto asset
|
|
///
|
|
/// Used in Dialogue ScriptableObject Template
|
|
/// </summary>
|
|
/// <param name="dialogueIndex"></param>
|
|
public void DialogueEndAction(int dialogueIndex)
|
|
{
|
|
GameObject.FindObjectsOfType<NpcDialogueManager>().Where(obj => obj.name == gameObject.name).First().GetComponent<NpcDialogueManager>().InvokeDialogueEndAction(dialogueIndex);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Function to invoke actions declared in manager (on current object)
|
|
///
|
|
/// Use this to invoke actions which we want to occured after specific Dialogue
|
|
/// </summary>
|
|
/// <param name="dialogueIndex"></param>
|
|
protected void InvokeDialogueEndAction(int dialogueIndex)
|
|
{
|
|
EndactionEventList.Where(el => el.Key.Key == dialogueIndex).ToList().ForEach(el => el.Value.Invoke());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Function to invoke actions declared in manager on object from scene not onto asset
|
|
///
|
|
/// Used in Dialogue ScriptableObject Template
|
|
/// </summary>
|
|
public void StepEndAction()
|
|
{
|
|
GameObject.FindObjectsOfType<NpcDialogueManager>().Where(obj => obj.name == gameObject.name).First().GetComponent<NpcDialogueManager>().InvokeStepEndAction();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Function to invoke actions declared in manager (on current object)
|
|
///
|
|
/// Use this to invoke actions which we want to occured after specific Dialogue Step
|
|
/// </summary>
|
|
protected void InvokeStepEndAction()
|
|
{
|
|
var dialogueProgress = Dialogue.DialogueStepStatus();
|
|
|
|
EndactionEventList.Where(el => el.Key.Key == dialogueProgress.Item1 & el.Key.Value == dialogueProgress.Item2).ToList().ForEach(el => el.Value.Invoke());
|
|
}
|
|
#endregion
|
|
} |