feature: Only generating one message on start
This commit is contained in:
parent
bb07b2c0ef
commit
3669dec76f
13 changed files with 104 additions and 20 deletions
7
Assets/Jokes/chiste1.txt.meta
Normal file
7
Assets/Jokes/chiste1.txt.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c585a95f4d115b445b82535bda5f460c
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Assets/Jokes/chiste10.txt.meta
Normal file
7
Assets/Jokes/chiste10.txt.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ec37bca099ef3e847b3be147fcfe4d9e
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Assets/Jokes/chiste2.txt.meta
Normal file
7
Assets/Jokes/chiste2.txt.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a6e549c30cb55c64d85cda64b3e5f264
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Assets/Jokes/chiste3.txt.meta
Normal file
7
Assets/Jokes/chiste3.txt.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4eea457582b04f640b48b613312e90ae
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Assets/Jokes/chiste4.txt.meta
Normal file
7
Assets/Jokes/chiste4.txt.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8f6e8913745efbd478f88445cb4bacdd
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Assets/Jokes/chiste5.txt.meta
Normal file
7
Assets/Jokes/chiste5.txt.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dfe2ad8536db02b458922f1d656549fb
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Assets/Jokes/chiste6.txt.meta
Normal file
7
Assets/Jokes/chiste6.txt.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7f0889a12268baf4dae1dcdc69e4b6a4
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Assets/Jokes/chiste7.txt.meta
Normal file
7
Assets/Jokes/chiste7.txt.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ad10d007892f39943a2e9b4f9a0d98cb
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Assets/Jokes/chiste8.txt.meta
Normal file
7
Assets/Jokes/chiste8.txt.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d0647985eae927441a5b4a0b854f0eee
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
Assets/Jokes/chiste9.txt.meta
Normal file
7
Assets/Jokes/chiste9.txt.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bf2ae237b56a65648a26e0fc41a94d8a
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -2064,7 +2064,10 @@ MonoBehaviour:
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
messageStructureGenerator: {fileID: 1079303793}
|
messageStructureGenerator: {fileID: 1079303793}
|
||||||
textAsset: {fileID: 4900000, guid: 709db39fbdad6d64d913304ea83d7f85, type: 3}
|
jokes:
|
||||||
|
- {fileID: 4900000, guid: 709db39fbdad6d64d913304ea83d7f85, type: 3}
|
||||||
|
sendJokeDelay: 2
|
||||||
|
initialSendJokeDelay: 4
|
||||||
--- !u!1001 &1825731470
|
--- !u!1001 &1825731470
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -2457,8 +2460,8 @@ MonoBehaviour:
|
||||||
m_faceColor:
|
m_faceColor:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
rgba: 4294967295
|
rgba: 4294967295
|
||||||
m_fontSize: 36
|
m_fontSize: 16
|
||||||
m_fontSizeBase: 36
|
m_fontSizeBase: 16
|
||||||
m_fontWeight: 400
|
m_fontWeight: 400
|
||||||
m_enableAutoSizing: 0
|
m_enableAutoSizing: 0
|
||||||
m_fontSizeMin: 18
|
m_fontSizeMin: 18
|
||||||
|
@ -2521,11 +2524,11 @@ RectTransform:
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 507035066}
|
m_Father: {fileID: 507035066}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
m_AnchorMin: {x: 0, y: 1}
|
||||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
m_AnchorMax: {x: 0, y: 1}
|
||||||
m_AnchoredPosition: {x: 107.76931, y: -159.5}
|
m_AnchoredPosition: {x: 16, y: -212}
|
||||||
m_SizeDelta: {x: 439.3386, y: 50}
|
m_SizeDelta: {x: 258, y: 32}
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
m_Pivot: {x: 0, y: 1}
|
||||||
--- !u!1001 &2129526353
|
--- !u!1001 &2129526353
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -32,12 +32,14 @@ namespace Messaging {
|
||||||
SetText(ref answerContainer.TypingCoroutine, answerContainer.messageText, answerContainer.TextTyper,
|
SetText(ref answerContainer.TypingCoroutine, answerContainer.messageText, answerContainer.TextTyper,
|
||||||
text, animate);
|
text, animate);
|
||||||
|
|
||||||
|
if(string.IsNullOrEmpty(text)) return;
|
||||||
answerContainer.container.SetActive(true);
|
answerContainer.container.SetActive(true);
|
||||||
questionContainer.container.SetActive(false);
|
questionContainer.container.SetActive(false);
|
||||||
} else {
|
} else {
|
||||||
SetText(ref questionContainer.TypingCoroutine, questionContainer.messageText,
|
SetText(ref questionContainer.TypingCoroutine, questionContainer.messageText,
|
||||||
questionContainer.TextTyper, text, animate);
|
questionContainer.TextTyper, text, animate);
|
||||||
|
|
||||||
|
if(string.IsNullOrEmpty(text)) return;
|
||||||
questionContainer.container.SetActive(true);
|
questionContainer.container.SetActive(true);
|
||||||
answerContainer.container.SetActive(false);
|
answerContainer.container.SetActive(false);
|
||||||
}
|
}
|
||||||
|
@ -52,12 +54,14 @@ namespace Messaging {
|
||||||
SetText(ref answerContainer.RealTypingCoroutine, answerContainer.realMessageText,
|
SetText(ref answerContainer.RealTypingCoroutine, answerContainer.realMessageText,
|
||||||
answerContainer.RealTextTyper, text, animate);
|
answerContainer.RealTextTyper, text, animate);
|
||||||
|
|
||||||
|
if(string.IsNullOrEmpty(text)) return;
|
||||||
answerContainer.container.SetActive(true);
|
answerContainer.container.SetActive(true);
|
||||||
questionContainer.container.SetActive(false);
|
questionContainer.container.SetActive(false);
|
||||||
} else {
|
} else {
|
||||||
SetText(ref questionContainer.RealTypingCoroutine, questionContainer.realMessageText,
|
SetText(ref questionContainer.RealTypingCoroutine, questionContainer.realMessageText,
|
||||||
questionContainer.RealTextTyper, text, animate);
|
questionContainer.RealTextTyper, text, animate);
|
||||||
|
|
||||||
|
if(string.IsNullOrEmpty(text)) return;
|
||||||
questionContainer.container.SetActive(true);
|
questionContainer.container.SetActive(true);
|
||||||
answerContainer.container.SetActive(false);
|
answerContainer.container.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
namespace Messaging {
|
namespace Messaging {
|
||||||
public class MessageManager : MonoBehaviour {
|
public class MessageManager : MonoBehaviour {
|
||||||
|
@ -9,24 +11,21 @@ namespace Messaging {
|
||||||
|
|
||||||
private Message[] _messages;
|
private Message[] _messages;
|
||||||
|
|
||||||
[SerializeField] private TextAsset textAsset;
|
[SerializeField] private TextAsset[] jokes;
|
||||||
|
[SerializeField, Min(0)] private float sendJokeDelay = 2f;
|
||||||
|
[SerializeField, Min(0)] private float initialSendJokeDelay = 4f;
|
||||||
|
|
||||||
|
private List<TextAsset> jokesBag;
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
_messages = messageStructureGenerator.GenerateMessages();
|
_messages = messageStructureGenerator.GenerateMessages();
|
||||||
|
jokesBag = new List<TextAsset>(jokes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Start() {
|
private async void Start() {
|
||||||
MessageData.MessageData data = new(textAsset.text);
|
MessageData.MessageData joke = GetRandomJoke();
|
||||||
int i = 0;
|
await Task.Delay((int)(initialSendJokeDelay * 1000));
|
||||||
while (Application.isPlaying) {
|
CreateMessage(joke.QuestionMessage.Key, false);
|
||||||
bool isAnswer = i % 2 != 0;
|
|
||||||
|
|
||||||
CreateMessage(data.QuestionMessage.Key, isAnswer);
|
|
||||||
await Task.Delay(2000);
|
|
||||||
CreateRealMessage(data.QuestionMessage.Value, isAnswer);
|
|
||||||
await Task.Delay(2000);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateMessage(string message, bool isAnswer) {
|
public void CreateMessage(string message, bool isAnswer) {
|
||||||
|
@ -54,6 +53,14 @@ namespace Messaging {
|
||||||
_messages[index].SetMessageRealText("", false, _messages[index].IsAnswer);
|
_messages[index].SetMessageRealText("", false, _messages[index].IsAnswer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MessageData.MessageData GetRandomJoke() {
|
||||||
|
TextAsset joke = jokesBag[Random.Range(0, jokesBag.Count)];
|
||||||
|
if (jokesBag.Count == 0)
|
||||||
|
jokesBag = new List<TextAsset>(jokes);
|
||||||
|
|
||||||
|
return new MessageData.MessageData(joke.text);
|
||||||
|
}
|
||||||
|
|
||||||
private void ModifyPreviousMessage(string message, string realMessage, int index, bool isAnswer, bool isReal) {
|
private void ModifyPreviousMessage(string message, string realMessage, int index, bool isAnswer, bool isReal) {
|
||||||
if (index < 0) return;
|
if (index < 0) return;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue