更新贴屏对话

This commit is contained in:
2024-09-17 20:36:55 +08:00
parent e7540d54f8
commit 180c8f1038
8 changed files with 1001 additions and 68 deletions

File diff suppressed because one or more lines are too long

View File

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

BIN
Assets/Cubic_11_1.013_R.ttf Normal file

Binary file not shown.

View File

@@ -0,0 +1,21 @@
fileFormatVersion: 2
guid: 91942d145a7996242b69fffc3c35d097
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Cubic 11
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -38,7 +38,6 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@@ -783,8 +782,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 944706249}
- component: {fileID: 944706248}
- component: {fileID: 944706247}
- component: {fileID: 944706246}
- component: {fileID: 944706250}
- component: {fileID: 944706251}
@@ -818,56 +815,6 @@ CapsuleCollider:
m_Height: 2
m_Direction: 1
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &944706247
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 944706245}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &944706248
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 944706245}
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &944706249
Transform:
m_ObjectHideFlags: 0
@@ -1134,9 +1081,9 @@ Canvas:
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_Camera: {fileID: 963194227}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_PixelPerfect: 1
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
@@ -1159,9 +1106,9 @@ RectTransform:
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 675862482}
- {fileID: 1644802856}
- {fileID: 1157830469}
- {fileID: 675862482}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
@@ -1203,7 +1150,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_SizeDelta: {x: 20, y: 5}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1157830470
MonoBehaviour:
@@ -1219,6 +1166,12 @@ MonoBehaviour:
m_EditorClassIdentifier:
dialogsPath:
dialogJson:
typingSpeed: 0.5
IntroduceText:
textMeshPro: {fileID: 1644802857}
printTime: 0
maxPrintTime: 10
isTime2Break: 0
--- !u!1 &1306517519
GameObject:
m_ObjectHideFlags: 0
@@ -1336,7 +1289,7 @@ GameObject:
- component: {fileID: 1644802856}
- component: {fileID: 1644802858}
- component: {fileID: 1644802857}
m_Layer: 5
m_Layer: 6
m_Name: Arror
m_TagString: Untagged
m_Icon: {fileID: 0}
@@ -1384,8 +1337,8 @@ MonoBehaviour:
m_Calls: []
m_text: +
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontAsset: {fileID: 11400000, guid: faf204988c60a4c4fb8373d533153646, type: 2}
m_sharedMaterial: {fileID: -5877148221832478119, guid: faf204988c60a4c4fb8373d533153646, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
@@ -1409,10 +1362,10 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 44.75
m_fontSizeBase: 36
m_fontSize: 42.85
m_fontSizeBase: 42.85
m_fontWeight: 400
m_enableAutoSizing: 1
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
@@ -1425,7 +1378,7 @@ MonoBehaviour:
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_enableWordWrapping: 0
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}

View File

@@ -1,8 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Event;
using Event.EventArgs;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
namespace UI
@@ -13,6 +16,17 @@ namespace UI
[SerializeField] private string dialogJson;
private Dictionary<int, string> _dialogsMap = new();
public float typingSpeed = 0.05f;
public string IntroduceText;
private string _currentText = "";
private float _timer;
private int _currentIndex;
private bool _start;
private bool _isBlinking;
public TMP_Text textMeshPro;
public float printTime;
public float maxPrintTime=10;
public bool isTime2Break;
private void Awake()
{
dialogsPath = Application.persistentDataPath + "/" + "Dialogs.json";
@@ -24,20 +38,80 @@ namespace UI
}
else
{
_dialogsMap.Add(0, "New Dialog");
_dialogsMap.Add(0, "我会视奸你,永远...永远......");
dialogJson = JsonConvert.SerializeObject(_dialogsMap, Formatting.Indented);
File.WriteAllText(dialogsPath, dialogJson);
}
}
private void Update()
{
if (!_start) return;
printTime += Time.deltaTime;
if (printTime > maxPrintTime)
{
isTime2Break = true;
}
if (_currentText == IntroduceText) return;
_timer += Time.deltaTime;
if (!(_timer >= typingSpeed)) return;
_timer = 0f;
_currentText += IntroduceText[_currentIndex];
textMeshPro.text = _currentText;
_currentIndex++;
}
private void Start()
{
EventManager.Instance.DialogPop += OpenDialog;
EventManager.Instance.DialogPop += StartPrinting;
}
public void OpenDialog(DialogPopArgs e)
/*public void OpenDialog(DialogPopArgs e)
{
Debug.Log(_dialogsMap[e.Index]);
}*/
//闪烁光标
private IEnumerator BlinkCursor()
{
while (true)
{
if (isTime2Break)
{
_start = false;
printTime = 0;
isTime2Break = false;
textMeshPro.fontSize = 48.7f;
textMeshPro.text = "+";
break;
}
if (!_isBlinking)
{
textMeshPro.text += "|";
_isBlinking = true;
}
else
{
textMeshPro.text = textMeshPro.text[..^1];
_isBlinking = false;
}
yield return new WaitForSeconds(0.3f); // 闪烁速度
}
}
// 调用此方法开始打印文字
private void StartPrinting(DialogPopArgs e)
{
if(printTime != 0) return;
_start = true;
_currentText = "";
IntroduceText = _dialogsMap[e.Index];
_currentIndex = 0;
_timer = 0f;
textMeshPro.fontSize = 80;
StartCoroutine(BlinkCursor());
}
}
}