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
|
@ -32,12 +32,14 @@ namespace Messaging {
|
|||
SetText(ref answerContainer.TypingCoroutine, answerContainer.messageText, answerContainer.TextTyper,
|
||||
text, animate);
|
||||
|
||||
if(string.IsNullOrEmpty(text)) return;
|
||||
answerContainer.container.SetActive(true);
|
||||
questionContainer.container.SetActive(false);
|
||||
} else {
|
||||
SetText(ref questionContainer.TypingCoroutine, questionContainer.messageText,
|
||||
questionContainer.TextTyper, text, animate);
|
||||
|
||||
if(string.IsNullOrEmpty(text)) return;
|
||||
questionContainer.container.SetActive(true);
|
||||
answerContainer.container.SetActive(false);
|
||||
}
|
||||
|
@ -52,12 +54,14 @@ namespace Messaging {
|
|||
SetText(ref answerContainer.RealTypingCoroutine, answerContainer.realMessageText,
|
||||
answerContainer.RealTextTyper, text, animate);
|
||||
|
||||
if(string.IsNullOrEmpty(text)) return;
|
||||
answerContainer.container.SetActive(true);
|
||||
questionContainer.container.SetActive(false);
|
||||
} else {
|
||||
SetText(ref questionContainer.RealTypingCoroutine, questionContainer.realMessageText,
|
||||
questionContainer.RealTextTyper, text, animate);
|
||||
|
||||
if(string.IsNullOrEmpty(text)) return;
|
||||
questionContainer.container.SetActive(true);
|
||||
answerContainer.container.SetActive(false);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Messaging {
|
||||
public class MessageManager : MonoBehaviour {
|
||||
|
@ -9,24 +11,21 @@ namespace Messaging {
|
|||
|
||||
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() {
|
||||
_messages = messageStructureGenerator.GenerateMessages();
|
||||
jokesBag = new List<TextAsset>(jokes);
|
||||
}
|
||||
|
||||
private async void Start() {
|
||||
MessageData.MessageData data = new(textAsset.text);
|
||||
int i = 0;
|
||||
while (Application.isPlaying) {
|
||||
bool isAnswer = i % 2 != 0;
|
||||
|
||||
CreateMessage(data.QuestionMessage.Key, isAnswer);
|
||||
await Task.Delay(2000);
|
||||
CreateRealMessage(data.QuestionMessage.Value, isAnswer);
|
||||
await Task.Delay(2000);
|
||||
++i;
|
||||
}
|
||||
MessageData.MessageData joke = GetRandomJoke();
|
||||
await Task.Delay((int)(initialSendJokeDelay * 1000));
|
||||
CreateMessage(joke.QuestionMessage.Key, false);
|
||||
}
|
||||
|
||||
public void CreateMessage(string message, bool isAnswer) {
|
||||
|
@ -54,6 +53,14 @@ namespace Messaging {
|
|||
_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) {
|
||||
if (index < 0) return;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue