finsihed castle walls, adding attack, block and kick aniamtions and input. Started on NPCdiagloue system
This commit is contained in:
24
Assets/Scripts/Dialogue.cs
Normal file
24
Assets/Scripts/Dialogue.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
[System.Serializable]
|
||||
public class Dialogue
|
||||
{
|
||||
public string npcId;
|
||||
public string name;
|
||||
public List<string> sentences;
|
||||
public List<DialogueOption> options;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class DialogueOption
|
||||
{
|
||||
public string text;
|
||||
public DialogueOutcome outcome;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class DialogueOutcome
|
||||
{
|
||||
public List<Quest> quests;
|
||||
public Dialogue dialogue;
|
||||
}
|
||||
2
Assets/Scripts/Dialogue.cs.meta
Normal file
2
Assets/Scripts/Dialogue.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b0e181f6cafbf34aabc5cdf55b44681
|
||||
98
Assets/Scripts/DialogueDatabase.cs
Normal file
98
Assets/Scripts/DialogueDatabase.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
[System.Serializable]
|
||||
public class DialogueEntry
|
||||
{
|
||||
public string npcId;
|
||||
public string npcName;
|
||||
public List<Dialogue> dialogues;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class DialogueDatabase : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<DialogueEntry> entries;
|
||||
private Dictionary<string, DialogueEntry> dialogueDictionary;
|
||||
|
||||
private static DialogueDatabase instance;
|
||||
public static DialogueDatabase Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = FindObjectOfType<DialogueDatabase>();
|
||||
if (instance == null)
|
||||
{
|
||||
GameObject obj = new GameObject("DialogueDatabase");
|
||||
instance = obj.AddComponent<DialogueDatabase>();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
InitializeDictionary();
|
||||
}
|
||||
else if (instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeDictionary()
|
||||
{
|
||||
dialogueDictionary = new Dictionary<string, DialogueEntry>();
|
||||
foreach (DialogueEntry entry in entries)
|
||||
{
|
||||
dialogueDictionary[entry.npcId] = entry;
|
||||
}
|
||||
}
|
||||
|
||||
public Dialogue GetRandomDialogue(string npcId)
|
||||
{
|
||||
if (dialogueDictionary.TryGetValue(npcId, out DialogueEntry entry))
|
||||
{
|
||||
if (entry.dialogues.Count > 0)
|
||||
{
|
||||
int randomIndex = UnityEngine.Random.Range(0, entry.dialogues.Count);
|
||||
return entry.dialogues[randomIndex];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Dialogue GetSpecificDialogue(string npcId, int dialogueIndex)
|
||||
{
|
||||
if (dialogueDictionary.TryGetValue(npcId, out DialogueEntry entry))
|
||||
{
|
||||
if (dialogueIndex >= 0 && dialogueIndex < entry.dialogues.Count)
|
||||
{
|
||||
return entry.dialogues[dialogueIndex];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool HasDialogue(string npcId)
|
||||
{
|
||||
return dialogueDictionary.ContainsKey(npcId);
|
||||
}
|
||||
|
||||
public string GetNPCName(string npcId)
|
||||
{
|
||||
if (dialogueDictionary.TryGetValue(npcId, out DialogueEntry entry))
|
||||
{
|
||||
return entry.npcName;
|
||||
}
|
||||
return "Unknown NPC";
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/DialogueDatabase.cs.meta
Normal file
2
Assets/Scripts/DialogueDatabase.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66cb6b6827098d54bbecf557ce602e95
|
||||
140
Assets/Scripts/DialogueManager.cs
Normal file
140
Assets/Scripts/DialogueManager.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DialogueManager : MonoBehaviour
|
||||
{
|
||||
[Header("UI Elements")]
|
||||
[SerializeField] private GameObject dialoguePanel;
|
||||
[SerializeField] private Text dialogueText;
|
||||
[SerializeField] private GameObject optionsPanel;
|
||||
[SerializeField] private RectTransform optionsContainer;
|
||||
[SerializeField] private GameObject optionPrefab;
|
||||
|
||||
[Header("Dialogue Settings")]
|
||||
[SerializeField] private float textSpeed = 0.05f;
|
||||
[SerializeField] private float dialogueDelay = 1f;
|
||||
|
||||
private Queue<string> sentences;
|
||||
private Dialogue currentDialogue;
|
||||
private bool isTyping;
|
||||
private bool isDialogueActive;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
sentences = new Queue<string>();
|
||||
dialoguePanel.SetActive(false);
|
||||
optionsPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void StartDialogue(string npcId)
|
||||
{
|
||||
Dialogue dialogue = DialogueDatabase.Instance.GetRandomDialogue(npcId);
|
||||
if (dialogue == null)
|
||||
{
|
||||
Debug.LogWarning($"No dialogue found for NPC with ID: {npcId}");
|
||||
return;
|
||||
}
|
||||
|
||||
currentDialogue = dialogue;
|
||||
isDialogueActive = true;
|
||||
dialoguePanel.SetActive(true);
|
||||
sentences.Clear();
|
||||
|
||||
foreach (string sentence in dialogue.sentences)
|
||||
{
|
||||
sentences.Enqueue(sentence);
|
||||
}
|
||||
|
||||
DisplayNextSentence();
|
||||
}
|
||||
|
||||
public void DisplayNextSentence()
|
||||
{
|
||||
if (isTyping)
|
||||
return;
|
||||
|
||||
if (sentences.Count == 0)
|
||||
{
|
||||
EndDialogue();
|
||||
return;
|
||||
}
|
||||
|
||||
string sentence = sentences.Dequeue();
|
||||
StartCoroutine(TypeSentence(sentence));
|
||||
}
|
||||
|
||||
private IEnumerator TypeSentence(string sentence)
|
||||
{
|
||||
isTyping = true;
|
||||
dialogueText.text = "";
|
||||
|
||||
foreach (char letter in sentence.ToCharArray())
|
||||
{
|
||||
dialogueText.text += letter;
|
||||
yield return new WaitForSeconds(textSpeed);
|
||||
}
|
||||
|
||||
isTyping = false;
|
||||
|
||||
if (currentDialogue.options != null && currentDialogue.options.Count > 0)
|
||||
{
|
||||
ShowOptions(currentDialogue.options);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowOptions(List<DialogueOption> options)
|
||||
{
|
||||
optionsPanel.SetActive(true);
|
||||
optionsContainer.sizeDelta = new Vector2(optionsContainer.sizeDelta.x, options.Count * 50);
|
||||
|
||||
foreach (Transform child in optionsContainer)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
foreach (DialogueOption option in options)
|
||||
{
|
||||
GameObject optionObj = Instantiate(optionPrefab, optionsContainer);
|
||||
Button button = optionObj.GetComponent<Button>();
|
||||
Text buttonText = optionObj.GetComponentInChildren<Text>();
|
||||
|
||||
buttonText.text = option.text;
|
||||
button.onClick.AddListener(() => SelectOption(option));
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectOption(DialogueOption option)
|
||||
{
|
||||
optionsPanel.SetActive(false);
|
||||
|
||||
if (option.outcome != null)
|
||||
{
|
||||
if (option.outcome.quests != null)
|
||||
{
|
||||
foreach (Quest quest in option.outcome.quests)
|
||||
{
|
||||
quest.StartQuest();
|
||||
}
|
||||
}
|
||||
|
||||
if (option.outcome.dialogue != null)
|
||||
{
|
||||
StartDialogue(option.outcome.dialogue.npcId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EndDialogue()
|
||||
{
|
||||
dialoguePanel.SetActive(false);
|
||||
optionsPanel.SetActive(false);
|
||||
isDialogueActive = false;
|
||||
}
|
||||
|
||||
public bool IsDialogueActive()
|
||||
{
|
||||
return isDialogueActive;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/DialogueManager.cs.meta
Normal file
2
Assets/Scripts/DialogueManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b888d53a2e6ac14ba51cf57f6b1eb03
|
||||
37
Assets/Scripts/NPC.cs
Normal file
37
Assets/Scripts/NPC.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class NPC : MonoBehaviour
|
||||
{
|
||||
[Header("NPC Settings")]
|
||||
[SerializeField] private string npcId;
|
||||
[SerializeField] private string npcName;
|
||||
[SerializeField] private bool canTalk;
|
||||
|
||||
private DialogueManager dialogueManager;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
dialogueManager = FindObjectOfType<DialogueManager>();
|
||||
}
|
||||
|
||||
private void OnMouseDown()
|
||||
{
|
||||
if (canTalk && !dialogueManager.IsDialogueActive())
|
||||
{
|
||||
dialogueManager.StartDialogue(npcId);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMouseOver()
|
||||
{
|
||||
if (canTalk)
|
||||
{
|
||||
// Show interaction prompt
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMouseExit()
|
||||
{
|
||||
// Hide interaction prompt
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/NPC.cs.meta
Normal file
2
Assets/Scripts/NPC.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df30bc802d6a98c478e7811c21f6a285
|
||||
20
Assets/Scripts/ObjectInformation.cs
Normal file
20
Assets/Scripts/ObjectInformation.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ObjectInformation : MonoBehaviour
|
||||
{
|
||||
public string objectName; // Variable to store the name of the object
|
||||
public string objectDescription; // Variable to store the description of the object
|
||||
public string objectType; // Variable to store the type of the object
|
||||
public string objectWeight; // Variable to store the material of the object
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/ObjectInformation.cs.meta
Normal file
2
Assets/Scripts/ObjectInformation.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92daabeadbca0814f942350adfec7650
|
||||
48
Assets/Scripts/PopUpManager.cs
Normal file
48
Assets/Scripts/PopUpManager.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEditor.VisionOS;
|
||||
|
||||
public class PopUpManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public static PopUpManager instance; // Singleton instance of PopUpManager
|
||||
public void Awake()
|
||||
{
|
||||
instance = this; // Assign the current instance to the static instance variable
|
||||
}
|
||||
public TMP_Text popUpText; // Reference to the TextMeshPro component for displaying the message
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ShowPopUp(string objectName, string objectDesc, Transform targetObject)
|
||||
{
|
||||
// Set the text of the pop-up to the provided message
|
||||
popUpText.text = objectName + "\n" + objectDesc;
|
||||
|
||||
// Position the pop-up above the target object
|
||||
Vector3 offset = new Vector3(0, 0.5f, 0); // Adjust the Y offset as needed
|
||||
transform.position = targetObject.position + offset;
|
||||
|
||||
// Make the pop-up face the camera
|
||||
Camera mainCamera = Camera.main;
|
||||
if (mainCamera != null)
|
||||
{
|
||||
// Make the pop-up face the camera, but invert the forward direction to fix the text being backwards
|
||||
Vector3 directionToCamera = transform.position - mainCamera.transform.position;
|
||||
transform.rotation = Quaternion.LookRotation(directionToCamera);
|
||||
transform.rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y, 0); // Lock rotation to Y-axis
|
||||
}
|
||||
|
||||
// Activate the pop-up GameObject to make it visible
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/PopUpManager.cs.meta
Normal file
2
Assets/Scripts/PopUpManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa68d514b83894842bbe9be1a68a7067
|
||||
27
Assets/Scripts/Quest.cs
Normal file
27
Assets/Scripts/Quest.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Quest : MonoBehaviour
|
||||
{
|
||||
public string questName;
|
||||
public string description;
|
||||
public bool isCompleted;
|
||||
|
||||
public void StartQuest()
|
||||
{
|
||||
isCompleted = false;
|
||||
// Add quest start logic here
|
||||
Debug.Log($"Quest '{questName}' has started!");
|
||||
}
|
||||
|
||||
public void CompleteQuest()
|
||||
{
|
||||
isCompleted = true;
|
||||
// Add quest completion logic here
|
||||
Debug.Log($"Quest '{questName}' has been completed!");
|
||||
}
|
||||
|
||||
public bool IsCompleted()
|
||||
{
|
||||
return isCompleted;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Quest.cs.meta
Normal file
2
Assets/Scripts/Quest.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c0ceb6b85de3bb4ea7a062a997cd073
|
||||
Reference in New Issue
Block a user