This commit is contained in:
JA
2026-06-20 19:34:23 +08:00
parent e5031c0068
commit d442805c3f
4136 changed files with 514641 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum CharacterType
{
Npc,
Player,
}
[Serializable]
public class DialogNode
{
public int npcID;
public int ToId;
public CharacterType type;
public string characterName;
public Sprite characterSprite;
[TextArea]
public string dialog;
}

View File

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

View File

@@ -0,0 +1,123 @@
%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: a8ce42ca11e4651489ab01075c11226c, type: 3}
m_Name: Dialogue
m_EditorClassIdentifier:
dialogNode:
- npcID: 0
ToId: 0
type: 0
characterName: "\u5927\u767D\u7F8A"
characterSprite: {fileID: 21300000, guid: 6c9534d590f8fe84da19aeca85f376d8, type: 3}
dialog: "\u4F60\u597D\u554A\uFF0C\u5C11\u5E74\uFF01\uFF01"
- npcID: 0
ToId: 0
type: 1
characterName: "\u73A9\u5BB6"
characterSprite: {fileID: 21300000, guid: cf242bc813f581f438f1c1e8d464145a, type: 3}
dialog: "\u5582\uFF01\u4F60\u662F\u4E2A\u4EC0\u4E48\u73A9\u610F\uFF1F"
- npcID: 0
ToId: 0
type: 0
characterName: "\u5927\u767D\u7F8A"
characterSprite: {fileID: 21300000, guid: 6c9534d590f8fe84da19aeca85f376d8, type: 3}
dialog: "\u7B2C\u4E00\uFF0C\u6211\u4E0D\u53EB\u5582\uFF0C\u7B2C\u4E8C\uFF0C\u6211\u4E0D\u662F\u73A9\u610F"
- npcID: 0
ToId: 0
type: 0
characterName: "\u5927\u767D\u7F8A"
characterSprite: {fileID: 21300000, guid: 6c9534d590f8fe84da19aeca85f376d8, type: 3}
dialog: "\u4F60\u53EF\u4EE5\u53EB\u6211\u5927\u767D\u7F8A"
- npcID: 0
ToId: 0
type: 1
characterName: "\u73A9\u5BB6"
characterSprite: {fileID: 21300000, guid: cf242bc813f581f438f1c1e8d464145a, type: 3}
dialog: "\u597D\u7684\uFF0C\u5927\u767D\u7F8A\u3002\u63A5\u4E0B\u6765\u6211\u8981\u5E72\u561B\uFF1F\uFF1F\uFF1F"
- npcID: 0
ToId: 0
type: 0
characterName: "\u5927\u767D\u7F8A"
characterSprite: {fileID: 21300000, guid: 6c9534d590f8fe84da19aeca85f376d8, type: 3}
dialog: "\u5F53\u7136\u662F\u4E0D\u65AD\u6218\u6597\u4E86\uFF0C\u56E0\u4E3A\uFF0C\u6218\u6597\uFF01\uFF01\u723D\uFF01\uFF01\uFF01"
- npcID: 0
ToId: 0
type: 1
characterName: "\u73A9\u5BB6"
characterSprite: {fileID: 21300000, guid: cf242bc813f581f438f1c1e8d464145a, type: 3}
dialog: "\u53EF\u662F\u6211\u4E0D\u4F1A\u6218\u6597\uFF01\uFF01\uFF01"
- npcID: 0
ToId: 0
type: 0
characterName: "\u5927\u767D\u7F8A"
characterSprite: {fileID: 21300000, guid: 6c9534d590f8fe84da19aeca85f376d8, type: 3}
dialog: "\u65E0\u59A8\uFF0C\u6211\u6765\u6559\u4F60\u3002"
- npcID: 0
ToId: 0
type: 0
characterName: "\u5927\u767D\u7F8A"
characterSprite: {fileID: 21300000, guid: 6c9534d590f8fe84da19aeca85f376d8, type: 3}
dialog: "AWSD\u79FB\u52A8\uFF0C\u9F20\u6807\u653B\u51FB\uFF0CLshift\u7FFB\u6EDA\u95EA\u907F"
- npcID: 0
ToId: 0
type: 0
characterName: "\u5927\u767D\u7F8A"
characterSprite: {fileID: 21300000, guid: 6c9534d590f8fe84da19aeca85f376d8, type: 3}
dialog: "Tab\u6253\u5F00\u80CC\u5305\uFF0C1\u559D\u836F\u56DE\u8840\uFF0CEsc\u4F60\u61C2\u7684"
- npcID: 0
ToId: 0
type: 0
characterName: "\u5927\u767D\u7F8A"
characterSprite: {fileID: 21300000, guid: 6c9534d590f8fe84da19aeca85f376d8, type: 3}
dialog: "\u5927\u6982\u5C31\u8FD9\u4E9B\uFF0C\u4E0A\u5427\uFF0C\u5C11\u5E74\uFF01\uFF01\uFF01"
- npcID: 0
ToId: 0
type: 1
characterName: "\u73A9\u5BB6"
characterSprite: {fileID: 21300000, guid: cf242bc813f581f438f1c1e8d464145a, type: 3}
dialog: "\uFF1F\uFF1F\uFF1F"
- npcID: 0
ToId: 0
type: 0
characterName: "\u5927\u767D\u7F8A"
characterSprite: {fileID: 21300000, guid: 6c9534d590f8fe84da19aeca85f376d8, type: 3}
dialog: "\u597D\u4E86\uFF0C\u4F60\u5DF2\u7ECF\u662F\u4E2A\u6210\u719F\u7684\u52C7\u58EB\u4E86\u3002\u4E0A\u5427\uFF01\uFF01\uFF01"
- npcID: 1
ToId: 0
type: 0
characterName: "\u5929\u68AF\u5546\u4EBA"
characterSprite: {fileID: 21300000, guid: 5a38bec081c255c4a9cecabc8fbdca11, type: 3}
dialog: "\u4F60\u597D\uFF0C\u9A9A\u5E74\u90CE\uFF01\uFF01"
- npcID: 1
ToId: 0
type: 0
characterName: "\u5929\u68AF\u5546\u4EBA"
characterSprite: {fileID: 21300000, guid: 5a38bec081c255c4a9cecabc8fbdca11, type: 3}
dialog: "\u5728\u6211\u8FD9\u91CC\u53EF\u4EE5\u901A\u8FC7\u6C38\u6052\u4E4B\u5FC3\u5E2E\u52A9\u4F60\u6C38\u4E45\u63D0\u5347\u5C5E\u6027\uFF01\uFF01"
- npcID: 1
ToId: 0
type: 0
characterName: "\u5929\u68AF\u5546\u4EBA"
characterSprite: {fileID: 21300000, guid: 5a38bec081c255c4a9cecabc8fbdca11, type: 3}
dialog: "\u6BCF\u6B21\u51FB\u8D25\u654C\u4EBA\u540E\u4F60\u90FD\u80FD\u83B7\u5F97\u6C38\u6052\u4E4B\u5FC3"
- npcID: 1
ToId: 0
type: 0
characterName: "\u5929\u68AF\u5546\u4EBA"
characterSprite: {fileID: 21300000, guid: 5a38bec081c255c4a9cecabc8fbdca11, type: 3}
dialog: "\u4E0D\u65AD\u5347\u7EA7\u4E4B\u540E\u4F60\u5C31\u80FD\u780D\u74DC\u5207\u83DC\u4E86"
- npcID: 1
ToId: 0
type: 0
characterName: "\u5929\u68AF\u5546\u4EBA"
characterSprite: {fileID: 21300000, guid: 5a38bec081c255c4a9cecabc8fbdca11, type: 3}
dialog: "\u52AA\u529B\u5427\uFF0C\u9A9A\u5E74\uFF01\uFF01\uFF01"

View File

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

View File

@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName ="Dialogue")]
public class Dialogue : ScriptableObject
{
public DialogNode[] dialogNode;
}

View File

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

View File

@@ -0,0 +1,95 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueSystem : MonoBehaviour
{
[SerializeField] private Dialogue dialogue;
[SerializeField] private GameObject dialogBox;
[SerializeField] private Text dialog;
[SerializeField] private Text characterName;
[SerializeField] private Image characterSprite;
[SerializeField] private CharacterType type;
private int index;
private bool isInTurn;
private int npcId;
public Dictionary<int, List<DialogNode>> dialogNodes = new Dictionary<int, List<DialogNode>>();
private void Awake()
{
foreach (var dia in dialogue.dialogNode)
{
if (!dialogNodes.ContainsKey(dia.npcID))
{
dialogNodes.Add(dia.npcID,new List<DialogNode> { dia});
}
else
{
dialogNodes[dia.npcID].Add(dia);
}
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.E) && isInTurn)
{
Play();
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Npc"))
{
Debug.Log("aaa");
isInTurn = true;
npcId = collision.GetComponent<UITip>().GetNpcId();
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.CompareTag("Npc"))
{
Debug.Log("bbb");
isInTurn = false;
index = 0;
dialogBox.SetActive(false);
}
}
void Play()
{
dialogBox.SetActive(true);
DialogNode node = dialogNodes[npcId][Mathf.Clamp(index++, 0, dialogNodes[npcId].Count - 1)];
if (index - 1 == dialogNodes[npcId].Count)
{
dialog.text = "抱歉,我很忙,你可以找一下事情做";
}
else
{
dialog.text = node.dialog;
}
characterName.text = node.characterName;
characterSprite.overrideSprite = node.characterSprite;
if (index - 1 == dialogNodes[npcId].Count)
{
dialog.text = null;
dialogBox.SetActive(false);
}
}
}

View File

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