【剧情】打字机效果完善

main
chenyuqi 2023-10-31 15:49:24 +08:00
parent 89657e1e55
commit eb91b9b56f
2 changed files with 72 additions and 19 deletions

View File

@ -502,7 +502,7 @@ GameObject:
- component: {fileID: 6319488051365112474}
- component: {fileID: 6696831508494206924}
- component: {fileID: 6749107212381630933}
- component: {fileID: 8836889226163915217}
- component: {fileID: 506122473372319921}
m_Layer: 5
m_Name: Scroll View
m_TagString: Untagged
@ -569,7 +569,7 @@ MonoBehaviour:
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &8836889226163915217
--- !u!114 &506122473372319921
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -578,11 +578,11 @@ MonoBehaviour:
m_GameObject: {fileID: 511891900535165924}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1aa08ab6e0800fa44ae55d278d1423e3, type: 3}
m_Script: {fileID: 11500000, guid: 2d355eec575560046ba27246695b84ad, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Content: {fileID: 2027222233794998720}
m_Horizontal: 1
m_Horizontal: 0
m_Vertical: 1
m_MovementType: 1
m_Elasticity: 0.1
@ -592,13 +592,17 @@ MonoBehaviour:
m_Viewport: {fileID: 955885197068060797}
m_HorizontalScrollbar: {fileID: 0}
m_VerticalScrollbar: {fileID: 5526992997119787535}
m_HorizontalScrollbarVisibility: 2
m_VerticalScrollbarVisibility: 2
m_HorizontalScrollbarSpacing: -3
m_VerticalScrollbarSpacing: -3
m_HorizontalScrollbarVisibility: 0
m_VerticalScrollbarVisibility: 0
m_HorizontalScrollbarSpacing: 0
m_VerticalScrollbarSpacing: 0
m_OnValueChanged:
m_PersistentCalls:
m_Calls: []
defaultItemSize: {x: 1520.5, y: 208}
itemTemplate: {fileID: 7051972693408823226}
layoutType: 1
poolSize: 5
--- !u!1 &890811276893610588
GameObject:
m_ObjectHideFlags: 0
@ -1430,7 +1434,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &7051972693408823226
RectTransform:
m_ObjectHideFlags: 0
@ -4864,7 +4868,7 @@ RectTransform:
m_Father: {fileID: 5014326811785617644}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -18}
m_SizeDelta: {x: 35, y: 203}
m_Pivot: {x: 0.5, y: 0.5}
@ -5382,7 +5386,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &2435750827471002304
RectTransform:
m_ObjectHideFlags: 0
@ -6787,11 +6791,11 @@ RectTransform:
- {fileID: 8159813512205391015}
- {fileID: 6104782591014005104}
- {fileID: 109264313758130537}
- {fileID: 2435750827471002304}
- {fileID: 7051972693408823226}
- {fileID: 3827942846217615775}
- {fileID: 8616551682924160344}
- {fileID: 4429350005946987221}
- {fileID: 2435750827471002304}
- {fileID: 7233120182087931439}
- {fileID: 7896991221781629267}
m_Father: {fileID: 0}
@ -7165,9 +7169,9 @@ RectTransform:
m_Father: {fileID: 6319488051365112474}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_SizeDelta: {x: -17, y: 0}
m_Pivot: {x: 0, y: 1}
--- !u!222 &289031393887604237
CanvasRenderer:

View File

@ -77,6 +77,7 @@ public class UIStoryMainController : UIWindow
private string _curBlock2DTalk; //2D模式下对话缓存
private int _cur2DTalkPlayerId; //2D模式下说话人缓存
private bool _isTalking; //正在播放打字机效果
private bool _isBlockEnd; //是否已经到block的最后一帧
private struct LogData
{
public string name;
@ -260,6 +261,16 @@ public class UIStoryMainController : UIWindow
private void OnClickInterAct()
{
if (_isTalking)
{
foreach (var bubble in _dispBubblePool)
{
CompleteBubble(bubble.Key, bubble.Value);
}
_isTalking = false;
EventManager.Instance.Send(EventManager.EventName.STORY_CLICK_SCREEN);
return;
}
//互动消息
EventManager.Instance.Send(EventManager.EventName.STORY_CLICK_SCREEN);
}
@ -389,6 +400,7 @@ public class UIStoryMainController : UIWindow
//展示气泡框对话
private void ShowBubble(EDPlayerTalkData talkData)
{
_isTalking = true;
if (CheckIsAside(talkData.playerId))
{
//var go = GetBubbleObj(talkData.playerId);
@ -410,6 +422,16 @@ public class UIStoryMainController : UIWindow
txtName.text = charName;
txtContent.text = StringManager.GetStoryTalkText(content);
txtContent.ForceMeshUpdate();
//先清掉原来的text网格信息
var textInfo = txtContent.textInfo;
for (int i = 0; i < textInfo.materialCount; ++i)
{
textInfo.meshInfo[i].Clear();
}
txtContent.UpdateVertexData(TMP_VertexDataUpdateFlags.Vertices);
//延迟一帧再进行打字机效果播放
await UniTask.DelayFrame(1);
await DoTyperText(txtContent, 100);
}
@ -517,6 +539,8 @@ public class UIStoryMainController : UIWindow
{
return false;
}
_curBlockTalkDic[playerId] = content;
return playerContent == content;
}
@ -602,7 +626,14 @@ public class UIStoryMainController : UIWindow
for (int i = 0; i < textInfo.characterCount; ++i)
{
await UniTask.Delay(waitTime);
if (_isTalking)
{
await UniTask.Delay(waitTime);
}
else
{
return;
}
TMP_CharacterInfo characterInfo = textInfo.characterInfo[i];
@ -622,6 +653,8 @@ public class UIStoryMainController : UIWindow
tmpText.UpdateVertexData(TMPro.TMP_VertexDataUpdateFlags.Vertices);
}
}
_isTalking = true;
}
//打印单个字
@ -686,14 +719,16 @@ public class UIStoryMainController : UIWindow
//监听事件
private void OnBlockEnd()
{
foreach (var bubble in _dispBubblePool)
{
CompleteBubble(bubble.Key, bubble.Value);
}
_isBlockEnd = true;
// foreach (var bubble in _dispBubblePool)
// {
// CompleteBubble(bubble.Key, bubble.Value);
// }
}
private void OnBlockStart()
{
_isBlockEnd = false;
HideAllEnableBubble();
}
@ -701,5 +736,19 @@ public class UIStoryMainController : UIWindow
{
var txtContent = CommonUtils.GetComponent<TMP_Text>(go, "TextContent");
txtContent.text = _curBlockTalkDic[playerId];
txtContent.ForceMeshUpdate();
}
private bool CheckIsTalking()
{
foreach (var b in _playingDic)
{
if (b.Value)
{
return true;
}
}
return false;
}
}